chungen0126 commented on code in PR #10246:
URL: https://github.com/apache/ozone/pull/10246#discussion_r3240721915


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerData.java:
##########
@@ -516,22 +529,32 @@ public String getOriginNodeId() {
   }
 
   /**
-   * Compute the checksum for ContainerData using the specified Yaml (based
-   * on ContainerType) and set the checksum.
+   * Compute the checksum for ContainerData and set the checksum.
    *
    * Checksum of ContainerData is calculated by setting the
    * {@link ContainerData#checksum} field to a 64-byte array with all 0's -
    * {@link ContainerData#ZERO_CHECKSUM}. After the checksum is calculated,
    * the checksum field is updated with this value.
    *
-   * @param yaml Yaml for ContainerType to get the ContainerData as Yaml String
    * @throws IOException
    */
-  public void computeAndSetContainerFileChecksum(Yaml yaml) throws IOException 
{
+  public void computeAndSetContainerFileChecksum() throws IOException {
     // Set checksum to dummy value - 0 byte array, to calculate the checksum
     // of rest of the data.
     this.checksum = ZERO_CHECKSUM;
 
+    // Create Yaml for checksum calculation that excludes storageType for 
backward compatibility
+    boolean withReplicaIndex = this instanceof KeyValueContainerData &&
+        ((KeyValueContainerData) this).getReplicaIndex() > 0;
+    // IMPORTANT: Pass null for storageType to ensure rollback compatibility.
+    // Ozone calculates checksum by reading the YAML file into a Java object, 
then converting
+    // it back to YAML string (not directly using the YAML file content).
+    // If storageType participates in checksum calculation, when rolling back 
to older versions that don't
+    // support storageType, they would recalculate checksum without 
storageType field
+    // (as it's unknown to them), causing checksum mismatch and validation 
failure.
+    Yaml yaml = ContainerDataYaml.getYamlForContainerType(

Review Comment:
   Please use `ContainerDataYaml.getYamlForContainerType(this.containerType, 
withReplicaIndex);` here. Alternatively, consider cleaning up the method 
`getYamlForContainerType(ContainerType containerType,
         boolean withReplicaIndex)` if it is no longer being invoked elsewhere.



-- 
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]

Reply via email to