swamirishi commented on code in PR #1218:
URL: https://github.com/apache/ratis/pull/1218#discussion_r1951787602
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java:
##########
@@ -182,22 +180,28 @@ public String toString() {
@Override
public void run() {
+ CompletableFuture<Void> applyLogFutures =
CompletableFuture.completedFuture(null);
for(; state != State.STOP; ) {
try {
- waitForCommit();
+ waitForCommit(applyLogFutures);
if (state == State.RELOAD) {
reload();
}
- final MemoizedSupplier<List<CompletableFuture<Message>>> futures =
applyLog();
- checkAndTakeSnapshot(futures);
+ applyLogFutures = applyLog(applyLogFutures);
+ checkAndTakeSnapshot(applyLogFutures);
if (shouldStop()) {
- checkAndTakeSnapshot(futures);
+ applyLogFutures.get();
stop();
}
} catch (Throwable t) {
+ try {
+ applyLogFutures.get();
+ } catch (InterruptedException | ExecutionException e) {
+ LOG.info("{}: interrupted while waiting for apply transactions",
this, t);
+ }
Review Comment:
> @swamirishi , Why calling ` applyLogFutures.get()` when there is already
an exception/error? It could cause problems such as:
>
> 1. The future may never complete.
It is guaranteed it will always complete right?
> 2. The thread may already be interrupted.
> 3. In may throw another runtime exception/error (such as OOM)
It won't be thrown by the future right? If the future throws exception we
anyways handle it and mark the future as completed.
https://github.com/apache/ratis/blob/b635b137329f011e715c9083e93c7bb7f22b221f/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java#L271C11-L274C25
--
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]