From b3c5221f3091d394ef8c227f6776af07f7116658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Wed, 19 Sep 2018 14:51:03 +0200 Subject: [PATCH] HDDS-458. numberofKeys is 0 for all containers even when keys are present. Contributed by LiXin Ge. (cherry picked from commit 8600b049af184af04dfb93b6bc353740e3e821d3) --- .../container/keyvalue/KeyValueContainer.java | 1 + .../scm/container/TestContainerMapping.java | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java index b893a389f1..0870c76061 100644 --- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java +++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java @@ -521,6 +521,7 @@ public File getContainerFile() { .setWriteCount(containerData.getWriteCount()) .setReadBytes(containerData.getReadBytes()) .setWriteBytes(containerData.getWriteBytes()) + .setKeyCount(containerData.getKeyCount()) .setUsed(containerData.getBytesUsed()) .setState(getHddsState()) .setDeleteTransactionId(containerData.getDeleteTransactionId()); diff --git a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerMapping.java b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerMapping.java index 224f6dddca..f9a881e27d 100644 --- a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerMapping.java +++ b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/container/TestContainerMapping.java @@ -280,6 +280,52 @@ public void testFullContainerReport() throws Exception { } } + @Test + public void testListContainerAfterReport() throws Exception { + ContainerInfo info1 = createContainer(); + ContainerInfo info2 = createContainer(); + DatanodeDetails datanodeDetails = TestUtils.randomDatanodeDetails(); + List reports = + new ArrayList<>(); + StorageContainerDatanodeProtocolProtos.ContainerInfo.Builder ciBuilder = + StorageContainerDatanodeProtocolProtos.ContainerInfo.newBuilder(); + long cID1 = info1.getContainerID(); + long cID2 = info2.getContainerID(); + ciBuilder.setFinalhash("e16cc9d6024365750ed8dbd194ea46d2") + .setSize(1000000000L) + .setUsed(987654321L) + .setKeyCount(100000000L) + .setReadBytes(1000000000L) + .setWriteBytes(1000000000L) + .setContainerID(cID1); + reports.add(ciBuilder.build()); + + ciBuilder.setFinalhash("e16cc9d6024365750ed8dbd194ea54a9") + .setSize(1000000000L) + .setUsed(123456789L) + .setKeyCount(200000000L) + .setReadBytes(3000000000L) + .setWriteBytes(4000000000L) + .setContainerID(cID2); + reports.add(ciBuilder.build()); + + ContainerReportsProto.Builder crBuilder = ContainerReportsProto + .newBuilder(); + crBuilder.addAllReports(reports); + + mapping.processContainerReports(datanodeDetails, crBuilder.build(), false); + + List list = mapping.listContainer(0, 50); + Assert.assertEquals(2, list.stream().filter( + x -> x.getContainerID() == cID1 || x.getContainerID() == cID2).count()); + Assert.assertEquals(300000000L, list.stream().filter( + x -> x.getContainerID() == cID1 || x.getContainerID() == cID2) + .mapToLong(x -> x.getNumberOfKeys()).sum()); + Assert.assertEquals(1111111110L, list.stream().filter( + x -> x.getContainerID() == cID1 || x.getContainerID() == cID2) + .mapToLong(x -> x.getUsedBytes()).sum()); + } + @Test public void testCloseContainer() throws IOException { ContainerInfo info = createContainer();