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

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f5159db4 RATIS-2146. Fixed possible issues caused by concurrent 
deletion and election when member changes (#1140)
8f5159db4 is described below

commit 8f5159db4cade67b96c7b9c8589e7c0cdba571e0
Author: Potato <[email protected]>
AuthorDate: Tue Sep 3 11:42:14 2024 +0800

    RATIS-2146. Fixed possible issues caused by concurrent deletion and 
election when member changes (#1140)
---
 .../main/java/org/apache/ratis/server/impl/RaftServerImpl.java | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
index 7ec94076f..8833011f5 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ratis.server.impl;
 
+import java.util.concurrent.CountDownLatch;
 import org.apache.ratis.client.impl.ClientProtoUtils;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.metrics.Timekeeper;
@@ -229,6 +230,7 @@ class RaftServerImpl implements RaftServer.Division,
   private final RaftServerJmxAdapter jmxAdapter = new 
RaftServerJmxAdapter(this);
   private final LeaderElectionMetrics leaderElectionMetrics;
   private final RaftServerMetricsImpl raftServerMetrics;
+  private final CountDownLatch closeFinishedLatch = new CountDownLatch(1);
 
   // To avoid append entry before complete start() method
   // For example, if thread1 start(), but before thread1 startAsFollower(), 
thread2 receive append entry
@@ -463,6 +465,13 @@ class RaftServerImpl implements RaftServer.Division,
     /* Shutdown is triggered here inorder to avoid any locked files. */
     state.getStateMachineUpdater().setRemoving();
     close();
+    try {
+      closeFinishedLatch.await();
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      LOG.warn("{}: Waiting closing interrupted, will not continue to remove 
group locally", getMemberId());
+      return;
+    }
     getStateMachine().event().notifyGroupRemove();
     if (deleteDirectory) {
       for (int i = 0; i < FileUtils.NUM_ATTEMPTS; i ++) {
@@ -541,6 +550,7 @@ class RaftServerImpl implements RaftServer.Division,
       } catch (Exception e) {
         LOG.warn(getMemberId() + ": Failed to shutdown serverExecutor", e);
       }
+      closeFinishedLatch.countDown();
     });
   }
 

Reply via email to