This is an automated email from the ASF dual-hosted git repository.
ArafatKhan2198 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 1eff2d9438b HDDS-17061. Recon drops the replicas of a DELETED
container when it moves it back to SCM's live state. (#12096)
1eff2d9438b is described below
commit 1eff2d9438b717555c493c1e8c1f75f0f0d5981f
Author: Arafat2198 <[email protected]>
AuthorDate: Fri Nov 27 14:33:17 2026 +0530
HDDS-17061. Recon drops the replicas of a DELETED container when it moves
it back to SCM's live state. (#12096)
Co-authored-by: Siyao Meng <[email protected]>
---
.../recon/scm/ReconStorageContainerSyncHelper.java | 21 ++++----
.../scm/TestReconSCMContainerSyncIntegration.java | 59 ++++++++++++++++++++--
2 files changed, 66 insertions(+), 14 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 5187df5cafb..b727df1f595 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
@@ -64,7 +64,7 @@
* <li><b>QUASI_CLOSED and CLOSED:</b> paginate SCM state lists; add absent
* containers and advance existing Recon containers through valid local
* state-machine transitions. If Recon has DELETED but SCM reports one of
- * these states, Recon rebuilds the container record from SCM
metadata.</li>
+ * these states, Recon moves its record back to that state.</li>
* <li><b>DELETED:</b> paginates SCM's DELETED ID list. For IDs already in
* Recon, Recon drives the container to DELETED in a single call. Full
* {@code ContainerInfo} is fetched only for IDs missing from Recon. The
@@ -287,7 +287,7 @@ private int reconcileToQuasiClosed(ContainerID containerID,
HddsProtos.LifeCycleState reconState) {
try {
if (reconState == HddsProtos.LifeCycleState.DELETED) {
- return rebuildContainerFromScm(containerID,
+ return moveDeletedBackToScmState(containerID,
HddsProtos.LifeCycleState.QUASI_CLOSED);
}
if (reconState == HddsProtos.LifeCycleState.OPEN) {
@@ -341,7 +341,7 @@ private int reconcileToClosed(ContainerID containerID,
HddsProtos.LifeCycleState reconState) {
try {
if (reconState == HddsProtos.LifeCycleState.DELETED) {
- return rebuildContainerFromScm(containerID,
HddsProtos.LifeCycleState.CLOSED);
+ return moveDeletedBackToScmState(containerID,
HddsProtos.LifeCycleState.CLOSED);
}
if (reconState == HddsProtos.LifeCycleState.OPEN) {
containerManager.transitionOpenToClosing(containerID, reconContainer);
@@ -367,23 +367,24 @@ private int reconcileToClosed(ContainerID containerID,
return 0;
}
- private int rebuildContainerFromScm(ContainerID containerID,
- HddsProtos.LifeCycleState scmState) {
+ private int moveDeletedBackToScmState(ContainerID containerID,
+ HddsProtos.LifeCycleState scmState) {
try {
List<ContainerInfo> infos = scmServiceProvider.getListOfContainerInfos(
containerID, 1, scmState);
if (infos.isEmpty() || !infos.get(0).containerID().equals(containerID)) {
- LOG.debug("Container {} no longer in SCM state {}; skipping rebuild.",
+ LOG.debug("Container {} no longer in SCM state {}; skipping move
back.",
containerID, scmState);
return 0;
}
- containerManager.deleteContainer(containerID);
- containerManager.addNewContainer(new ContainerWithPipeline(infos.get(0),
null));
- LOG.info("Rebuilt container {} in Recon from DELETED to SCM state {}.",
+ // Move the existing record back in place, as SCM's report handler does,
so the replicas Recon
+ // already knows are kept. If the update fails the container stays in
the map and the next sync retries.
+ containerManager.transitionDeletingOrDeletedToTargetState(containerID,
scmState);
+ LOG.info("Moved container {} in Recon from DELETED back to SCM state
{}.",
containerID, scmState);
return 1;
} catch (IOException e) {
- LOG.warn("Failed to rebuild container {} from SCM state {}.",
+ LOG.warn("Failed to move container {} from DELETED back to SCM state
{}.",
containerID, scmState, e);
return 0;
}
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 4fb96371ba8..7e350085b59 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
@@ -19,6 +19,7 @@
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.CLEANUP;
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;
@@ -37,6 +38,7 @@
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -68,6 +70,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
import org.junit.jupiter.params.provider.ValueSource;
/**
@@ -186,10 +189,6 @@ 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);
}
@@ -204,6 +203,10 @@ private void addReplica(ContainerID containerID,
ContainerReplicaProto.State sta
.build());
}
+ /**
+ * 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 seedReconAsClosing(long startId, int count) throws Exception {
seedRecon(startId, count, OPEN);
ReconContainerManager cm = getContainerManager();
@@ -212,6 +215,26 @@ private void seedReconAsClosing(long startId, int count)
throws Exception {
}
}
+ /** Seeds a container Recon retired to DELETED while a datanode still
reported a replica of it. */
+ private ContainerID seedDeletedWithReplica(long id) throws Exception {
+ seedRecon(id, 1, CLOSED);
+ ContainerID containerID = ContainerID.valueOf(id);
+ addReplica(containerID, ContainerReplicaProto.State.CLOSED);
+ ReconContainerManager containerManager = getContainerManager();
+ containerManager.updateContainerState(containerID, DELETE);
+ containerManager.updateContainerState(containerID, CLEANUP);
+ return containerID;
+ }
+
+ /** Stubs SCM's list for {@code state} to contain exactly the given
container. */
+ private void stubInScm(ContainerID containerID, LifeCycleState state) throws
IOException {
+ when(mockScm.getContainerCount(state)).thenReturn(1L);
+ when(mockScm.getListOfContainerIDs(eq(ContainerID.valueOf(1L)), eq(1),
eq(state)))
+ .thenReturn(Collections.singletonList(containerID));
+ when(mockScm.getListOfContainerInfos(eq(containerID), eq(1), eq(state)))
+
.thenReturn(Collections.singletonList(containerInfo(containerID.getId(),
state)));
+ }
+
/** Returns a list of ContainerIDs for IDs in [{@code start}, {@code end}).
*/
private List<ContainerID> idRange(long start, long end) {
return LongStream.range(start, end)
@@ -314,6 +337,34 @@ void pass1CorrectQuasiClosedToClosedViaForceClose() throws
Exception {
assertEquals(CLOSED, getContainerManager().getContainer(cid).getState());
}
+ @ParameterizedTest
+ @EnumSource(value = LifeCycleState.class, names = {"CLOSED",
"QUASI_CLOSED"})
+ void containerDeletedInReconButLiveInScmKeepsReplicas(LifeCycleState
scmState) throws Exception {
+ // SCM moved the container back from DELETED to CLOSED or QUASI_CLOSED.
Recon must follow
+ // without losing the replica it already knows. Both states take the
same move-back path.
+ ContainerID cid = seedDeletedWithReplica(40L);
+ stubInScm(cid, scmState);
+
+ assertTrue(syncHelper.syncWithSCMContainerInfo());
+
assertThat(getContainerManager().getContainer(cid).getState()).isEqualTo(scmState);
+ assertThat(getContainerManager().getContainerReplicas(cid)).hasSize(1);
+ }
+
+ @Test
+ void failedCorrectionFromDeletedKeepsContainerInRecon() throws Exception {
+ ContainerID cid = seedDeletedWithReplica(41L);
+ stubInScm(cid, CLOSED);
+ ReconContainerManager failingManager = spy(getContainerManager());
+ doThrow(new IOException("injected")).when(failingManager)
+ .transitionDeletingOrDeletedToTargetState(any(), any());
+
+ assertTrue(new ReconStorageContainerSyncHelper(mockScm, getConf(),
failingManager, metrics)
+ .syncWithSCMContainerInfo());
+ assertThat(getContainerManager().containerExist(cid)).isTrue();
+
assertThat(getContainerManager().getContainer(cid).getState()).isEqualTo(DELETED);
+ assertThat(getContainerManager().getContainerReplicas(cid)).hasSize(1);
+ }
+
@Test
void emptyListFromSCMBeforeTotalExhaustedReturnsFalse() throws Exception {
// SCM says there are 2 containers but returns empty list — indicates a
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]