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 22e8e2c7813 HDDS-11470. Report OM snapshot installation failures to 
Ratis (#11086)
22e8e2c7813 is described below

commit 22e8e2c7813946d6bb97865fb2a64ade38075736
Author: Andy Huang <[email protected]>
AuthorDate: Sat Nov 7 23:01:03 2026 +0800

    HDDS-11470. Report OM snapshot installation failures to Ratis (#11086)
---
 .../hadoop/ozone/om/TestOMRatisSnapshots.java      | 17 ++++++---
 .../org/apache/hadoop/ozone/om/OzoneManager.java   | 18 +++++-----
 .../om/ratis/TestOzoneManagerStateMachine.java     | 41 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 14 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
index fbddb8101fd..c58af77127b 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMRatisSnapshots.java
@@ -29,6 +29,7 @@
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
@@ -42,6 +43,7 @@
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -630,9 +632,10 @@ public void testInstallSnapshotFailedBackupRestoresDbDir() 
throws Exception {
         "Simulated backup move failure for test"));
     followerOM.setExitManagerForTesting(new DummyExitManager());
     try {
-      TermIndex termIndex = followerOM.installCheckpoint(
-          leaderOMNodeId, leaderCheckpointLocation, leaderCheckpointTrxnInfo);
-      assertNull(termIndex, "Install should have been reported as failed");
+      IOException exception = assertThrows(IOException.class, () ->
+          followerOM.installCheckpoint(leaderOMNodeId, 
leaderCheckpointLocation,
+              leaderCheckpointTrxnInfo));
+      assertThat(exception).hasMessageContaining("Cannot replace DB");
 
       // Everything present before the aborted install must still be present.
       assertThat(topLevelNames(followerMetaDir)).containsAll(namesBefore);
@@ -693,7 +696,9 @@ public void 
testFailedInstallExitsAfterApplyRejectedDuringPause() throws Excepti
       GenericTestUtils.waitFor(
           () -> 
followerOM.getOmRatisServer().getLastAppliedTermIndex().getIndex() >= 
leaderIndex, 100, 30_000);
       followerOM.setCheckpointBackupInjector(new 
ThrowOnNthPauseFaultInjector(1, "Simulated backup move failure"));
-      assertNull(followerOM.installCheckpoint(leaderOMNodeId, 
leaderCheckpointLocation, aheadTrxnInfo));
+      IOException exception = assertThrows(IOException.class,
+          () -> followerOM.installCheckpoint(leaderOMNodeId, 
leaderCheckpointLocation, aheadTrxnInfo));
+      assertThat(exception).hasMessageContaining("Cannot replace DB");
       assertThat(exitManager.messages).isEmpty();
 
       followerOM.setCheckpointBackupInjector(injector);
@@ -710,7 +715,9 @@ public void 
testFailedInstallExitsAfterApplyRejectedDuringPause() throws Excepti
       GenericTestUtils.waitFor(() -> 
Arrays.stream(updaterLog.getOutput().split("\n"))
           .anyMatch(line -> line.contains(follower) && line.contains(index)), 
100, 30_000);
       injector.resume();
-      assertNull(install.get(60, TimeUnit.SECONDS));
+      ExecutionException installException = 
assertThrows(ExecutionException.class,
+          () -> install.get(60, TimeUnit.SECONDS));
+      
assertThat(installException.getCause()).isInstanceOf(IOException.class).hasMessageContaining("Cannot
 replace DB");
 
       assertThat(exitManager.messages)
           .as("follower resumed applies on its old DB after the entry at index 
%d was skipped", keyIndex)
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
index c207586f8ff..217bb934a9a 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java
@@ -4717,6 +4717,7 @@ public synchronized TermIndex 
installSnapshotFromLeader(String leaderId) throws
       termIndex = installCheckpoint(leaderId, checkpointLocation);
     } catch (Exception ex) {
       LOG.error("Failed to install snapshot from Leader OM.", ex);
+      throw new IOException("Failed to install snapshot from Leader " + 
leaderId, ex);
     } finally {
       cleanupCheckpoint(omDBCheckpoint);
     }
@@ -4773,6 +4774,7 @@ TermIndex installCheckpoint(String leaderId, Path 
checkpointLocation,
     long startTime = Time.monotonicNow();
     File oldDBLocation = metadataManager.getStore().getDbLocation();
     Path omDbPath = Paths.get(checkpointLocation.toString(), OM_DB_NAME);
+    IOException installFailure = null;
     try {
       // Stop Background services
       keyManager.stop();
@@ -4782,20 +4784,16 @@ TermIndex installCheckpoint(String leaderId, Path 
checkpointLocation,
       // Pause the State Machine. It flushes the transactions already applied 
and rejects new ones until unpause.
       omRatisServer.getOmStateMachine().pause();
     } catch (Exception e) {
-      LOG.error("Failed to stop/ pause the services. Cannot proceed with " +
-          "installing the new checkpoint.");
       // Stop the checkpoint install process and restart the services.
       keyManager.start(configuration);
       startSecretManagerIfNecessary();
       startTrashEmptier(configuration);
-      throw e;
+      throw new IOException("Failed to install checkpoint " + 
checkpointTrxnInfo + ": Cannot stop/pause services.", e);
     }
-
     File dbBackup = null;
     TermIndex termIndex = omRatisServer.getLastAppliedTermIndex();
     long term = termIndex.getTerm();
     long lastAppliedIndex = termIndex.getIndex();
-
     // Check if current applied log index is smaller than the downloaded
     // checkpoint transaction index. If yes, proceed by stopping the ratis
     // server so that the OM state can be re-initialized. If no then do not
@@ -4837,6 +4835,8 @@ TermIndex installCheckpoint(String leaderId, Path 
checkpointLocation,
         LOG.error("Failed to install Snapshot from {} as OM failed to replace" 
+
             " DB with downloaded checkpoint. Reloading old OM state.",
             leaderId, e);
+        installFailure = new IOException("Failed to install checkpoint " + 
checkpointTrxnInfo
+            + ": Cannot replace DB.", e);
       }
     } else {
       LOG.warn("Cannot proceed with InstallSnapshot as OM is at TermIndex {} " 
+
@@ -4904,13 +4904,13 @@ TermIndex installCheckpoint(String leaderId, Path 
checkpointLocation,
       LOG.error("Failed to delete the backup of the original DB {}",
           dbBackup, e);
     }
-
+    if (installFailure != null) {
+      throw installFailure;
+    }
     if (lastAppliedIndex != checkpointTrxnInfo.getTransactionIndex()) {
-      // Install Snapshot failed and old state was reloaded. Return null to
-      // Ratis to indicate that installation failed.
+      // An older checkpoint was skipped. Return null to Ratis to indicate 
that no snapshot was installed.
       return null;
     }
-
     // TODO: We should only return the snpashotIndex to the leader.
     //  Should be fixed after RATIS-586
     TermIndex newTermIndex = TermIndex.valueOf(term, lastAppliedIndex);
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
index ed94136cf49..837b5c7d534 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/ratis/TestOzoneManagerStateMachine.java
@@ -1348,6 +1348,38 @@ public void testNotifyConfigurationChanged() {
 
   // --- notifySnapshotInstalled tests ---
 
+  @Test
+  public void testNotifyInstallSnapshotFromLeaderSuccess() throws Exception {
+    TermIndex termIndex = TermIndex.valueOf(1, 10);
+    when(om.installSnapshotFromLeader("leader-om")).thenReturn(termIndex);
+
+    CompletableFuture<TermIndex> future = sm.notifyInstallSnapshotFromLeader(
+        roleInfoWithLeader("leader-om"), TermIndex.valueOf(1, 11));
+
+    assertEquals(termIndex, future.get());
+  }
+
+  @Test
+  public void testNotifyInstallSnapshotFromLeaderNullResult() throws Exception 
{
+    CompletableFuture<TermIndex> future = sm.notifyInstallSnapshotFromLeader(
+        roleInfoWithLeader("leader-om"), TermIndex.valueOf(1, 11));
+
+    assertNull(future.get());
+  }
+
+  @Test
+  public void testNotifyInstallSnapshotFromLeaderFailure() throws Exception {
+    IOException failure = new IOException("Failed to install checkpoint");
+    doThrow(failure).when(om).installSnapshotFromLeader("leader-om");
+
+    CompletableFuture<TermIndex> future = sm.notifyInstallSnapshotFromLeader(
+        roleInfoWithLeader("leader-om"), TermIndex.valueOf(1, 11));
+
+    ExecutionException exception = assertThrows(ExecutionException.class, 
future::get);
+
+    assertSame(failure, exception.getCause());
+  }
+
   @Test
   public void testNotifySnapshotInstalledSuccess() {
     RaftPeer localPeer = RaftPeer.newBuilder()
@@ -1740,6 +1772,15 @@ private RaftClientRequest buildClientRequest(
         .build();
   }
 
+  private RaftProtos.RoleInfoProto roleInfoWithLeader(String leaderId) {
+    return RaftProtos.RoleInfoProto.newBuilder()
+        .setFollowerInfo(RaftProtos.FollowerInfoProto.newBuilder()
+            .setLeaderInfo(RaftProtos.ServerRpcProto.newBuilder()
+                .setId(RaftProtos.RaftPeerProto.newBuilder()
+                    .setId(ByteString.copyFromUtf8(leaderId)))))
+        .build();
+  }
+
   @Test
   public void testRatisEventsRecording() {
     OzoneConfiguration conf = new OzoneConfiguration();


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

Reply via email to