aswinshakil commented on code in PR #8402:
URL: https://github.com/apache/ozone/pull/8402#discussion_r2077847233
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/checksum/ContainerChecksumTreeManager.java:
##########
@@ -81,35 +81,45 @@ public void stop() {
* The data merkle tree within the file is replaced with the {@code tree}
parameter, but all other content of the
* file remains unchanged.
* Concurrent writes to the same file are coordinated internally.
+ * This method also updates the container's data checksum in the {@code
data} parameter, which will be seen by SCM
+ * on container reports.
*/
public ContainerProtos.ContainerChecksumInfo
writeContainerDataTree(ContainerData data,
-
ContainerMerkleTreeWriter tree)
- throws IOException {
+ ContainerMerkleTreeWriter tree) throws IOException {
long containerID = data.getContainerID();
+ // If there is an error generating the tree and we cannot obtain a final
checksum, use 0 to indicate a metadata
+ // failure.
+ long dataChecksum = 0;
+ ContainerProtos.ContainerChecksumInfo checksumInfo = null;
Lock writeLock = getLock(containerID);
writeLock.lock();
try {
ContainerProtos.ContainerChecksumInfo.Builder checksumInfoBuilder = null;
try {
// If the file is not present, we will create the data for the first
time. This happens under a write lock.
- checksumInfoBuilder = readBuilder(data)
- .orElse(ContainerProtos.ContainerChecksumInfo.newBuilder());
+ checksumInfoBuilder =
readBuilder(data).orElse(ContainerProtos.ContainerChecksumInfo.newBuilder());
} catch (IOException ex) {
- LOG.error("Failed to read container checksum tree file for container
{}. Overwriting it with a new instance.",
+ LOG.error("Failed to read container checksum tree file for container
{}. Creating a new instance.",
containerID, ex);
checksumInfoBuilder =
ContainerProtos.ContainerChecksumInfo.newBuilder();
}
- ContainerProtos.ContainerChecksumInfo checksumInfo = checksumInfoBuilder
+ ContainerProtos.ContainerMerkleTree treeProto =
captureLatencyNs(metrics.getCreateMerkleTreeLatencyNS(),
+ tree::toProto);
+ checksumInfoBuilder
.setContainerID(containerID)
-
.setContainerMerkleTree(captureLatencyNs(metrics.getCreateMerkleTreeLatencyNS(),
tree::toProto))
- .build();
+ .setContainerMerkleTree(treeProto);
+ checksumInfo = checksumInfoBuilder.build();
write(data, checksumInfo);
- LOG.debug("Data merkle tree for container {} updated", containerID);
- return checksumInfo;
+ // If write succeeds, update the checksum in memory. Otherwise 0 will be
used to indicate the metadata failure.
+ dataChecksum = treeProto.getDataChecksum();
+ LOG.debug("Data merkle tree for container {} updated with container
checksum {}", containerID, dataChecksum);
Review Comment:
~~If it is 0 we should show it as 0, and if it is not 0 then do the
`checksumToString` conversion. We can add this condition to `checksumToString`
to simplify this.~~ Just checked hex of 0 is 0. So we can ignore this comment.
Just need to add `checksumToString`
```suggestion
LOG.debug("Data merkle tree for container {} updated with container
checksum {}", containerID, checksumToString(dataChecksum));
```
--
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]