szetszwo commented on code in PR #1168:
URL: https://github.com/apache/ratis/pull/1168#discussion_r1805936472
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java:
##########
@@ -613,24 +606,33 @@ private synchronized CompletableFuture<Void>
changeToFollowerAsync(
return future;
}
- synchronized void changeToFollowerAndPersistMetadata(
+ synchronized CompletableFuture<Void> changeToFollowerAndPersistMetadata(
long newTerm,
boolean allowListener,
Object reason) throws IOException {
- if (changeToFollower(newTerm, false, allowListener, reason)) {
- state.persistMetadata();
+ final AtomicBoolean metadataUpdated = new AtomicBoolean();
+ final CompletableFuture<Void> future = changeToFollower(newTerm, false,
allowListener, reason, metadataUpdated);
+ try {
+ if (metadataUpdated.get()) {
+ state.persistMetadata();
+ }
+ } catch (IOException e) {
+ CompletableFuture.runAsync(future::join);
Review Comment:
> Replacing CompleteFuture.runAsync(future::join) with future.join ...
I mean "remove the line", not "replace it with future.join", i.e. case 3
below.
Three cases:
1. With `future.join()`, the current thread will wait for the shutdown
thread to complete
2. With `CompleteFuture.runAsync(future::join)`, the current thread and the
shutdown thread will run in parallel. In addition, it uses one more thread to
wait for the shutdown thread.
3. With an empty line, the current thread and the shutdown thread will run
in parallel.
--
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]