amaliujia commented on code in PR #1676:
URL: https://github.com/apache/ratis/pull/1676#discussion_r4452912120
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/ReadRequestHandler.java:
##########
@@ -81,6 +81,12 @@ RaftGroupMemberId getMemberId() {
}
CompletableFuture<RaftClientReply> staleReadAsync(RaftClientRequest request)
{
+ final long installSnapshot =
server.getSnapshotInstallationHandler().getInProgressInstallSnapshotIndex();
Review Comment:
Unfortunately this index only covers one path of the snapshot installing, so
this check is not complete:
https://github.com/apache/ratis/blob/master/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java#L135-L146
Basically there are two snapshot install path. One is chunk based which
leader sends over the snapshot data in bytes. Another is notification based in
which leaders only notify to install snapshot while the snapshot data is
transferred by applications.
I am thinking the state machine lifecycle would be a better signal. Snapshot
install would pause the StateMachine before install, so it seems to be fine
that we reject read here when SM is paused. Just one thing to notice that a
paused server could also pause SM, so we need to exclude that scenario:
Something like this:
```
/**
* @return the exception to reject a read with, or null if the state machine
can serve it.
*/
private RaftException getReadExceptionIfStateMachineNotReady(String op) {
// Read the state machine state before the server state:
// a server pause/resume sets the server state first and restores it last.
final LifeCycle.State smState = stateMachine.getLifeCycleState();
if (!smState.isPausingOrPaused()) {
return null;
}
final LifeCycle.State serverState = server.getInfo().getLifeCycleState();
if (!serverState.isRunning()) {
return new ServerNotReadyException(getMemberId() + ": Failed to " + op
+ " since the server is " + serverState);
}
return new ReadException(getMemberId() + ": Failed to " + op
+ " since the state machine is " + smState + " for snapshot
installation");
}
CompletableFuture<RaftClientReply> staleReadAsync(RaftClientRequest request)
{
final RaftException e = getReadExceptionIfStateMachineNotReady("stale
read");
if (e != null) {
return
CompletableFuture.completedFuture(server.newExceptionReply(request, e));
}
final long minIndex = request.getType().getStaleRead().getMinIndex();
// ... unchanged ...
}
```
--
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]