ptlrs commented on code in PR #7934:
URL: https://github.com/apache/ozone/pull/7934#discussion_r1972661198
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/TarContainerPacker.java:
##########
@@ -95,9 +101,19 @@ public byte[]
unpackContainerData(Container<KeyValueContainerData> container,
Files.createDirectories(destContainerDir);
}
if (FileUtils.isEmptyDirectory(destContainerDir.toFile())) {
+ // Before the atomic move, the destination dir is empty and doesn't have
a metadata directory.
+ // Writing the .container file will fail as the metadata dir doesn't
exist
+ Path containerMetadataPath =
Paths.get(container.getContainerData().getMetadataPath());
+ Path tempContainerMetadataPath = Paths.get(containerUntarDir.toString(),
+ containerMetadataPath.getName(containerMetadataPath.getNameCount() -
1).toString());
+
container.getContainerData().setMetadataPath(tempContainerMetadataPath.toString());
+ persistCustomContainerState(container, descriptorFileContent,
State.RECOVERING);
+
container.getContainerData().setMetadataPath(containerMetadataPath.toString());
Files.move(containerUntarDir, destContainerDir,
StandardCopyOption.ATOMIC_MOVE,
StandardCopyOption.REPLACE_EXISTING);
+ // Persist again to update the metadata path to point the destination dir
+ persistCustomContainerState(container, descriptorFileContent,
State.RECOVERING);
Review Comment:
We update the state before the atomic move. In the `.container` file that
gets generated, the metadata path points to the `containerUntarDir` because we
set it to that. See `tempContainerMetadataPath`.
Once we update the container's metadata path and persist again, the metadata
path is updated to the actual path within the `.container` file's content.
That's why we persist twice.
We need to do this because we can't directly persist the container file to
the `destContainerDir` as that path doesn't yet exist until the atomic move is
performed.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]