errose28 commented on code in PR #8604:
URL: https://github.com/apache/ozone/pull/8604#discussion_r2141352926
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -1441,6 +1441,14 @@ private ContainerProtos.ContainerChecksumInfo
updateAndGetContainerChecksum(Cont
if (updatedDataChecksum != originalDataChecksum) {
containerData.setDataChecksum(updatedDataChecksum);
+ try (DBHandle dbHandle = BlockUtils.getDB(containerData, conf)) {
Review Comment:
Let's add a comment that this value is only used on startup so if the DB
update fails we are ok with leaving the datanode running with the merkle tree
and in-memory value matching, leaving this to be retried on the next tree
update.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -1409,7 +1409,7 @@ private void
updateContainerChecksumFromMetadataIfNeeded(Container container) {
* This method does not send an ICR with the updated checksum info.
* @param container - Container for which the container merkle tree needs to
be updated.
*/
- private ContainerProtos.ContainerChecksumInfo
updateAndGetContainerChecksumFromMetadata(
+ public ContainerProtos.ContainerChecksumInfo
updateAndGetContainerChecksumFromMetadata(
Review Comment:
If this is only used for tests we should mark it as `@VisibleForTesting`.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/KeyValueContainerUtil.java:
##########
@@ -367,14 +370,23 @@ private static void populateContainerMetadata(
kvContainerData.markAsEmpty();
}
+ // Set container data checksum.
+ Long containerDataChecksum = metadataTable.get(
+ kvContainerData.getContainerDataChecksumKey());
+
+ if (containerDataChecksum != null) {
+ kvContainerData.setDataChecksum(containerDataChecksum);
+ } else if
(ContainerChecksumTreeManager.hasContainerChecksumFile(kvContainerData)) {
+ populateContainerDataChecksum(kvContainerData, metadataTable);
Review Comment:
`populateContainerDataChecksum` already has a check for the file existing,
so I think we can leave `hasContainerChecksumFile` private. Additionally I
think `populateContainerMetadata` should be the one writing to the table if the
value is present, since it already read from it. This is consistent with how
the other counters are updated. `populateContainerDataCheckum` would then just
fall back to deserializing the tree if it exists and getting the value from
there, and the name can be updated.
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/KeyValueHandler.java:
##########
@@ -1441,6 +1441,14 @@ private ContainerProtos.ContainerChecksumInfo
updateAndGetContainerChecksum(Cont
if (updatedDataChecksum != originalDataChecksum) {
containerData.setDataChecksum(updatedDataChecksum);
+ try (DBHandle dbHandle = BlockUtils.getDB(containerData, conf)) {
+
dbHandle.getStore().getMetadataTable().put(containerData.getContainerDataChecksumKey(),
updatedDataChecksum);
+ } catch (IOException e) {
+ LOG.error("Failed to update container data checksum in RocksDB for
container {}. " +
+ "Continuing with original checksum for RocksDB {}.",
containerData.getContainerID(),
+ originalDataChecksum, e);
Review Comment:
We should wrap this in `checksumToString`
##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/checksum/ContainerChecksumTreeManager.java:
##########
@@ -316,12 +317,12 @@ public static boolean
hasContainerChecksumFile(ContainerData data) {
*/
@VisibleForTesting
public static File getContainerChecksumFile(ContainerData data) {
Review Comment:
If we are using this when building the tar we should remove the
`@VisibleForTesting` annotation.
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/checksum/TestContainerChecksumTreeManager.java:
##########
@@ -97,7 +98,7 @@ public void init() {
container = mock(KeyValueContainerData.class);
when(container.getContainerID()).thenReturn(CONTAINER_ID);
when(container.getMetadataPath()).thenReturn(testDir.getAbsolutePath());
- checksumFile = new File(testDir, CONTAINER_ID + ".tree");
+ checksumFile = new File(testDir, CONTAINER_ID +
CONTAINER_DATA_CHECKSUM_EXTENSION);
Review Comment:
I deliberately hardcoded the path because changing the name of the file is
somewhat of an incompatible change and I wanted `testChecksumTreeFilePath` to
fail because of that. Maybe we can add a comment here explaining that in case
such a change happens in the future.
##########
hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/keyvalue/TestContainerReconciliationWithMockDatanodes.java:
##########
@@ -350,13 +350,18 @@ public
ContainerProtos.GetContainerChecksumInfoResponseProto getChecksumInfo(lon
*/
public long checkAndGetDataChecksum(long containerID) {
KeyValueContainer container = getContainer(containerID);
+ KeyValueContainerData containerData = container.getContainerData();
long dataChecksum = 0;
try {
Optional<ContainerProtos.ContainerChecksumInfo> containerChecksumInfo =
- handler.getChecksumManager().read(container.getContainerData());
+ handler.getChecksumManager().read(containerData);
assertTrue(containerChecksumInfo.isPresent());
dataChecksum =
containerChecksumInfo.get().getContainerMerkleTree().getDataChecksum();
- assertEquals(container.getContainerData().getDataChecksum(),
dataChecksum);
+ assertEquals(containerData.getDataChecksum(), dataChecksum);
+ try (DBHandle dbHandle = BlockUtils.getDB(containerData, conf)) {
+ Long dbDataChecksum =
dbHandle.getStore().getMetadataTable().get(containerData.getContainerDataChecksumKey());
+ assertEquals(containerData.getDataChecksum(), dbDataChecksum, "DB
should have the updated data checksum.");
+ }
Review Comment:
Can we add a helper method to `ContainerMerkleTreeTestUtils` that verifies
the checksum matches in memory, tree, and DB? I don't think the parameter list
would be too long. Then we can invoke that from other tests as needed.
--
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]