This is an automated email from the ASF dual-hosted git repository.
dragonyliu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new ca9fdd29e RATIS-1543. Log from GrpcLogAppender is confusing. (#821)
ca9fdd29e is described below
commit ca9fdd29e15b81464fd20d73a1d070a050bae30c
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Fri Feb 17 01:22:28 2023 -0800
RATIS-1543. Log from GrpcLogAppender is confusing. (#821)
---
.../apache/ratis/grpc/server/GrpcLogAppender.java | 23 +++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git
a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
index e30f3b8c5..b9b88f471 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java
@@ -121,13 +121,14 @@ public class GrpcLogAppender extends LogAppenderBase {
firstResponseReceived = false;
// clear the pending requests queue and reset the next index of follower
pendingRequests.clear();
+ final FollowerInfo f = getFollower();
final long nextIndex = 1 + Optional.ofNullable(request)
.map(AppendEntriesRequest::getPreviousLog)
.map(TermIndex::getIndex)
- .orElseGet(getFollower()::getMatchIndex);
- if (onError && getFollower().getMatchIndex() == 0 && request == null) {
- LOG.warn("{}: Leader has not got in touch with Follower {} yet, " +
- "just keep nextIndex unchanged and retry.", this, getFollower());
+ .orElseGet(f::getMatchIndex);
+ if (onError && f.getMatchIndex() == 0 && request == null) {
+ LOG.warn("{}: Follower failed when matchIndex == 0, " +
+ " keep nextIndex ({}) unchanged and retry.", this, f.getNextIndex());
return;
}
getFollower().decreaseNextIndex(nextIndex);
@@ -320,8 +321,10 @@ public class GrpcLogAppender extends LogAppenderBase {
}
}
- private void increaseNextIndex(final long installedSnapshotIndex) {
- getFollower().updateNextIndex(installedSnapshotIndex + 1);
+ private void increaseNextIndex(final long installedSnapshotIndex, Object
reason) {
+ final long newNextIndex = installedSnapshotIndex + 1;
+ LOG.info("{}: updateNextIndex {} for {}", this, newNextIndex, reason);
+ getFollower().updateNextIndex(newNextIndex);
}
/**
@@ -377,12 +380,14 @@ public class GrpcLogAppender extends LogAppenderBase {
break;
case NOT_LEADER:
grpcServerMetrics.onRequestNotLeader(getFollowerId().toString());
+ LOG.warn("{}: received {} reply with term {}", this,
reply.getResult(), reply.getTerm());
if (onFollowerTerm(reply.getTerm())) {
return;
}
break;
case INCONSISTENCY:
grpcServerMetrics.onRequestInconsistency(getFollowerId().toString());
+ LOG.warn("{}: received {} reply with nextIndex {}", this,
reply.getResult(), reply.getNextIndex());
updateNextIndex(reply.getNextIndex());
break;
default:
@@ -515,7 +520,7 @@ public class GrpcLogAppender extends LogAppenderBase {
getFollower().setSnapshotIndex(followerSnapshotIndex);
getFollower().setAttemptedToInstallSnapshot();
getLeaderState().onFollowerCommitIndex(getFollower(),
followerSnapshotIndex);
- increaseNextIndex(followerSnapshotIndex);
+ increaseNextIndex(followerSnapshotIndex, reply.getResult());
removePending(reply);
break;
case NOT_LEADER:
@@ -532,7 +537,7 @@ public class GrpcLogAppender extends LogAppenderBase {
getFollower().setSnapshotIndex(followerSnapshotIndex);
getFollower().setAttemptedToInstallSnapshot();
getLeaderState().onFollowerCommitIndex(getFollower(),
followerSnapshotIndex);
- increaseNextIndex(followerSnapshotIndex);
+ increaseNextIndex(followerSnapshotIndex, reply.getResult());
onFollowerCatchup(followerSnapshotIndex);
removePending(reply);
break;
@@ -543,7 +548,7 @@ public class GrpcLogAppender extends LogAppenderBase {
removePending(reply);
break;
case UNRECOGNIZED:
- LOG.error("Unrecongnized the reply result {}: Leader is {}, follower
is {}",
+ LOG.error("Unrecognized the reply result {}: Leader is {}, follower
is {}",
reply.getResult(), getServer().getId(), getFollowerId());
break;
default: