sumitagrawl commented on code in PR #8360: URL: https://github.com/apache/ozone/pull/8360#discussion_r2081481107
########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueContainer.java: ########## @@ -173,6 +173,8 @@ public void create(VolumeSet volumeSet, VolumeChoosingPolicy // Set volume before getContainerDBFile(), because we may need the // volume to deduce the db file. containerData.setVolume(containerVolume); + // commit space has been reserved by volumeChoosingPolicy + containerData.setCommittedSpace(true); Review Comment: this needs to be done at VolumeChoosingPolicy call, as if any exception happens, it can be released at exception handler. This is as release logic check for committed Flag, and it will be false. ########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerData.java: ########## @@ -214,21 +213,14 @@ public synchronized void setState(ContainerDataProto.State state) { (state != oldState)) { releaseCommitSpace(); } + } - /** - * commit space when container transitions (back) to Open. - * when? perhaps closing a container threw an exception - */ - if ((state == ContainerDataProto.State.OPEN) && - (state != oldState)) { - Preconditions.checkState(getMaxSize() > 0); - commitSpace(); - } + public boolean isCommittedSpace() { Review Comment: this method is used only in testcases, we can define @VisibleForTesting ########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/ozoneimpl/ContainerReader.java: ########## @@ -202,50 +202,52 @@ public void verifyAndFixupContainerData(ContainerData containerData) throws IOException { switch (containerData.getContainerType()) { case KeyValueContainer: - if (containerData instanceof KeyValueContainerData) { - KeyValueContainerData kvContainerData = (KeyValueContainerData) - containerData; - containerData.setVolume(hddsVolume); - KeyValueContainerUtil.parseKVContainerData(kvContainerData, config); - KeyValueContainer kvContainer = new KeyValueContainer(kvContainerData, - config); - if (kvContainer.getContainerState() == RECOVERING) { - if (shouldDelete) { - // delete Ratis replicated RECOVERING containers - if (kvContainer.getContainerData().getReplicaIndex() == 0) { - cleanupContainer(hddsVolume, kvContainer); - } else { - kvContainer.markContainerUnhealthy(); - LOG.info("Stale recovering container {} marked UNHEALTHY", - kvContainerData.getContainerID()); - containerSet.addContainer(kvContainer); - } - } - return; - } - if (kvContainer.getContainerState() == DELETED) { - if (shouldDelete) { - cleanupContainer(hddsVolume, kvContainer); - } - return; - } - try { - containerSet.addContainer(kvContainer); - } catch (StorageContainerException e) { - if (e.getResult() != ContainerProtos.Result.CONTAINER_EXISTS) { - throw e; - } - if (shouldDelete) { - resolveDuplicate((KeyValueContainer) containerSet.getContainer( - kvContainer.getContainerData().getContainerID()), kvContainer); - } - } - } else { + if (!(containerData instanceof KeyValueContainerData)) { throw new StorageContainerException("Container File is corrupted. " + "ContainerType is KeyValueContainer but cast to " + "KeyValueContainerData failed. ", ContainerProtos.Result.CONTAINER_METADATA_ERROR); } + + KeyValueContainerData kvContainerData = (KeyValueContainerData) + containerData; + containerData.setVolume(hddsVolume); + KeyValueContainerUtil.parseKVContainerData(kvContainerData, config); + KeyValueContainer kvContainer = new KeyValueContainer(kvContainerData, + config); + if (kvContainer.getContainerState() == RECOVERING) { + if (shouldDelete) { + // delete Ratis replicated RECOVERING containers + if (kvContainer.getContainerData().getReplicaIndex() == 0) { + cleanupContainer(hddsVolume, kvContainer); + } else { + kvContainer.markContainerUnhealthy(); + LOG.info("Stale recovering container {} marked UNHEALTHY", + kvContainerData.getContainerID()); + containerSet.addContainer(kvContainer); + } + } + return; + } else if (kvContainer.getContainerState() == DELETED) { + if (shouldDelete) { + cleanupContainer(hddsVolume, kvContainer); + } + return; + } + + try { + containerSet.addContainer(kvContainer); + // this should be the last step of this block + containerData.commitSpace(); + } catch (StorageContainerException e) { + if (e.getResult() != ContainerProtos.Result.CONTAINER_EXISTS) { + throw e; + } + if (shouldDelete) { + resolveDuplicate((KeyValueContainer) containerSet.getContainer( Review Comment: need add commitSpace() based on final open container for resolveDuplicate; - if existing is removed, need release that commited space - if new is added, need add commit space -- 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: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org