Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,22 @@ public static void parseKVContainerData(KeyValueContainerData kvContainerData,
private static void initializeUsedBytesAndBlockCount(
KeyValueContainerData kvContainerData) throws IOException {

MetadataKeyFilters.KeyPrefixFilter filter =
new MetadataKeyFilters.KeyPrefixFilter();

// Ignore all blocks except those with no prefix, or those with
// #deleting# prefix.
filter.addFilter(OzoneConsts.DELETED_KEY_PREFIX, true)
.addFilter(OzoneConsts.DELETE_TRANSACTION_KEY_PREFIX, true)
.addFilter(OzoneConsts.BLOCK_COMMIT_SEQUENCE_ID_PREFIX, true)
.addFilter(OzoneConsts.BLOCK_COUNT, true)
.addFilter(OzoneConsts.CONTAINER_BYTES_USED, true)
.addFilter(OzoneConsts.PENDING_DELETE_BLOCK_COUNT, true);

long blockCount = 0;
try (KeyValueBlockIterator blockIter = new KeyValueBlockIterator(
kvContainerData.getContainerID(),
new File(kvContainerData.getContainerPath()))) {
new File(kvContainerData.getContainerPath()), filter)) {
long usedBytes = 0;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import java.util.UUID;

import static org.apache.hadoop.ozone.OzoneConsts.DB_BLOCK_COUNT_KEY;
import static org.apache.hadoop.ozone.OzoneConsts.DB_CONTAINER_BYTES_USED_KEY;
import static org.apache.hadoop.ozone.OzoneConsts.DB_PENDING_DELETE_BLOCK_COUNT_KEY;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
Expand Down Expand Up @@ -139,17 +138,10 @@ private void markBlocksForDelete(KeyValueContainer keyValueContainer,
}

if (setMetaData) {
// Pending delete blocks are still counted towards the block count
// and bytes used metadata values, so those do not change.
metadataStore.getStore().put(DB_PENDING_DELETE_BLOCK_COUNT_KEY,
Longs.toByteArray(count));
long blkCount = Longs.fromByteArray(
metadataStore.getStore().get(DB_BLOCK_COUNT_KEY));
metadataStore.getStore().put(DB_BLOCK_COUNT_KEY,
Longs.toByteArray(blkCount - count));
long bytesUsed = Longs.fromByteArray(
metadataStore.getStore().get(DB_CONTAINER_BYTES_USED_KEY));
metadataStore.getStore().put(DB_CONTAINER_BYTES_USED_KEY,
Longs.toByteArray(bytesUsed - (count * blockLen)));

}
}

Expand Down Expand Up @@ -210,10 +202,10 @@ public void testContainerReader() throws Exception {
keyValueContainer.getContainerData();

// Verify block related metadata.
Assert.assertEquals(blockCount - i,
Assert.assertEquals(blockCount,
keyValueContainerData.getKeyCount());

Assert.assertEquals((blockCount - i) * blockLen,
Assert.assertEquals(blockCount * blockLen,
keyValueContainerData.getBytesUsed());

Assert.assertEquals(i,
Expand Down