[
https://issues.apache.org/jira/browse/RATIS-1838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17716768#comment-17716768
]
Tsz-wo Sze commented on RATIS-1838:
-----------------------------------
BTW, we should synchronize the server instead of the handler.
{code}
+++
b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java
@@ -157,7 +157,7 @@ class SnapshotInstallationHandler {
final InstallSnapshotRequestProto.SnapshotChunkProto snapshotChunkRequest
= request.getSnapshotChunk();
final TermIndex lastIncluded =
TermIndex.valueOf(snapshotChunkRequest.getTermIndex());
final long lastIncludedIndex = lastIncluded.getIndex();
- synchronized (this) {
+ synchronized (server) {
final boolean recognized = state.recognizeLeader(leaderId, leaderTerm);
currentTerm = state.getCurrentTerm();
if (!recognized) {
@@ -204,7 +204,7 @@ class SnapshotInstallationHandler {
final TermIndex firstAvailableLogTermIndex = TermIndex.valueOf(
request.getNotification().getFirstAvailableTermIndex());
final long firstAvailableLogIndex = firstAvailableLogTermIndex.getIndex();
- synchronized (this) {
+ synchronized (server) {
final boolean recognized = state.recognizeLeader(leaderId, leaderTerm);
currentTerm = state.getCurrentTerm();
if (!recognized) {
{code}
> java.lang.IllegalStateException thrown when nextIndex in follower is
> inconsistent with leader's snapshot
> --------------------------------------------------------------------------------------------------------
>
> Key: RATIS-1838
> URL: https://issues.apache.org/jira/browse/RATIS-1838
> Project: Ratis
> Issue Type: Bug
> Components: snapshot
> Affects Versions: 2.5.0
> Reporter: Song Ziyang
> Priority: Major
> Attachments: image-2023-04-25-22-10-01-209.png
>
>
> h3. 1. Error Stack
> !image-2023-04-25-22-10-01-209.png!
>
> The reason: The leader sets follower's nextIndex to 0 in
> [https://github.com/apache/ratis/blob/60587b63a4401cc6160907d33fb5cd89dbbdc724/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java#L134]
> and then sends a snapshot to the follower.
> The SnapshotInstallationHandler in follower asserts it's a stale snapshot and
> throws a unrecoverable IllegalStatementException.
>
> h3. ISSUE 1
> The assertions should compare snapshot last included with *commit index*
> rather that next index.
> [https://github.com/apache/ratis/blob/60587b63a4401cc6160907d33fb5cd89dbbdc724/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotInstallationHandler.java#L177-L179]
>
>
> h3. ISSUE 2
> When a follower receives a stale snapshot from leader, rather than throwing a
> IlleaglStatementException in assert, can we just simply reply
> ALREADY_INSTALLED?
>
> h3. ISSUE 3
> When appendEntriesHandler onError is called, shall we remain the nextIndex
> unchanged?
> [https://github.com/apache/ratis/blob/60587b63a4401cc6160907d33fb5cd89dbbdc724/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java#L420]
>
> onError only happens when grpc connections has something wrong (channel
> disconnected, timeout, etc) and the leader receives no reply. I think we can
> keep nextIndex unchanged and retry. When the communications are restored, let
> onNext decide what is the correct nextIndex (may experience INCONSISTENCY).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)