Skip to content

Commit 979ef95

Browse files
berthougGautier Berthou
authored and
Gautier Berthou
committed
add ee changes that should also have been made in community
1 parent 518df7d commit 979ef95

8 files changed

+131
-12
lines changed

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

+50-10
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,42 @@ public void prepare(Collection<BlockInfo> removed, Collection<BlockInfo> news,
186186
session.release(luChanges);
187187
}
188188
}
189+
190+
//only for testing
191+
@Override
192+
public void deleteBlocksForFile(long inodeID) throws StorageException {
193+
HopsSession session = connector.obtainSession();
194+
195+
HopsQueryBuilder qb = session.getQueryBuilder();
196+
HopsQueryDomainType<BlockInfoDTO> dobj = qb.createQueryDefinition(BlockInfoDTO.class);
197+
HopsPredicate pred1 = dobj.get("iNodeId").equal(dobj.param("inodeIdParam"));
198+
dobj.where(pred1);
199+
200+
HopsQuery<BlockInfoDTO> query = session.createQuery(dobj);
201+
query.setParameter("inodeIdParam", inodeID);
202+
List<BlockInfoDTO> dtos = query.getResultList();
203+
204+
session.deletePersistentAll(dtos);
205+
session.release(dtos);
206+
207+
deleteBlockLoopupForFile(inodeID);
208+
}
209+
210+
private void deleteBlockLoopupForFile(long inodeID) throws StorageException {
211+
HopsSession session = connector.obtainSession();
212+
213+
HopsQueryBuilder qb = session.getQueryBuilder();
214+
HopsQueryDomainType<BlockLookUpClusterj.BlockLookUpDTO> dobj =
215+
qb.createQueryDefinition(BlockLookUpClusterj.BlockLookUpDTO.class);
216+
HopsPredicate pred = dobj.get("iNodeId").equal(dobj.param("inodeIdParam"));
217+
dobj.where(pred);
218+
HopsQuery<BlockLookUpClusterj.BlockLookUpDTO> query = session.createQuery(dobj);
219+
query.setParameter("inodeIdParam", inodeID);
220+
List<BlockLookUpClusterj.BlockLookUpDTO> dtos = query.getResultList();
221+
222+
session.deletePersistentAll(dtos);
223+
session.release(dtos);
224+
}
189225

190226
@Override
191227
public BlockInfo findById(long blockId, long inodeId) throws StorageException {
@@ -240,28 +276,32 @@ public List<BlockInfo> findByInodeIds(long[] inodeIds)
240276
return lbis;
241277
}
242278

243-
public BlockInfo scanByBlockId(long blockId) throws StorageException {
279+
@Override
280+
public List<BlockInfo> findAllBlocks() throws StorageException {
244281
HopsSession session = connector.obtainSession();
245282
HopsQueryBuilder qb = session.getQueryBuilder();
246283
HopsQueryDomainType<BlockInfoClusterj.BlockInfoDTO> dobj =
247284
qb.createQueryDefinition(BlockInfoClusterj.BlockInfoDTO.class);
248-
HopsPredicate pred1 = dobj.get("blockId").equal(dobj.param("blockIdParam"));
249-
dobj.where(pred1);
250285
HopsQuery<BlockInfoClusterj.BlockInfoDTO> query = session.createQuery(dobj);
251-
query.setParameter("blockIdParam", blockId);
286+
252287
List<BlockInfoDTO> biDtos = query.getResultList();
253-
BlockInfo bi = createBlockInfo(biDtos.get(0));
288+
List<BlockInfo> lbis = createBlockInfoList(biDtos);
254289
session.release(biDtos);
255-
return bi;
290+
return lbis;
256291
}
257292

258293
@Override
259-
public List<BlockInfo> findAllBlocks() throws StorageException {
294+
public List<BlockInfo> findAllBlocks(long startID, long endID) throws StorageException {
260295
HopsSession session = connector.obtainSession();
261296
HopsQueryBuilder qb = session.getQueryBuilder();
262-
HopsQueryDomainType<BlockInfoClusterj.BlockInfoDTO> dobj =
263-
qb.createQueryDefinition(BlockInfoClusterj.BlockInfoDTO.class);
264-
HopsQuery<BlockInfoClusterj.BlockInfoDTO> query = session.createQuery(dobj);
297+
HopsQueryDomainType<BlockInfoDTO> qdty = qb.createQueryDefinition(BlockInfoDTO.class);
298+
HopsPredicate pred1 = qdty.get("blockId").greaterEqual(qdty.param("blockIdParam1"));
299+
HopsPredicate pred2 = qdty.get("blockId").lessThan(qdty.param("blockIdParam2"));
300+
qdty.where(pred1.and(pred2));
301+
302+
HopsQuery<BlockInfoDTO> query = session.createQuery(qdty);
303+
query.setParameter("blockIdParam1", startID);
304+
query.setParameter("blockIdParam2", endID);
265305

266306
List<BlockInfoDTO> biDtos = query.getResultList();
267307
List<BlockInfo> lbis = createBlockInfoList(biDtos);

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

+12
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ public ExcessReplica findByPK(long bId, int sid, long inodeId)
200200
session.release(invTable);
201201
return result;
202202
}
203+
204+
@Override
205+
public List<ExcessReplica> findAll() throws StorageException {
206+
HopsSession session = connector.obtainSession();
207+
HopsQueryBuilder qb = session.getQueryBuilder();
208+
HopsQuery<ExcessReplicaDTO> query =
209+
session.createQuery(qb.createQueryDefinition(ExcessReplicaDTO.class));
210+
List<ExcessReplicaDTO> dtos = query.getResultList();
211+
List<ExcessReplica> list = createList(dtos);
212+
session.release(dtos);
213+
return list;
214+
}
203215

204216
@Override
205217
public void removeAll() throws StorageException {

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

+19
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,25 @@ public int countAllFiles() throws StorageException {
638638
.countWithCriterion(TABLE_NAME, String.format("%s<>0", HEADER));
639639
}
640640

641+
@Override
642+
public List<INode> findINodes(String name) throws StorageException {
643+
HopsSession session = connector.obtainSession();
644+
645+
HopsQueryBuilder qb = session.getQueryBuilder();
646+
HopsQueryDomainType<InodeDTO> dobj =
647+
qb.createQueryDefinition(InodeDTO.class);
648+
HopsPredicate pred1 = dobj.get("name").equal(dobj.param("nameParam"));
649+
dobj.where(pred1);
650+
651+
HopsQuery<InodeDTO> query = session.createQuery(dobj);
652+
query.setParameter("nameParam", name);
653+
654+
List<InodeDTO> dtos = query.getResultList();
655+
List<INode> results = convert(dtos);
656+
session.release(dtos);
657+
return results;
658+
}
659+
641660
@Override
642661
public void deleteInode(String inodeName) throws StorageException { // only for testing
643662
String query = "delete from "+TablesDef.INodeTableDef.TABLE_NAME+" where "+

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

+28
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,34 @@ public void removeAllByStorageId(int storageId) throws StorageException {
289289
query.deletePersistentAll();
290290
}
291291

292+
@Override
293+
public List<InvalidatedBlock> findAll() throws StorageException {
294+
HopsSession session = connector.obtainSession();
295+
HopsQueryBuilder qb = session.getQueryBuilder();
296+
HopsQuery<InvalidateBlocksDTO> query =
297+
session.createQuery(qb.createQueryDefinition(InvalidateBlocksDTO.class));
298+
List<InvalidateBlocksDTO> dtos = query.getResultList();
299+
List<InvalidatedBlock> list = createList(dtos);
300+
return list;
301+
}
302+
303+
@Override
304+
public List<InvalidatedBlock> findInvalidatedBlockInCloudList(int cloudStorageID, int limit)
305+
throws StorageException {
306+
HopsSession session = connector.obtainSession();
307+
HopsQueryBuilder qb = session.getQueryBuilder();
308+
HopsQueryDomainType<InvalidateBlocksDTO> qdt =
309+
qb.createQueryDefinition(InvalidateBlocksDTO.class);
310+
qdt.where(qdt.get("storageId").equal(qdt.param("param")));
311+
HopsQuery<InvalidateBlocksDTO> query = session.createQuery(qdt);
312+
query.setParameter("param", cloudStorageID);
313+
query.setLimits(0, limit);
314+
315+
List<InvalidateBlocksDTO> dtos = query.getResultList();
316+
List<InvalidatedBlock> ivl = createList(dtos);
317+
session.release(dtos);
318+
return ivl;
319+
}
292320

293321
private List<InvalidatedBlock> createList(List<InvalidateBlocksDTO> dtoList) {
294322
List<InvalidatedBlock> list = new ArrayList<>();

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

+11
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ public long findBlockIdAtIndex(int storageId, long index, int maxFetchingSize) t
332332
return 0;
333333
}
334334

335+
@Override
336+
public List<Replica> findAll() throws StorageException {
337+
HopsSession session = connector.obtainSession();
338+
HopsQueryBuilder qb = session.getQueryBuilder();
339+
HopsQuery<ReplicaDTO> query =
340+
session.createQuery(qb.createQueryDefinition(ReplicaDTO.class));
341+
List<ReplicaDTO> dtos = query.getResultList();
342+
List<Replica> list = convertAndRelease(session, dtos);
343+
return list;
344+
}
345+
335346
private static Long countBlocksInWindow(int storageId, long from, int size) throws
336347
StorageException {
337348
Long result = MySQLQueryHelper.executeLongAggrQuery(String.format("SELECT count(*) " +

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

+11
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ public int countAll() throws StorageException {
172172
return MySQLQueryHelper.countAll(TABLE_NAME);
173173
}
174174

175+
@Override
176+
public List<ReplicaUnderConstruction> findAll() throws StorageException {
177+
HopsSession session = connector.obtainSession();
178+
HopsQueryBuilder qb = session.getQueryBuilder();
179+
HopsQuery<ReplicaUcDTO> query =
180+
session.createQuery(qb.createQueryDefinition(ReplicaUcDTO.class));
181+
List<ReplicaUcDTO> dtos = query.getResultList();
182+
List<ReplicaUnderConstruction> list = convertAndRelease(session, dtos);
183+
return list;
184+
}
185+
175186
private List<ReplicaUnderConstruction> convertAndRelease(HopsSession session,
176187
List<ReplicaUcDTO> replicaUc) throws StorageException {
177188
List<ReplicaUnderConstruction> replicas =

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

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public static int countWhere(String tableName, String condition)
5757
* @throws StorageException
5858
*/
5959
public static int countAll(String tableName) throws StorageException {
60-
// TODO[H]: Is it good to create and close connections in every call?
6160
String query = String.format(COUNT_QUERY, tableName);
6261
return count(query);
6362
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class MySQLQueryHelper {
5454
* @throws io.hops.exception.StorageException
5555
*/
5656
public static int countAll(String tableName) throws StorageException {
57-
// TODO[H]: Is it good to create and close connections in every call?
5857
String query = String.format(COUNT_QUERY, tableName);
5958
return executeIntAggrQuery(query);
6059
}

0 commit comments

Comments
 (0)