diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ContainerInfo.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ContainerInfo.java index 427c08b9de1..311c1180aae 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ContainerInfo.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/scm/container/common/helpers/ContainerInfo.java @@ -212,6 +212,7 @@ public class ContainerInfo implements Comparator, public HddsProtos.SCMContainerInfo getProtobuf() { HddsProtos.SCMContainerInfo.Builder builder = HddsProtos.SCMContainerInfo.newBuilder(); + Preconditions.checkState(containerID > 0); return builder.setAllocatedBytes(getAllocatedBytes()) .setContainerID(getContainerID()) .setUsedBytes(getUsedBytes()) diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java index 11863f29bd5..4076dad6230 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/container/ContainerMapping.java @@ -733,21 +733,7 @@ public class ContainerMapping implements Mapping { // return info of a deleted container. may revisit this in the future, // for now, just skip a not-found container if (containerBytes != null) { - HddsProtos.SCMContainerInfo oldInfoProto = - HddsProtos.SCMContainerInfo.PARSER.parseFrom(containerBytes); - ContainerInfo oldInfo = ContainerInfo.fromProtobuf(oldInfoProto); - ContainerInfo newInfo = new ContainerInfo.Builder() - .setAllocatedBytes(info.getAllocatedBytes()) - .setNumberOfKeys(oldInfo.getNumberOfKeys()) - .setOwner(oldInfo.getOwner()) - .setPipelineID(oldInfo.getPipelineID()) - .setState(oldInfo.getState()) - .setUsedBytes(oldInfo.getUsedBytes()) - .setDeleteTransactionId(oldInfo.getDeleteTransactionId()) - .setReplicationFactor(oldInfo.getReplicationFactor()) - .setReplicationType(oldInfo.getReplicationType()) - .build(); - containerStore.put(dbKey, newInfo.getProtobuf().toByteArray()); + containerStore.put(dbKey, info.getProtobuf().toByteArray()); } else { LOG.debug("Container state manager has container {} but not found " + "in container store, a deleted container?", 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 2dc7e9960a4..1e9c35b65df 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 @@ -360,4 +360,12 @@ public class TestContainerMapping { return containerInfo; } + @Test + public void testFlushAllContainers() throws IOException { + ContainerInfo info = createContainer(); + List containers = mapping.getStateManager().getAllContainers(); + Assert.assertTrue(containers.size() > 0); + mapping.flushContainerInfo(); + } + }