szetszwo commented on code in PR #9671:
URL: https://github.com/apache/ozone/pull/9671#discussion_r2751673004


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java:
##########
@@ -285,6 +285,15 @@ public void notifyLeaderChanged(RaftGroupMemberId 
groupMemberId,
     currentLeaderTerm.set(scm.getScmHAManager().getRatisServer().getDivision()
         .getInfo().getCurrentTerm());
 
+    if (!refreshedAfterLeaderReady.get()) {
+      // refresh and validate safe mode rules if it can exit safe mode
+      // if being leader, all previous term transactions have been applied
+      // if other states, just refresh safe mode rules, and transaction keeps 
flushing from leader
+      // and does not depend on pending transactions.
+      refreshedAfterLeaderReady.set(true);

Review Comment:
   This is not atomic.  Use 
   ```java
       if (refreshedAfterLeaderReady.compareAndSet(false, true)) {
   ```



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SCMStateMachine.java:
##########
@@ -355,12 +364,9 @@ public void notifyTermIndexUpdated(long term, long index) {
     }
 
     if (currentLeaderTerm.get() == term) {
-      // Means all transactions before this term have been applied.
       // This means after a restart, all pending transactions have been 
applied.
-      // Perform
-      // 1. Refresh Safemode rules state.
-      // 2. Start DN Rpc server.
       if (!refreshedAfterLeaderReady.get()) {

Review Comment:
   Similarly, it needs  `compareAndSet`.
   
   BTW, why refreshedAfterLeaderReady won't be set to false after set to true?
   



##########
hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/safemode/TestSCMSafeModeManager.java:
##########
@@ -177,6 +181,16 @@ public void testSafeModeExitRule() throws Exception {
     }
     ContainerManager containerManager = mock(ContainerManager.class);
     
when(containerManager.getContainers(ReplicationType.RATIS)).thenReturn(containers);
+
+    StorageContainerManager mockScmManager = 
mock(StorageContainerManager.class);
+    SCMHAManager mockScmhaManager = mock(SCMHAManager.class);
+    when(mockScmManager.getScmHAManager()).thenReturn(mockScmhaManager);
+    SCMRatisServer mockScmRatisServer = mock(SCMRatisServer.class);
+    when(mockScmhaManager.getRatisServer()).thenReturn(mockScmRatisServer);
+    SCMStateMachine mockScmStateMachine = mock(SCMStateMachine.class);
+    
when(mockScmRatisServer.getSCMStateMachine()).thenReturn(mockScmStateMachine);
+    when((mockScmStateMachine.isRefreshedAfterLeaderReady())).thenReturn(true);
+    scmContext = new SCMContext.Builder().setSCM(mockScmManager).build();

Review Comment:
   Please don't use mock.  We need to a real cluster test which test SCM 
changing leader multiple times.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to