loserwang1024 commented on code in PR #3649:
URL: https://github.com/apache/fluss/pull/3649#discussion_r3601664673
##########
fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorLeaderElection.java:
##########
@@ -186,18 +140,138 @@ public void notLeader() {
public void close() {
LOG.info("Closing LeaderLatch for server {}.", serverId);
- if (leaderLatch != null) {
+ if (closing.compareAndSet(false, true)) {
try {
leaderLatch.close();
} catch (Exception e) {
LOG.error("Failed to close LeaderLatch for server {}.",
serverId, e);
}
+
+ // Events submitted after closing starts are ignored by their
executor-side check.
+ // Since the executor is single-threaded, this task runs after all
leadership work
+ // already queued before close and completes only after leader
cleanup has finished.
+ leaderCallbackExecutor.execute(
+ () -> {
+ try {
+ boolean cleanupRequired = state == State.LEADER;
+ state = State.CLOSED;
+ if (cleanupRequired) {
+ cleanupLeaderServices(null);
+ }
+ } finally {
+ closeFuture.complete(null);
+ }
+ });
}
- leaderCallbackExecutor.shutdownNow();
+ closeFuture.join();
Review Comment:
done
--
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]