bharatviswa504 commented on a change in pull request #742:
URL: https://github.com/apache/hadoop-ozone/pull/742#discussion_r421690519
##########
File path:
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/KeyValueContainerUtil.java
##########
@@ -150,29 +160,109 @@ public static void
parseKVContainerData(KeyValueContainerData kvContainerData,
}
kvContainerData.setDbFile(dbFile);
- try(ReferenceCountedDB metadata =
- BlockUtils.getDB(kvContainerData, config)) {
- long bytesUsed = 0;
- List<Map.Entry<byte[], byte[]>> liveKeys = metadata.getStore()
- .getRangeKVs(null, Integer.MAX_VALUE,
- MetadataKeyFilters.getNormalKeyFilter());
- bytesUsed = liveKeys.parallelStream().mapToLong(e-> {
- BlockData blockData;
+ boolean isBlockMetadataSet = false;
+
+ try(ReferenceCountedDB containerDB = BlockUtils.getDB(kvContainerData,
+ config)) {
+
+ // Set pending deleted block count.
+ byte[] pendingDeleteBlockCount =
+ containerDB.getStore().get(DB_PENDING_DELETE_BLOCK_COUNT_KEY);
+ if (pendingDeleteBlockCount != null) {
+ kvContainerData.incrPendingDeletionBlocks(
+ Ints.fromByteArray(pendingDeleteBlockCount));
+ } else {
+ // Set pending deleted block count.
+ MetadataKeyFilters.KeyPrefixFilter filter =
+ new MetadataKeyFilters.KeyPrefixFilter()
+ .addFilter(OzoneConsts.DELETING_KEY_PREFIX);
+ int numPendingDeletionBlocks =
+ containerDB.getStore().getSequentialRangeKVs(null,
+ Integer.MAX_VALUE, filter)
+ .size();
+ kvContainerData.incrPendingDeletionBlocks(numPendingDeletionBlocks);
+ }
+
+ // Set delete transaction id.
+ byte[] delTxnId =
+ containerDB.getStore().get(DB_CONTAINER_DELETE_TRANSACTION_KEY);
+ if (delTxnId != null) {
+ kvContainerData
+ .updateDeleteTransactionId(Longs.fromByteArray(delTxnId));
+ }
+
+ // Set BlockCommitSequenceId.
+ byte[] bcsId = containerDB.getStore().get(
+ DB_BLOCK_COMMIT_SEQUENCE_ID_KEY);
+ if (bcsId != null) {
+ kvContainerData
+ .updateBlockCommitSequenceId(Longs.fromByteArray(bcsId));
+ }
+
+ // Set bytes used.
+ // commitSpace for Open Containers relies on usedBytes
+ byte[] bytesUsed =
+ containerDB.getStore().get(DB_CONTAINER_BYTES_USED_KEY);
+ if (bytesUsed != null) {
+ isBlockMetadataSet = true;
+ kvContainerData.setBytesUsed(Longs.fromByteArray(bytesUsed));
+ }
+
+ // Set block count.
+ byte[] blockCount = containerDB.getStore().get(DB_BLOCK_COUNT_KEY);
+ if (blockCount != null) {
+ isBlockMetadataSet = true;
+ kvContainerData.setKeyCount(Longs.fromByteArray(blockCount));
+ }
+ }
+
+ if (!isBlockMetadataSet) {
+ initializeUsedBytesAndBlockCount(kvContainerData);
+ }
+ }
+
+
+ /**
+ * Initialize bytes used and block count.
+ * @param kvContainerData
+ * @throws IOException
+ */
+ private static void initializeUsedBytesAndBlockCount(
+ KeyValueContainerData kvContainerData) throws IOException {
+
+ long blockCount = 0;
+ try (KeyValueBlockIterator blockIter = new KeyValueBlockIterator(
+ kvContainerData.getContainerID(),
+ new File(kvContainerData.getContainerPath()))) {
+ long usedBytes = 0;
+
+
+ boolean success = true;
+ while (success) {
Review comment:
This is done like this because hasNext will return
StorageContainerException when unable to parse block data.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]