You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "priyeshkaratha (via GitHub)" <gi...@apache.org> on 2025/09/15 07:47:20 UTC

[PR] HDDS-13664. DN data distribution upgrade finalisation. [ozone]

priyeshkaratha opened a new pull request, #9036:
URL: https://github.com/apache/ozone/pull/9036

   ## What changes were proposed in this pull request?
   This PR introduces refactors the pending deletion metadata handling logic and comprehensive integration testing for the DataNode data distribution feature upgrade scenario. 
   The changes include:
   
   1. **Code Refactoring**: Refactored to improve the pending deletion metadata handling: `KeyValueContainerUtil.java`
       - Extracted `populatePendingDeletionMetadata()` method for better separation of concerns
       - Added separate handler methods for different upgrade states
       - Enhanced the conditional logic to properly handle DATA_DISTRIBUTION feature finalization
       - Improved code readability and maintainability
   2. **Integration Test Addition**: Created with comprehensive test coverage for the DN data distribution upgrade scenario, specifically validating: `TestDNDataDistributionFinalization.java`
       - Pre-finalization behavior (handlePreDataDistributionFeature path)
       - Post-finalization behavior (handlePostDataDistributionFeature path)
       - Missing metadata recalculation scenario (getAggregatePendingDelete path)
   
   ## What is the link to the Apache JIRA
   HDDS-13664
   ## How was this patch tested?
   Tested using integration added integration tests.


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on PR #9036:
URL: https://github.com/apache/ozone/pull/9036#issuecomment-3350086410

   > Why does the title of this PR refer to datanode upgrade finalization but the code changes do not add a datanode layout feature?
   
   updated the title. There is no upgrade actions. 


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on PR #9036:
URL: https://github.com/apache/ozone/pull/9036#issuecomment-3404883578

   Thank you @ChenSammi for the review and I have addressed all your comments in latest commit.


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2431051400


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +645,16 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status
-      long pendingBytes = containerData.getBlockPendingDeletionBytes() + delTX.getTotalBlockSize();
+      long pendingBytes = containerData.getBlockPendingDeletionBytes();
+      if (delTX.hasTotalBlockSize()) {

Review Comment:
   It's better to include all pendingBytes operations under the if scope, like this
   
   // update in-memory pending deletion blocks size container status and persistent
   If (VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION)) && delTX.hasTotalBlockSize()) {
         long pendingBytes = containerData.getBlockPendingDeletionBytes();
         pendingBytes += delTX.getTotalBlockSize();
         metadataTable
             .putWithBatch(batchOperation,
                 containerData.getPendingDeleteBlockBytesKey(),
                 pendingBytes);
    }
   
   The base rule is if the feature is not finalized, we should avoid persist any data introduced by the feature permanently. 



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Persist pendingDeleteBytes only when feature is finalized [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2434997528


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +647,17 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status

Review Comment:
   @priyeshkaratha , there is one more place that pendingDeleteBytes is persisted without check the feature finalized or not, KeyValueContainerMetadataInspector#checkAndRepair.  We can skip the pendingDeleteBytes check and repair if feature is not finalized. 



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Persist pendingDeleteBytes only when feature is finalized [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2434987470


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +647,17 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status

Review Comment:
   Can you refactor these two lines of comments to make it correct? 



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. DN data distribution upgrade finalisation. [ozone]

Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #9036:
URL: https://github.com/apache/ozone/pull/9036#issuecomment-3294159546

   Why does the title of this PR refer to datanode upgrade finalization but the code changes do not add a datanode layout feature?


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2431107067


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestDNDataDistributionFinalization.java:
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.upgrade;
+
+import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT;
+import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL;
+import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.ScmConfig;
+import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
+import org.apache.hadoop.hdds.scm.server.SCMConfigurator;
+import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
+import org.apache.hadoop.hdds.scm.server.upgrade.SCMUpgradeFinalizationContext;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
+import org.apache.hadoop.ozone.UniformDatanodesFactory;
+import org.apache.hadoop.ozone.client.BucketArgs;
+import org.apache.hadoop.ozone.client.ObjectStore;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneClientFactory;
+import org.apache.hadoop.ozone.client.OzoneVolume;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.container.common.impl.ContainerSet;
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
+import org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
+import org.apache.hadoop.ozone.upgrade.UpgradeFinalizationExecutor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests upgrade finalization failure scenarios and corner cases specific to DN data distribution feature.
+ */
+public class TestDNDataDistributionFinalization {
+  private static final String CLIENT_ID = UUID.randomUUID().toString();
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TestDNDataDistributionFinalization.class);
+
+  private StorageContainerLocationProtocol scmClient;
+  private MiniOzoneHAClusterImpl cluster;
+
+  private static final int NUM_DATANODES = 3;
+  private static final int NUM_SCMS = 3;
+  private Future<?> finalizationFuture;
+  private final String volumeName = UUID.randomUUID().toString();
+  private final String bucketName = UUID.randomUUID().toString();
+  private OzoneBucket bucket;
+
+  @AfterEach
+  public void cleanup() {
+    if (cluster != null) {
+      cluster.shutdown();
+    }
+  }
+
+  public void init(OzoneConfiguration conf,
+                   UpgradeFinalizationExecutor<SCMUpgradeFinalizationContext> executor,
+                   boolean doFinalize) throws Exception {
+
+    SCMConfigurator configurator = new SCMConfigurator();
+    configurator.setUpgradeFinalizationExecutor(executor);
+
+    conf.setInt(SCMStorageConfig.TESTING_INIT_LAYOUT_VERSION_KEY, HDDSLayoutFeature.HBASE_SUPPORT.layoutVersion());
+    conf.setTimeDuration(OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 100,
+        TimeUnit.MILLISECONDS);
+    conf.setTimeDuration(OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 100,
+        TimeUnit.MILLISECONDS);
+    conf.setTimeDuration(OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL,
+        100, TimeUnit.MILLISECONDS);
+    ScmConfig scmConfig = conf.getObject(ScmConfig.class);
+    scmConfig.setBlockDeletionInterval(Duration.ofMillis(100));
+    conf.setFromObject(scmConfig);
+    conf.set(HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT, "0s");
+
+    DatanodeConfiguration dnConf =
+        conf.getObject(DatanodeConfiguration.class);
+    dnConf.setBlockDeletionInterval(Duration.ofMillis(100));
+    conf.setFromObject(dnConf);
+
+    MiniOzoneHAClusterImpl.Builder clusterBuilder = MiniOzoneCluster.newHABuilder(conf);
+    clusterBuilder.setNumOfStorageContainerManagers(NUM_SCMS)
+        .setNumOfActiveSCMs(NUM_SCMS)
+        .setSCMServiceId("scmservice")
+        .setOMServiceId("omServiceId")
+        .setNumOfOzoneManagers(1)
+        .setSCMConfigurator(configurator)
+        .setNumDatanodes(NUM_DATANODES)
+        .setDatanodeFactory(UniformDatanodesFactory.newBuilder()
+            .setLayoutVersion(HDDSLayoutFeature.INITIAL_VERSION.layoutVersion())
+            .build());
+    this.cluster = clusterBuilder.build();
+
+    scmClient = cluster.getStorageContainerLocationClient();
+    cluster.waitForClusterToBeReady();
+    assertEquals(HDDSLayoutFeature.HBASE_SUPPORT.layoutVersion(), scmClient.getScmInfo().getMetaDataLayoutVersion());
+
+    // Create Volume and Bucket
+    try (OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(conf)) {
+      ObjectStore store = ozoneClient.getObjectStore();
+      store.createVolume(volumeName);
+      OzoneVolume volume = store.getVolume(volumeName);
+      BucketArgs.Builder builder = BucketArgs.newBuilder();
+      volume.createBucket(bucketName, builder.build());
+      bucket = volume.getBucket(bucketName);
+    }
+
+    // Launch finalization from the client. In the current implementation,
+    // this call will block until finalization completes. If the test
+    // involves restarts or leader changes the client may be disconnected,
+    // but finalization should still proceed.
+    if (doFinalize) {
+      finalizationFuture = Executors.newSingleThreadExecutor().submit(
+          () -> {
+            try {
+              scmClient.finalizeScmUpgrade(CLIENT_ID);
+            } catch (IOException ex) {
+              LOG.info("finalization client failed. This may be expected if the" +
+                  " test injected failures.", ex);
+            }
+          });
+    }
+  }
+
+  /**
+   * Test that validates the upgrade scenario for DN data distribution feature.
+   * This test specifically checks the conditions in populatePendingDeletionMetadata:
+   * 1. Pre-finalization: handlePreDataDistributionFeature path
+   * 2. Post-finalization: handlePostDataDistributionFeature path
+   * 3. Missing metadata: getAggregatePendingDelete path
+   */
+  @Test
+  public void testDataDistributionUpgradeScenario() throws Exception {
+    init(new OzoneConfiguration(), null, false);
+
+    // Verify initial state - DATA_DISTRIBUTION should not be finalized yet
+    assertEquals(HDDSLayoutFeature.HBASE_SUPPORT.layoutVersion(),
+        scmClient.getScmInfo().getMetaDataLayoutVersion());
+
+    // Create some data and delete operations to trigger pending deletion logic
+    String keyName1 = "testKey1";
+    String keyName2 = "testKey2";
+    byte[] data = new byte[1024];
+
+    // Write some keys
+    try (OzoneOutputStream out = bucket.createKey(keyName1, data.length)) {
+      out.write(data);
+    }
+    try (OzoneOutputStream out = bucket.createKey(keyName2, data.length)) {
+      out.write(data);
+    }
+
+    // Delete one key to create pending deletion blocks
+    bucket.deleteKey(keyName1);
+
+    // Validate pre-finalization state
+    validatePreDataDistributionFeatureState();
+
+    // Now trigger finalization
+    finalizationFuture = Executors.newSingleThreadExecutor().submit(
+        () -> {
+          try {
+            scmClient.finalizeScmUpgrade(CLIENT_ID);
+          } catch (IOException ex) {
+            LOG.info("finalization client failed. This may be expected if the" +
+                " test injected failures.", ex);
+          }
+        });
+
+    // Wait for finalization to complete
+    finalizationFuture.get();
+    TestHddsUpgradeUtils.waitForFinalizationFromClient(scmClient, CLIENT_ID);
+
+    // Verify finalization completed
+    assertEquals(HDDSLayoutFeature.DATA_DISTRIBUTION.layoutVersion(),
+        scmClient.getScmInfo().getMetaDataLayoutVersion());
+
+    // Create more data and deletions to test post-finalization behavior
+    String keyName3 = "testKey3";
+    try (OzoneOutputStream out = bucket.createKey(keyName3, data.length)) {
+      out.write(data);
+    }
+    bucket.deleteKey(keyName2);
+    bucket.deleteKey(keyName3);
+
+    // Validate post-finalization state
+    validatePostDataDistributionFeatureState();
+  }
+
+  /**
+   * Test specifically for the missing metadata scenario that triggers
+   * the getAggregatePendingDelete code path.
+   */
+  @Test
+  public void testMissingPendingDeleteMetadataRecalculation() throws Exception {
+    init(new OzoneConfiguration(), null, true);
+
+    // Create and delete keys to generate some pending deletion data
+    String keyName = "testKeyForRecalc";
+    byte[] data = new byte[2048];
+
+    try (OzoneOutputStream out = bucket.createKey(keyName, data.length)) {
+      out.write(data);
+    }
+    bucket.deleteKey(keyName);
+
+    // Wait for finalization
+    finalizationFuture.get();

Review Comment:
   Can we move the file deletion before start the finalization process, to make sure the recalculation to happen? 



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2431362841


##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestDNDataDistributionFinalization.java:
##########
@@ -0,0 +1,337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hdds.upgrade;
+
+import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT;
+import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL;
+import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.ScmConfig;
+import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
+import org.apache.hadoop.hdds.scm.server.SCMConfigurator;
+import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
+import org.apache.hadoop.hdds.scm.server.upgrade.SCMUpgradeFinalizationContext;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
+import org.apache.hadoop.ozone.UniformDatanodesFactory;
+import org.apache.hadoop.ozone.client.BucketArgs;
+import org.apache.hadoop.ozone.client.ObjectStore;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneClientFactory;
+import org.apache.hadoop.ozone.client.OzoneVolume;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.container.common.impl.ContainerSet;
+import org.apache.hadoop.ozone.container.common.interfaces.Container;
+import org.apache.hadoop.ozone.container.common.statemachine.DatanodeConfiguration;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer;
+import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData;
+import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
+import org.apache.hadoop.ozone.upgrade.UpgradeFinalizationExecutor;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests upgrade finalization failure scenarios and corner cases specific to DN data distribution feature.
+ */
+public class TestDNDataDistributionFinalization {
+  private static final String CLIENT_ID = UUID.randomUUID().toString();
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TestDNDataDistributionFinalization.class);
+
+  private StorageContainerLocationProtocol scmClient;
+  private MiniOzoneHAClusterImpl cluster;
+
+  private static final int NUM_DATANODES = 3;
+  private static final int NUM_SCMS = 3;
+  private Future<?> finalizationFuture;
+  private final String volumeName = UUID.randomUUID().toString();
+  private final String bucketName = UUID.randomUUID().toString();
+  private OzoneBucket bucket;
+
+  @AfterEach
+  public void cleanup() {
+    if (cluster != null) {
+      cluster.shutdown();
+    }
+  }
+
+  public void init(OzoneConfiguration conf,
+                   UpgradeFinalizationExecutor<SCMUpgradeFinalizationContext> executor,
+                   boolean doFinalize) throws Exception {
+
+    SCMConfigurator configurator = new SCMConfigurator();
+    configurator.setUpgradeFinalizationExecutor(executor);
+
+    conf.setInt(SCMStorageConfig.TESTING_INIT_LAYOUT_VERSION_KEY, HDDSLayoutFeature.HBASE_SUPPORT.layoutVersion());
+    conf.setTimeDuration(OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 100,
+        TimeUnit.MILLISECONDS);
+    conf.setTimeDuration(OZONE_BLOCK_DELETING_SERVICE_INTERVAL, 100,
+        TimeUnit.MILLISECONDS);
+    conf.setTimeDuration(OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL,
+        100, TimeUnit.MILLISECONDS);
+    ScmConfig scmConfig = conf.getObject(ScmConfig.class);
+    scmConfig.setBlockDeletionInterval(Duration.ofMillis(100));
+    conf.setFromObject(scmConfig);
+    conf.set(HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT, "0s");
+
+    DatanodeConfiguration dnConf =
+        conf.getObject(DatanodeConfiguration.class);
+    dnConf.setBlockDeletionInterval(Duration.ofMillis(100));
+    conf.setFromObject(dnConf);
+
+    MiniOzoneHAClusterImpl.Builder clusterBuilder = MiniOzoneCluster.newHABuilder(conf);
+    clusterBuilder.setNumOfStorageContainerManagers(NUM_SCMS)
+        .setNumOfActiveSCMs(NUM_SCMS)
+        .setSCMServiceId("scmservice")
+        .setOMServiceId("omServiceId")
+        .setNumOfOzoneManagers(1)
+        .setSCMConfigurator(configurator)
+        .setNumDatanodes(NUM_DATANODES)
+        .setDatanodeFactory(UniformDatanodesFactory.newBuilder()
+            .setLayoutVersion(HDDSLayoutFeature.INITIAL_VERSION.layoutVersion())
+            .build());
+    this.cluster = clusterBuilder.build();
+
+    scmClient = cluster.getStorageContainerLocationClient();
+    cluster.waitForClusterToBeReady();
+    assertEquals(HDDSLayoutFeature.HBASE_SUPPORT.layoutVersion(), scmClient.getScmInfo().getMetaDataLayoutVersion());
+
+    // Create Volume and Bucket
+    try (OzoneClient ozoneClient = OzoneClientFactory.getRpcClient(conf)) {
+      ObjectStore store = ozoneClient.getObjectStore();
+      store.createVolume(volumeName);
+      OzoneVolume volume = store.getVolume(volumeName);
+      BucketArgs.Builder builder = BucketArgs.newBuilder();
+      volume.createBucket(bucketName, builder.build());
+      bucket = volume.getBucket(bucketName);
+    }
+
+    // Launch finalization from the client. In the current implementation,
+    // this call will block until finalization completes. If the test
+    // involves restarts or leader changes the client may be disconnected,
+    // but finalization should still proceed.
+    if (doFinalize) {
+      finalizationFuture = Executors.newSingleThreadExecutor().submit(
+          () -> {
+            try {
+              scmClient.finalizeScmUpgrade(CLIENT_ID);
+            } catch (IOException ex) {
+              LOG.info("finalization client failed. This may be expected if the" +
+                  " test injected failures.", ex);
+            }
+          });
+    }
+  }
+
+  /**
+   * Test that validates the upgrade scenario for DN data distribution feature.
+   * This test specifically checks the conditions in populatePendingDeletionMetadata:
+   * 1. Pre-finalization: handlePreDataDistributionFeature path
+   * 2. Post-finalization: handlePostDataDistributionFeature path
+   * 3. Missing metadata: getAggregatePendingDelete path
+   */
+  @Test
+  public void testDataDistributionUpgradeScenario() throws Exception {
+    init(new OzoneConfiguration(), null, false);
+
+    // Verify initial state - DATA_DISTRIBUTION should not be finalized yet
+    assertEquals(HDDSLayoutFeature.HBASE_SUPPORT.layoutVersion(),
+        scmClient.getScmInfo().getMetaDataLayoutVersion());
+
+    // Create some data and delete operations to trigger pending deletion logic
+    String keyName1 = "testKey1";
+    String keyName2 = "testKey2";
+    byte[] data = new byte[1024];
+
+    // Write some keys
+    try (OzoneOutputStream out = bucket.createKey(keyName1, data.length)) {
+      out.write(data);
+    }
+    try (OzoneOutputStream out = bucket.createKey(keyName2, data.length)) {
+      out.write(data);
+    }
+
+    // Delete one key to create pending deletion blocks
+    bucket.deleteKey(keyName1);
+
+    // Validate pre-finalization state
+    validatePreDataDistributionFeatureState();
+
+    // Now trigger finalization
+    finalizationFuture = Executors.newSingleThreadExecutor().submit(
+        () -> {
+          try {
+            scmClient.finalizeScmUpgrade(CLIENT_ID);
+          } catch (IOException ex) {
+            LOG.info("finalization client failed. This may be expected if the" +
+                " test injected failures.", ex);
+          }
+        });
+
+    // Wait for finalization to complete
+    finalizationFuture.get();
+    TestHddsUpgradeUtils.waitForFinalizationFromClient(scmClient, CLIENT_ID);
+
+    // Verify finalization completed
+    assertEquals(HDDSLayoutFeature.DATA_DISTRIBUTION.layoutVersion(),
+        scmClient.getScmInfo().getMetaDataLayoutVersion());
+
+    // Create more data and deletions to test post-finalization behavior
+    String keyName3 = "testKey3";
+    try (OzoneOutputStream out = bucket.createKey(keyName3, data.length)) {
+      out.write(data);
+    }
+    bucket.deleteKey(keyName2);
+    bucket.deleteKey(keyName3);
+
+    // Validate post-finalization state
+    validatePostDataDistributionFeatureState();
+  }
+
+  /**
+   * Test specifically for the missing metadata scenario that triggers
+   * the getAggregatePendingDelete code path.
+   */
+  @Test
+  public void testMissingPendingDeleteMetadataRecalculation() throws Exception {
+    init(new OzoneConfiguration(), null, true);
+
+    // Create and delete keys to generate some pending deletion data
+    String keyName = "testKeyForRecalc";
+    byte[] data = new byte[2048];
+
+    try (OzoneOutputStream out = bucket.createKey(keyName, data.length)) {
+      out.write(data);
+    }
+    bucket.deleteKey(keyName);
+
+    // Wait for finalization
+    finalizationFuture.get();

Review Comment:
   Yes



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2431076888


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/keyvalue/helpers/KeyValueContainerUtil.java:
##########
@@ -405,6 +362,78 @@ private static void populateContainerMetadata(
     populateContainerFinalizeBlock(kvContainerData, store);
   }
 
+  private static PendingDelete populatePendingDeletionMetadata(
+      KeyValueContainerData kvContainerData, Table<String, Long> metadataTable,
+      DatanodeStore store) throws IOException {
+
+    Long pendingDeletionBlockBytes = metadataTable.get(kvContainerData.getPendingDeleteBlockBytesKey());
+    Long pendingDeleteBlockCount = metadataTable.get(kvContainerData.getPendingDeleteBlockCountKey());
+
+    if (!VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION)) {
+      return handlePreDataDistributionFeature(pendingDeleteBlockCount, metadataTable, store, kvContainerData);
+    } else if (pendingDeleteBlockCount != null) {
+      return handlePostDataDistributionFeature(pendingDeleteBlockCount, pendingDeletionBlockBytes,
+          metadataTable, store, kvContainerData);
+    } else {
+      LOG.warn("Missing pendingDeleteBlockCount/size from {}: recalculate them from delete txn tables",
+          metadataTable.getName());
+      return getAggregatePendingDelete(store, kvContainerData, kvContainerData.getSchemaVersion());
+    }
+  }
+
+  private static PendingDelete handlePreDataDistributionFeature(
+      Long pendingDeleteBlockCount, Table<String, Long> metadataTable,
+      DatanodeStore store, KeyValueContainerData kvContainerData) throws IOException {
+
+    if (pendingDeleteBlockCount != null) {
+      return new PendingDelete(pendingDeleteBlockCount, 0L);
+    } else {
+      LOG.warn("Missing pendingDeleteBlockCount/size from {}: recalculate them from delete txn tables",
+          metadataTable.getName());
+      return getAggregatePendingDelete(store, kvContainerData, kvContainerData.getSchemaVersion());
+    }
+  }
+
+  private static PendingDelete handlePostDataDistributionFeature(
+      Long pendingDeleteBlockCount, Long pendingDeletionBlockBytes,
+      Table<String, Long> metadataTable, DatanodeStore store,
+      KeyValueContainerData kvContainerData) throws IOException {
+
+    if (pendingDeletionBlockBytes != null) {
+      return new PendingDelete(pendingDeleteBlockCount, pendingDeletionBlockBytes);
+    } else {
+      LOG.warn("Missing pendingDeleteBlocksize from {}: recalculate them from delete txn tables",

Review Comment:
   pendingDeleteBlocksize -> pendingDeleteBlockSize



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. DN data distribution upgrade finalisation. [ozone]

Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on PR #9036:
URL: https://github.com/apache/ozone/pull/9036#issuecomment-3291152034

   @ChenSammi @sumitagrawl Can you please review the changes?


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Persist pendingDeleteBytes only when feature is finalized [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi merged PR #9036:
URL: https://github.com/apache/ozone/pull/9036


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "errose28 (via GitHub)" <gi...@apache.org>.
errose28 commented on PR #9036:
URL: https://github.com/apache/ozone/pull/9036#issuecomment-3353203581

   I see the layout feature was added earlier in the [feature branch](https://github.com/apache/ozone/pull/8566/files#diff-82cd1a32d63bebee797d30d0497debf782165d3ce81cb1b339db780fb3b563f5). Please update the [design doc](https://github.com/apache/ozone/pull/8907) with information why a layout feature is required for this. From what I can tell we are only adding new information, which does not usually require layout features.


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Persist pendingDeleteBytes only when feature is finalized [ozone]

Posted by "priyeshkaratha (via GitHub)" <gi...@apache.org>.
priyeshkaratha commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2435086119


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +647,17 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status

Review Comment:
   Handled checkAndRepair. Validated failed testcase locally and it is passing.



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Persist pendingDeleteBytes only when feature is finalized [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on PR #9036:
URL: https://github.com/apache/ozone/pull/9036#issuecomment-3410182733

   Thanks @priyeshkaratha. 


-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Persist pendingDeleteBytes only when feature is finalized [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2434997528


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +647,17 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status

Review Comment:
   @priyeshkaratha , there is one more place that pendingDeleteBytes is persisted without check the feature finalized or not, KeyValueContainerMetadataInspector#checkAndRepair.  We can skip the pendingDeleteBytes check and repair if feature is not finalized. 
   
   Please also check and run the fail test locally to see if it's related. 



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2431095094


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +645,16 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status
-      long pendingBytes = containerData.getBlockPendingDeletionBytes() + delTX.getTotalBlockSize();
+      long pendingBytes = containerData.getBlockPendingDeletionBytes();
+      if (delTX.hasTotalBlockSize()) {

Review Comment:
   Priyesh, we also need to 
   a. add the If (VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION)) check in 
    resetPendingDeleteBlockCount()
   b. do the null check in KeyValueContainerMetadataInspector#getDBMetadataJson



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-13664. Handle metadata read while restarting considering feature finalization. [ozone]

Posted by "ChenSammi (via GitHub)" <gi...@apache.org>.
ChenSammi commented on code in PR #9036:
URL: https://github.com/apache/ozone/pull/9036#discussion_r2431051400


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/commandhandler/DeleteBlocksCommandHandler.java:
##########
@@ -645,12 +645,16 @@ private void updateMetaData(KeyValueContainerData containerData,
 
       // update pending deletion blocks count and delete transaction ID in
       // in-memory container status
-      long pendingBytes = containerData.getBlockPendingDeletionBytes() + delTX.getTotalBlockSize();
+      long pendingBytes = containerData.getBlockPendingDeletionBytes();
+      if (delTX.hasTotalBlockSize()) {

Review Comment:
   It's better to include all pendingBytes operations under the if scope, like this
   
   // update in-memory pending deletion blocks size container status and persistent
   If (VersionedDatanodeFeatures.isFinalized(HDDSLayoutFeature.DATA_DISTRIBUTION)) && delTX.hasTotalBlockSize()) {
         long pendingBytes = containerData.getBlockPendingDeletionBytes();
         pendingBytes += delTX.getTotalBlockSize();
         metadataTable
             .putWithBatch(batchOperation,
                 containerData.getPendingDeleteBlockBytesKey(),
                 pendingBytes);
    }



-- 
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-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org