Skip to content

Commit 74e72c7

Browse files
smkniaziGautier Berthou
authored and
Gautier Berthou
committed
[HOPS-1655] fixed quota updates for delete, rename and overwrite operations
1 parent 5078144 commit 74e72c7

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

src/main/java/io/hops/metadata/ndb/dalimpl/hdfs/InvalidatedBlockClusterj.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.hops.exception.StorageException;
2929
import io.hops.metadata.hdfs.TablesDef;
3030
import io.hops.metadata.hdfs.dal.InvalidateBlockDataAccess;
31+
import io.hops.metadata.hdfs.dal.SQLResultSetHandler;
3132
import io.hops.metadata.hdfs.entity.InvalidatedBlock;
3233
import io.hops.metadata.ndb.ClusterjConnector;
3334
import io.hops.metadata.ndb.mysqlserver.MySQLQueryHelper;
@@ -121,7 +122,8 @@ public List<InvalidatedBlock> findInvalidatedBlockByStorageId(int storageId)
121122
@Override
122123
public Map<Long, Long> findInvalidatedBlockBySidUsingMySQLServer(int storageId) throws StorageException {
123124
return MySQLQueryHelper.execute(String.format("SELECT %s, %s "
124-
+ "FROM %s WHERE %s='%d'", BLOCK_ID, GENERATION_STAMP, TABLE_NAME, STORAGE_ID, storageId), new MySQLQueryHelper.ResultSetHandler<Map<Long,Long>>() {
125+
+ "FROM %s WHERE %s='%d'", BLOCK_ID, GENERATION_STAMP, TABLE_NAME, STORAGE_ID,
126+
storageId), new SQLResultSetHandler<Map<Long,Long>>() {
125127
@Override
126128
public Map<Long,Long> handle(ResultSet result) throws SQLException {
127129
Map<Long,Long> blockInodeMap = new HashMap<>();

src/main/java/io/hops/metadata/ndb/dalimpl/hdfs/QuotaUpdateClusterj.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.hops.exception.StorageException;
2525
import io.hops.metadata.hdfs.TablesDef;
2626
import io.hops.metadata.hdfs.dal.QuotaUpdateDataAccess;
27+
import io.hops.metadata.hdfs.dal.SQLResultSetHandler;
2728
import io.hops.metadata.hdfs.entity.QuotaUpdate;
2829
import io.hops.metadata.ndb.ClusterjConnector;
2930
import io.hops.metadata.ndb.mysqlserver.HopsSQLExceptionHelper;
@@ -41,6 +42,7 @@
4142
import java.sql.SQLException;
4243
import java.util.ArrayList;
4344
import java.util.Collection;
45+
import java.util.Collections;
4446
import java.util.HashMap;
4547
import java.util.List;
4648
import java.util.Map;
@@ -244,7 +246,7 @@ private QuotaUpdate convertAndRelease(HopsSession session, QuotaUpdateDTO dto) t
244246
private static final String INODE_ID_PARAM = "inodeId";
245247

246248
@Override
247-
public List<QuotaUpdate> findByInodeId(long inodeId) throws StorageException {
249+
public List<QuotaUpdate> findByInodeId(final long inodeId, final int limit) throws StorageException {
248250
HopsSession session = connector.obtainSession();
249251
HopsQueryBuilder qb = session.getQueryBuilder();
250252
HopsQueryDomainType<QuotaUpdateDTO> dobj =
@@ -254,6 +256,10 @@ public List<QuotaUpdate> findByInodeId(long inodeId) throws StorageException {
254256
HopsQuery<QuotaUpdateDTO> query = session.createQuery(dobj);
255257
query.setParameter(INODE_ID_PARAM, inodeId);
256258

259+
if (limit != -1) {
260+
query.setLimits(0, limit);
261+
}
262+
257263
List<QuotaUpdateDTO> results = query.getResultList();
258264
return convertAndRelease(session, results);
259265
}
@@ -263,4 +269,20 @@ public int getCount() throws StorageException {
263269
int count = MySQLQueryHelper.countAll(TablesDef.QuotaUpdateTableDef.TABLE_NAME);
264270
return count;
265271
}
272+
273+
@Override
274+
public List<Long> getDistinctInodes() throws StorageException {
275+
final String query = "select DISTINCT(" + INODE_ID + ") from " + TABLE_NAME;
276+
return MySQLQueryHelper.execute(query, new SQLResultSetHandler<List<Long>>() {
277+
@Override
278+
public List<Long> handle(ResultSet result) throws SQLException {
279+
List<Long> inodes = new ArrayList<>();
280+
281+
while (result.next()){
282+
inodes.add(result.getLong(INODE_ID));
283+
}
284+
return inodes;
285+
}
286+
});
287+
}
266288
}

src/main/java/io/hops/metadata/ndb/dalimpl/hdfs/ReplicaClusterj.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.hops.exception.StorageException;
3030
import io.hops.metadata.hdfs.TablesDef;
3131
import io.hops.metadata.hdfs.dal.ReplicaDataAccess;
32+
import io.hops.metadata.hdfs.dal.SQLResultSetHandler;
3233
import io.hops.metadata.hdfs.entity.Replica;
3334
import io.hops.metadata.ndb.ClusterjConnector;
3435
import io.hops.metadata.ndb.mysqlserver.MySQLQueryHelper;
@@ -239,7 +240,7 @@ protected static Set<Long> getReplicas(int storageId) throws
239240
StorageException {
240241
return MySQLQueryHelper.execute(String.format("SELECT %s " +
241242
"FROM %s WHERE %s='%d'", BLOCK_ID, TABLE_NAME, STORAGE_ID, storageId)
242-
, new MySQLQueryHelper.ResultSetHandler<Set<Long>>() {
243+
, new SQLResultSetHandler<Set<Long>>() {
243244
@Override
244245
public Set<Long> handle(ResultSet result) throws SQLException {
245246
Set<Long> blocks = Sets.newHashSet();

src/main/java/io/hops/metadata/ndb/mysqlserver/MySQLQueryHelper.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.sql.PreparedStatement;
2525
import java.sql.ResultSet;
2626
import java.sql.SQLException;
27+
28+
import io.hops.metadata.hdfs.dal.SQLResultSetHandler;
2729
import org.apache.commons.logging.Log;
2830
import org.apache.commons.logging.LogFactory;
2931

@@ -125,7 +127,7 @@ public static long maxLong(String tableName, String column)
125127

126128
public static int executeIntAggrQuery(final String query)
127129
throws StorageException {
128-
return execute(query, new ResultSetHandler<Integer>() {
130+
return execute(query, new SQLResultSetHandler<Integer>() {
129131
@Override
130132
public Integer handle(ResultSet result) throws SQLException, StorageException {
131133
if (!result.next()) {
@@ -139,7 +141,7 @@ public Integer handle(ResultSet result) throws SQLException, StorageException {
139141

140142
public static long executeLongAggrQuery(final String query)
141143
throws StorageException {
142-
return execute(query, new ResultSetHandler<Long>() {
144+
return execute(query, new SQLResultSetHandler<Long>() {
143145
@Override
144146
public Long handle(ResultSet result) throws SQLException, StorageException {
145147
if (!result.next()) {
@@ -153,7 +155,7 @@ public Long handle(ResultSet result) throws SQLException, StorageException {
153155

154156
private static boolean executeBooleanQuery(final String query)
155157
throws StorageException {
156-
return execute(query, new ResultSetHandler<Boolean>() {
158+
return execute(query, new SQLResultSetHandler<Boolean>() {
157159
@Override
158160
public Boolean handle(ResultSet result) throws SQLException, StorageException {
159161
if (!result.next()) {
@@ -185,11 +187,7 @@ public static int execute(String query) throws StorageException {
185187
}
186188
}
187189

188-
public interface ResultSetHandler<R> {
189-
R handle(ResultSet result) throws SQLException, StorageException;
190-
}
191-
192-
public static <R> R execute(String query, ResultSetHandler<R> handler)
190+
public static <R> R execute(String query, SQLResultSetHandler<R> handler)
193191
throws StorageException {
194192
try {
195193
PreparedStatement s = null;

src/main/java/io/hops/metadata/ndb/mysqlserver/MysqlServerConnector.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131
import java.io.InputStreamReader;
32+
33+
import io.hops.metadata.hdfs.dal.SQLResultSetHandler;
3234
import org.apache.commons.logging.Log;
3335
import org.apache.commons.logging.LogFactory;
3436
import java.sql.Connection;
@@ -301,7 +303,7 @@ public String getDatabaseName() {
301303
public static float getResourceMemUtilization() throws StorageException {
302304
return MySQLQueryHelper.execute("SELECT memory_type, used, total FROM " +
303305
"ndbinfo.memoryusage where memory_type = \"Data memory\"",
304-
new MySQLQueryHelper.ResultSetHandler<Float>() {
306+
new SQLResultSetHandler<Float>() {
305307
@Override
306308
public Float handle(ResultSet result)
307309
throws SQLException {
@@ -318,7 +320,7 @@ public Float handle(ResultSet result)
318320
public static boolean hasResources(final double threshold) throws StorageException {
319321
return MySQLQueryHelper.execute("SELECT memory_type, used, total FROM " +
320322
"ndbinfo.memoryusage where memory_type = \"Data memory\"",
321-
new MySQLQueryHelper.ResultSetHandler<Boolean>() {
323+
new SQLResultSetHandler<Boolean>() {
322324
@Override
323325
public Boolean handle(ResultSet result)
324326
throws SQLException, StorageException {

0 commit comments

Comments
 (0)