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 0fab043a1ff HDDS-17042. Recon manual task rebuild requested while a 
delta sync is being applied makes the tasks apply that delta twice. (#12001)
0fab043a1ff is described below

commit 0fab043a1ff54d64ab6622272e8859fd20688a77
Author: Arafat2198 <[email protected]>
AuthorDate: Wed Nov 18 11:28:22 2026 +0530

    HDDS-17042. Recon manual task rebuild requested while a delta sync is being 
applied makes the tasks apply that delta twice. (#12001)
    
    Co-authored-by: Claude <[email protected]>
    Co-authored-by: Doroszlai, Attila <[email protected]>
---
 .../spi/impl/OzoneManagerServiceProviderImpl.java  | 24 +++++++++++--
 .../impl/TestOzoneManagerServiceProviderImpl.java  | 39 ++++++++++++++++++++++
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java
index be1acec94fe..a94e0d603bd 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/OzoneManagerServiceProviderImpl.java
@@ -59,6 +59,7 @@
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -128,6 +129,9 @@ public class OzoneManagerServiceProviderImpl
   private final long omDBLagThreshold;
 
   private AtomicBoolean isSyncDataFromOMRunning;
+  // Held by the sync thread from applying a delta batch to the Recon OM DB 
until the batch is handed to the tasks,
+  // so that a manual rebuild cannot checkpoint the DB with the batch in it 
and then have the batch applied again.
+  private final ReentrantLock deltaApplyLock = new ReentrantLock();
   private final String threadNamePrefix;
   private ThreadFactory threadFactory;
   private ReconContext reconContext;
@@ -595,8 +599,14 @@ public OMDBReprocessResponse triggerTaskRebuild() {
               + "present in the Recon OM DB directory and has been loaded, 
then retry.");
     }
 
-    ReconTaskController.ReInitializationResult result = 
reconTaskController.queueReInitializationEvent(
-        
ReconTaskReInitializationEvent.ReInitializationReason.MANUAL_OM_DB_REBUILD);
+    ReconTaskController.ReInitializationResult result;
+    deltaApplyLock.lock();
+    try {
+      result = reconTaskController.queueReInitializationEvent(
+          
ReconTaskReInitializationEvent.ReInitializationReason.MANUAL_OM_DB_REBUILD);
+    } finally {
+      deltaApplyLock.unlock();
+    }
 
     if (result == ReconTaskController.ReInitializationResult.SUCCESS) {
       return new OMDBReprocessResponse(OMDBReprocessResponse.Status.ACCEPTED,
@@ -611,6 +621,8 @@ public OMDBReprocessResponse triggerTaskRebuild() {
   /**
    * Get Delta updates from OM through RPC call and apply to local OM DB as
    * well as accumulate in a buffer.
+   * When OM returns updates, this returns (or throws) holding {@code 
deltaApplyLock};
+   * the caller must release it after handing the updates to the tasks.
    *
    * @param fromSequenceNumber from sequence number to request from.
    * @param omdbUpdatesHandler OM DB updates handler to buffer updates.
@@ -640,6 +652,8 @@ Long getAndApplyDeltaUpdatesFromOM(
   /**
    * Get Delta updates from OM through RPC call and apply to local OM DB as
    * well as accumulate in a buffer.
+   * When OM returns updates, this takes {@code deltaApplyLock} before 
applying them and returns (or throws)
+   * still holding it; the caller must release it after handing the updates to 
the tasks.
    *
    * @param fromSequenceNumber from sequence number to request from.
    * @param omdbUpdatesHandler OM DB updates handler to buffer updates.
@@ -687,6 +701,8 @@ ImmutablePair<Boolean, Long> 
innerGetAndApplyDeltaUpdatesFromOM(long fromSequenc
       // Track delta apply (conversion + DB apply combined)
       long deltaApplyStartTime = Time.monotonicNow();
 
+      // Released by syncDataFromOM once the events are handed to the tasks.
+      deltaApplyLock.lock();
       try {
         for (byte[] data : dbUpdates.getData()) {
           try (ManagedWriteBatch writeBatch = new ManagedWriteBatch(data)) {
@@ -862,6 +878,10 @@ public boolean syncDataFromOM() {
               LOG.warn("Unable to get and apply delta updates from OM: {}, 
falling back to full snapshot",
                   e.getMessage());
               fullSnapshot = true;
+            } finally {
+              if (deltaApplyLock.isHeldByCurrentThread()) {
+                deltaApplyLock.unlock();
+              }
             }
             if (fullSnapshot) {
               break;
diff --git 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java
 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java
index 5c615ab932d..3a447e25afe 100644
--- 
a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java
+++ 
b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/spi/impl/TestOzoneManagerServiceProviderImpl.java
@@ -38,6 +38,7 @@
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -62,12 +63,14 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.io.FileUtils;
@@ -980,6 +983,42 @@ configuration, mock(ReconOMMetadataManager.class), 
noDbController,
     verify(noDbController, never()).queueReInitializationEvent(any());
   }
 
+  @Test
+  public void testTriggerTaskRebuildWaitsForDeltaHandOff(
+      @TempDir File dirOmMetadata, @TempDir File dirReconMetadata) throws 
Exception {
+    ReconOMMetadataManager omMetadataManager = 
stopAfterTest(getTestReconOmMetadataManager(
+        initializeNewOmMetadataManager(dirOmMetadata), dirReconMetadata));
+    DBUpdates dbUpdates = new DBUpdates();
+    dbUpdates.setCurrentSequenceNumber(0);
+    ReconTaskController reconTaskControllerMock = getMockTaskController();
+    OzoneManagerServiceProviderImpl serviceProvider = new 
OzoneManagerServiceProviderImpl(configuration,
+        omMetadataManager, reconTaskControllerMock, new ReconUtils(), 
getMockOzoneManagerClient(dbUpdates),
+        reconContext, getMockTaskStatusUpdaterManager());
+
+    AtomicBoolean handingOff = new AtomicBoolean();
+    AtomicBoolean queuedDuringHandOff = new AtomicBoolean();
+    
when(reconTaskControllerMock.queueReInitializationEvent(any())).thenAnswer(invocation
 -> {
+      queuedDuringHandOff.compareAndSet(false, handingOff.get());
+      return ReconTaskController.ReInitializationResult.SUCCESS;
+    });
+    // Request a rebuild from another thread after the sync has applied a 
delta batch and before it hands it over.
+    CompletableFuture<OMDBReprocessResponse> rebuild = new 
CompletableFuture<>();
+    doAnswer(invocation -> {
+      handingOff.set(true);
+      Thread rebuildThread = new Thread(() -> 
rebuild.complete(serviceProvider.triggerTaskRebuild()));
+      rebuildThread.start();
+      GenericTestUtils.waitFor(() -> rebuild.isDone() || 
rebuildThread.getState() == Thread.State.WAITING, 10, 10000);
+      handingOff.set(false);
+      return null;
+    
}).when(reconTaskControllerMock).updateOMMetadataManager(any(ReconOMMetadataManager.class));
+
+    assertTrue(serviceProvider.syncDataFromOM());
+    assertThat(rebuild.get(10, 
TimeUnit.SECONDS).getStatus()).isEqualTo(OMDBReprocessResponse.Status.ACCEPTED);
+    assertThat(queuedDuringHandOff).isFalse();
+    verify(reconTaskControllerMock, times(1)).queueReInitializationEvent(
+        
ReconTaskReInitializationEvent.ReInitializationReason.MANUAL_OM_DB_REBUILD);
+  }
+
   @Test
   public void testStartupReconciliationReprocessesTaskOnLineageRegression() {
     ReconTaskController reconTaskController = mock(ReconTaskController.class);


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

Reply via email to