133tosakarin commented on code in PR #1168:
URL: https://github.com/apache/ratis/pull/1168#discussion_r1805797639
##########
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 still
presents the deadlock issue where thread A holds the lock while waiting for the
future, and thread B needs to acquire the lock.
If we simply ignore the future and throw an exception without handling it,
then no deadlock will occur.
--
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]