szetszwo commented on code in PR #4337:
URL: https://github.com/apache/ozone/pull/4337#discussion_r1125231344
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainerMetadataInspector.java:
##########
@@ -437,41 +497,107 @@ private JsonObject buildErrorAndRepair(String property,
JsonElement expected,
return error;
}
- private long countPendingDeletesSchemaV2(DatanodeStoreSchemaTwoImpl
- schemaTwoStore) throws IOException {
+ enum PendingDeleteType {
+ COUNT("pendingDeleteBlocks"),
+ BYTES("pendingDeleteBytes");
+
+ private final String jsonKey;
+
+ PendingDeleteType(String jsonKey) {
+ this.jsonKey = jsonKey;
+ }
+
+ String getJsonKey() {
+ return jsonKey;
+ }
+
+ void addProperty(EnumMap<PendingDeleteType, Long> map,
+ JsonObject json) {
+ Optional.of(map.get(this))
+ .ifPresent(bytes -> json.addProperty(getJsonKey(), bytes));
+ }
+
+ static EnumMap<PendingDeleteType, Long> newMap(long count, long bytes) {
+ final EnumMap<PendingDeleteType, Long> map
+ = new EnumMap<>(PendingDeleteType.class);
+ map.put(PendingDeleteType.COUNT, count);
+ map.put(PendingDeleteType.BYTES, bytes);
+ return map;
+ }
+ }
+
+ static EnumMap<PendingDeleteType, Long> countPendingDeletesSchemaV2(
+ DatanodeStoreSchemaTwoImpl schemaTwoStore,
+ KeyValueContainerData containerData) throws IOException {
long pendingDeleteBlockCountTotal = 0;
+ long pendingDeleteBytes = 0;
+
Table<Long, DeletedBlocksTransaction> delTxTable =
schemaTwoStore.getDeleteTransactionTable();
+ final Table<String, BlockData> blockDataTable
+ = schemaTwoStore.getBlockDataTable();
+
try (TableIterator<Long, ? extends Table.KeyValue<Long,
DeletedBlocksTransaction>> iterator = delTxTable.iterator()) {
while (iterator.hasNext()) {
DeletedBlocksTransaction txn = iterator.next().getValue();
+ final List<Long> localIDs = txn.getLocalIDList();
// In schema 2, pending delete blocks are stored in the
// transaction object. Since the actual blocks still exist in the
// block data table with no prefix, they have already been
// counted towards bytes used and total block count above.
- pendingDeleteBlockCountTotal += txn.getLocalIDList().size();
+ pendingDeleteBlockCountTotal += localIDs.size();
+ pendingDeleteBytes += computePendingDeleteBytes(
+ localIDs, containerData, blockDataTable);
}
}
- return pendingDeleteBlockCountTotal;
+ return PendingDeleteType.newMap(pendingDeleteBlockCountTotal,
+ pendingDeleteBytes);
+ }
+
+ static long computePendingDeleteBytes(List<Long> localIDs,
+ KeyValueContainerData containerData,
+ Table<String, BlockData> blockDataTable) {
+ long pendingDeleteBytes = 0;
+ for (long id : localIDs) {
+ try {
+ final String blockKey = containerData.getBlockKey(id);
+ final BlockData blockData = blockDataTable.get(blockKey);
+ if (blockData != null) {
+ pendingDeleteBytes += blockData.getSize();
+ }
+ } catch (Throwable t) {
Review Comment:
Sure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]