You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by dr...@apache.org on 2022/10/03 13:01:06 UTC
[ratis] 01/03: RATIS-1707. Fix corner case when getPrevious in LogAppenderBase (#745)
This is an automated email from the ASF dual-hosted git repository.
dragonyliu pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/ratis.git
commit fb63635a7d37bb859deda9c8ad00d4a8cae36d88
Author: Nibiru <ax...@qq.com>
AuthorDate: Thu Sep 22 17:14:06 2022 +0800
RATIS-1707. Fix corner case when getPrevious in LogAppenderBase (#745)
(cherry picked from commit 89853ea72bf8357d1a6983b8b52419d0ec6ccf1e)
---
.../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 2aa14cbed..3d6fb517b 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
@@ -1259,15 +1259,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++) {