This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new a6e57bc6f90 HDDS-17060. Recon keeps container CLOSED after SCM moves 
it from DELETING or DELETED back to QUASI_CLOSED (#12095)
a6e57bc6f90 is described below

commit a6e57bc6f902d3087ff77cd2222023aae1644842
Author: Arafat2198 <[email protected]>
AuthorDate: Thu Nov 26 21:14:29 2026 +0530

    HDDS-17060. Recon keeps container CLOSED after SCM moves it from DELETING 
or DELETED back to QUASI_CLOSED (#12095)
---
 .../recon/scm/ReconStorageContainerSyncHelper.java | 28 ++++++++
 .../scm/TestReconSCMContainerSyncIntegration.java  | 83 +++++++++++++++++++++-
 2 files changed, 109 insertions(+), 2 deletions(-)

diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerSyncHelper.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerSyncHelper.java
index 439f596fbc6..5187df5cafb 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerSyncHelper.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/scm/ReconStorageContainerSyncHelper.java
@@ -38,6 +38,7 @@
 import java.util.concurrent.atomic.AtomicLong;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto;
 import org.apache.hadoop.hdds.scm.container.ContainerID;
 import org.apache.hadoop.hdds.scm.container.ContainerInfo;
 import org.apache.hadoop.hdds.scm.container.ContainerNotFoundException;
@@ -299,6 +300,20 @@ private int reconcileToQuasiClosed(ContainerID containerID,
             containerID);
         return 1;
       }
+      // SCM moves a CLOSED container back to QUASI_CLOSED only through 
DELETING or DELETED, which Recon
+      // may not have copied. Recon is ahead of SCM only when it closed the 
container from a CLOSED replica
+      // that SCM has not processed yet. DELETING here is that same move, 
stopped between the two steps.
+      if (reconState == HddsProtos.LifeCycleState.DELETING
+          || (reconState == HddsProtos.LifeCycleState.CLOSED && 
!hasClosedReplica(reconContainer))) {
+        if (reconState == HddsProtos.LifeCycleState.CLOSED) {
+          containerManager.updateContainerState(containerID, DELETE);
+        }
+        containerManager.transitionDeletingOrDeletedToTargetState(
+            containerID, HddsProtos.LifeCycleState.QUASI_CLOSED);
+        LOG.info("Container {} moved from {} back to QUASI_CLOSED based on SCM 
state.",
+            containerID, reconState);
+        return 1;
+      }
       LOG.debug("Skipping container {} because SCM reports QUASI_CLOSED while "
           + "Recon has state {}.", containerID, reconState);
     } catch (InvalidStateTransitionException | IOException e) {
@@ -308,6 +323,19 @@ private int reconcileToQuasiClosed(ContainerID containerID,
     return 0;
   }
 
+  /**
+   * Returns true iff Recon has a CLOSED replica whose sequence ID matches the 
container's.
+   * A stale CLOSED replica (older sequence) is treated the same as a 
non-CLOSED replica: SCM
+   * would not close the container on its basis, so it cannot be evidence that 
Recon is ahead.
+   */
+  private boolean hasClosedReplica(ContainerInfo container) throws 
ContainerNotFoundException {
+    long containerSeq = container.getSequenceId();
+    return 
containerManager.getContainerReplicas(container.containerID()).stream()
+        .anyMatch(replica -> replica.getState() == 
ContainerReplicaProto.State.CLOSED
+            && replica.getSequenceId() != null
+            && replica.getSequenceId() == containerSeq);
+  }
+
   private int reconcileToClosed(ContainerID containerID,
                                 ContainerInfo reconContainer,
                                 HddsProtos.LifeCycleState reconState) {
diff --git 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconSCMContainerSyncIntegration.java
 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconSCMContainerSyncIntegration.java
index 0d869f9b755..4fb96371ba8 100644
--- 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconSCMContainerSyncIntegration.java
+++ 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/scm/TestReconSCMContainerSyncIntegration.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.ozone.recon.scm;
 
 import static 
org.apache.hadoop.fs.CommonConfigurationKeys.IPC_MAXIMUM_DATA_LENGTH;
+import static 
org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails;
 import static 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.DELETE;
 import static 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleEvent.FINALIZE;
 import static 
org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState.CLOSED;
@@ -52,8 +53,10 @@
 import java.util.stream.LongStream;
 import org.apache.hadoop.hdds.client.StandaloneReplicationConfig;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos.LifeCycleState;
+import 
org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReplicaProto;
 import org.apache.hadoop.hdds.scm.container.ContainerID;
 import org.apache.hadoop.hdds.scm.container.ContainerInfo;
+import org.apache.hadoop.hdds.scm.container.ContainerReplica;
 import 
org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
 import org.apache.hadoop.hdds.scm.ha.SCMHADBTransactionBuffer;
 import org.apache.hadoop.ozone.recon.ReconServerConfigKeys;
@@ -187,6 +190,20 @@ private void seedRecon(long startId, int count, 
LifeCycleState state)
    * Seeds Recon with {@code count} OPEN containers and then transitions each
    * one to CLOSING so that Pass 1 can exercise the CLOSING→CLOSED correction.
    */
+  private void addReplica(ContainerID containerID, ContainerReplicaProto.State 
state) throws Exception {
+    addReplica(containerID, state, 0L);
+  }
+
+  private void addReplica(ContainerID containerID, ContainerReplicaProto.State 
state, long sequenceId)
+      throws Exception {
+    getContainerManager().updateContainerReplica(containerID, 
ContainerReplica.newBuilder()
+        .setContainerID(containerID)
+        .setContainerState(state)
+        .setDatanodeDetails(randomDatanodeDetails())
+        .setSequenceId(sequenceId)
+        .build());
+  }
+
   private void seedReconAsClosing(long startId, int count) throws Exception {
     seedRecon(startId, count, OPEN);
     ReconContainerManager cm = getContainerManager();
@@ -543,10 +560,11 @@ void doesNotDuplicateExistingQuasiClosedContainer() 
throws Exception {
 
     @Test
     void doesNotOverwriteContainerAlreadyClosedInRecon() throws Exception {
-      // Container already CLOSED in Recon but still in SCM's QUASI_CLOSED 
list.
-      // Pass 3 must not revert the container to QUASI_CLOSED (no downgrade).
+      // CLOSED in Recon from a CLOSED replica SCM has not processed yet, so 
SCM still lists it
+      // QUASI_CLOSED. The sync must not move it back.
       seedRecon(30, 1, CLOSED);
       ContainerID cid = ContainerID.valueOf(30L);
+      addReplica(cid, ContainerReplicaProto.State.CLOSED);
 
       when(mockScm.getContainerCount(QUASI_CLOSED)).thenReturn(1L);
       when(mockScm.getListOfContainerIDs(
@@ -557,6 +575,67 @@ void doesNotOverwriteContainerAlreadyClosedInRecon() 
throws Exception {
       assertEquals(CLOSED, getContainerManager().getContainer(cid).getState());
     }
 
+    @Test
+    void followsScmToQuasiClosedWhenClosedReplicaHasOlderSequence() throws 
Exception {
+      // Recon has the container CLOSED at sequence 100. It has one stale 
CLOSED replica at sequence
+      // 90 and one UNHEALTHY replica. SCM already moved the container to 
QUASI_CLOSED. The stale
+      // CLOSED replica must not block the correction; Recon should follow SCM 
to QUASI_CLOSED.
+      ContainerID cid = ContainerID.valueOf(31L);
+      ContainerInfo info = new ContainerInfo.Builder()
+          .setContainerID(31L)
+          .setState(CLOSED)
+          .setSequenceId(100L)
+          .setReplicationConfig(StandaloneReplicationConfig.getInstance(ONE))
+          .setOwner("test")
+          .build();
+      getContainerManager().addNewContainer(new ContainerWithPipeline(info, 
null));
+      addReplica(cid, ContainerReplicaProto.State.CLOSED, 90L);
+      addReplica(cid, ContainerReplicaProto.State.UNHEALTHY, 90L);
+
+      when(mockScm.getContainerCount(QUASI_CLOSED)).thenReturn(1L);
+      when(mockScm.getListOfContainerIDs(
+          eq(ContainerID.valueOf(1L)), eq(1), eq(QUASI_CLOSED)))
+          .thenReturn(Collections.singletonList(cid));
+
+      assertTrue(syncHelper.syncWithSCMContainerInfo());
+      
assertThat(getContainerManager().getContainer(cid).getState()).isEqualTo(QUASI_CLOSED);
+      assertThat(getContainerManager().getContainerReplicas(cid)).hasSize(2);
+    }
+
+    @Test
+    void followsScmBackToQuasiClosedWhenReconHasNoClosedReplica() throws 
Exception {
+      // SCM moved the CLOSED container through DELETING and back to 
QUASI_CLOSED after a datanode
+      // reported a non-empty UNHEALTHY replica. Recon still has CLOSED and no 
CLOSED replica.
+      seedRecon(32, 1, CLOSED);
+      ContainerID cid = ContainerID.valueOf(32L);
+      addReplica(cid, ContainerReplicaProto.State.UNHEALTHY);
+
+      when(mockScm.getContainerCount(QUASI_CLOSED)).thenReturn(1L);
+      when(mockScm.getListOfContainerIDs(
+          eq(ContainerID.valueOf(1L)), eq(1), eq(QUASI_CLOSED)))
+          .thenReturn(Collections.singletonList(cid));
+
+      assertTrue(syncHelper.syncWithSCMContainerInfo());
+      
assertThat(getContainerManager().getContainer(cid).getState()).isEqualTo(QUASI_CLOSED);
+      assertThat(getContainerManager().getContainerReplicas(cid)).hasSize(1);
+    }
+
+    @Test
+    void finishesQuasiClosedMoveStoppedInDeleting() throws Exception {
+      // The CLOSED to QUASI_CLOSED move stopped after DELETE. SCM still lists 
the container
+      // QUASI_CLOSED, so the next sync must finish the move.
+      seedRecon(33, 1, DELETING);
+      ContainerID cid = ContainerID.valueOf(33L);
+
+      when(mockScm.getContainerCount(QUASI_CLOSED)).thenReturn(1L);
+      when(mockScm.getListOfContainerIDs(
+          eq(ContainerID.valueOf(1L)), eq(1), eq(QUASI_CLOSED)))
+          .thenReturn(Collections.singletonList(cid));
+
+      assertTrue(syncHelper.syncWithSCMContainerInfo());
+      assertEquals(QUASI_CLOSED, 
getContainerManager().getContainer(cid).getState());
+    }
+
     @Test
     void pass3CorrectOpenToQuasiClosed() throws Exception {
       // Container is OPEN in Recon but SCM has already moved it to 
QUASI_CLOSED.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to