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

ashishkr 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 9afaeacf71 HDDS-10546. OM startup failure as leader is not getting 
ready (#6395)
9afaeacf71 is described below

commit 9afaeacf715e432d1fce97962cd88402552b6af4
Author: Sumit Agrawal <[email protected]>
AuthorDate: Tue Mar 19 12:35:11 2024 +0530

    HDDS-10546. OM startup failure as leader is not getting ready (#6395)
---
 .../hadoop/ozone/om/ratis/OzoneManagerStateMachine.java  | 16 +++++++++++++++-
 .../ozone/om/ratis/TestOzoneManagerStateMachine.java     |  7 +++----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
index ff8e09435a..54f65ff887 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ratis/OzoneManagerStateMachine.java
@@ -161,12 +161,18 @@ public class OzoneManagerStateMachine extends 
BaseStateMachine {
   /** Notified by Ratis for non-StateMachine term-index update. */
   @Override
   public synchronized void notifyTermIndexUpdated(long currentTerm, long 
newIndex) {
+    // lastSkippedIndex is start of sequence (one less) of continuous 
notification from ratis
+    // if there is any applyTransaction (double buffer index), then this gap 
is handled during double buffer
+    // notification and lastSkippedIndex will be the start of last continuous 
sequence.
     final long oldIndex = lastNotifiedTermIndex.getIndex();
     if (newIndex - oldIndex > 1) {
       lastSkippedIndex = newIndex - 1;
     }
     final TermIndex newTermIndex = TermIndex.valueOf(currentTerm, newIndex);
     lastNotifiedTermIndex = assertUpdateIncreasingly("lastNotified", 
lastNotifiedTermIndex, newTermIndex);
+    if (lastNotifiedTermIndex.getIndex() - 
getLastAppliedTermIndex().getIndex() == 1) {
+      updateLastAppliedTermIndex(lastNotifiedTermIndex);
+    }
   }
 
   public TermIndex getLastNotifiedTermIndex() {
@@ -175,7 +181,15 @@ public class OzoneManagerStateMachine extends 
BaseStateMachine {
 
   @Override
   protected synchronized boolean updateLastAppliedTermIndex(TermIndex 
newTermIndex) {
-    assertUpdateIncreasingly("lastApplied", getLastAppliedTermIndex(), 
newTermIndex);
+    TermIndex lastApplied = getLastAppliedTermIndex();
+    assertUpdateIncreasingly("lastApplied", lastApplied, newTermIndex);
+    // if newTermIndex getting updated is within sequence of notifiedTermIndex 
(i.e. from lastSkippedIndex and
+    // notifiedTermIndex), then can update directly to lastNotifiedTermIndex 
as it ensure previous double buffer's
+    // Index is notified or getting notified matching lastSkippedIndex
+    if (newTermIndex.getIndex() < getLastNotifiedTermIndex().getIndex()
+        && lastApplied.getIndex() >= lastSkippedIndex) {
+      newTermIndex = getLastNotifiedTermIndex();
+    }
     return super.updateLastAppliedTermIndex(newTermIndex);
   }
 
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 93997826bf..3cd7b10910 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
@@ -37,7 +37,6 @@ import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.ratis.proto.RaftProtos;
 import org.apache.ratis.protocol.exceptions.StateMachineException;
 import org.apache.ratis.server.protocol.TermIndex;
-import org.apache.ratis.server.raftlog.RaftLog;
 import org.apache.ratis.statemachine.TransactionContext;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -101,12 +100,12 @@ public class TestOzoneManagerStateMachine {
   @Test
   public void testLastAppliedIndex() {
     ozoneManagerStateMachine.notifyTermIndexUpdated(0, 0);
-    assertTermIndex(0, RaftLog.INVALID_LOG_INDEX, 
ozoneManagerStateMachine.getLastAppliedTermIndex());
+    assertTermIndex(0, 0, ozoneManagerStateMachine.getLastAppliedTermIndex());
     assertTermIndex(0, 0, ozoneManagerStateMachine.getLastNotifiedTermIndex());
 
     // Conf/metadata transaction.
     ozoneManagerStateMachine.notifyTermIndexUpdated(0, 1);
-    assertTermIndex(0, RaftLog.INVALID_LOG_INDEX, 
ozoneManagerStateMachine.getLastAppliedTermIndex());
+    assertTermIndex(0, 1, ozoneManagerStateMachine.getLastAppliedTermIndex());
     assertTermIndex(0, 1, ozoneManagerStateMachine.getLastNotifiedTermIndex());
 
     // call update last applied index
@@ -119,7 +118,7 @@ public class TestOzoneManagerStateMachine {
     // Conf/metadata transaction.
     ozoneManagerStateMachine.notifyTermIndexUpdated(1L, 4L);
 
-    assertTermIndex(0, 3, ozoneManagerStateMachine.getLastAppliedTermIndex());
+    assertTermIndex(1, 4, ozoneManagerStateMachine.getLastAppliedTermIndex());
     assertTermIndex(1, 4, ozoneManagerStateMachine.getLastNotifiedTermIndex());
 
     // Add some apply transactions.


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

Reply via email to