This is an automated email from the ASF dual-hosted git repository.
szetszwo 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 89853ea72 RATIS-1707. Fix corner case when getPrevious in
LogAppenderBase (#745)
89853ea72 is described below
commit 89853ea72bf8357d1a6983b8b52419d0ec6ccf1e
Author: Nibiru <[email protected]>
AuthorDate: Thu Sep 22 17:14:06 2022 +0800
RATIS-1707. Fix corner case when getPrevious in LogAppenderBase (#745)
---
.../apache/ratis/server/impl/RaftServerImpl.java | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
index 8555d3b30..8c37e6273 100644
---
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
+++
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -1329,15 +1329,18 @@ class RaftServerImpl implements RaftServer.Division,
List<LogEntryProto> entries) {
if (entries != null && !entries.isEmpty()) {
final long index0 = entries.get(0).getIndex();
-
- if (previous == null || previous.getTerm() == 0) {
- Preconditions.assertTrue(index0 == 0,
- "Unexpected Index: previous is null but entries[%s].getIndex()=%s",
- 0, index0);
- } else {
- Preconditions.assertTrue(previous.getIndex() == index0 - 1,
- "Unexpected Index: previous is %s but entries[%s].getIndex()=%s",
- previous, 0, index0);
+ // Check if next entry's index is 1 greater than the snapshotIndex. If
yes, then
+ // we do not have to check for the existence of previous.
+ if (index0 != state.getSnapshotIndex() + 1) {
+ if (previous == null || previous.getTerm() == 0) {
+ Preconditions.assertTrue(index0 == 0,
+ "Unexpected Index: previous is null but
entries[%s].getIndex()=%s",
+ 0, index0);
+ } else {
+ Preconditions.assertTrue(previous.getIndex() == index0 - 1,
+ "Unexpected Index: previous is %s but entries[%s].getIndex()=%s",
+ previous, 0, index0);
+ }
}
for (int i = 0; i < entries.size(); i++) {