Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: OneSizeFitQuorum <[email protected]>
  • Loading branch information
OneSizeFitsQuorum committed Aug 29, 2024
1 parent 520ecab commit 8ea1833
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -229,6 +230,7 @@ public long[] getFollowerNextIndices() {
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
Expand Down Expand Up @@ -463,6 +465,13 @@ void groupRemove(boolean deleteDirectory, boolean renameDirectory) {
/* 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 ++) {
Expand Down Expand Up @@ -541,6 +550,7 @@ public void close() {
} catch (Exception e) {
LOG.warn(getMemberId() + ": Failed to shutdown serverExecutor", e);
}
closeFinishedLatch.countDown();
});
}

Expand Down

0 comments on commit 8ea1833

Please sign in to comment.