You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by ms...@apache.org on 2020/05/23 16:12:58 UTC
[incubator-ratis] branch master updated: RATIS-937. Loading of open
segments always throws corrupted segment warning (#100)
This is an automated email from the ASF dual-hosted git repository.
msingh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 8fdf86f RATIS-937. Loading of open segments always throws corrupted segment warning (#100)
8fdf86f is described below
commit 8fdf86f11838d7c0ab356f9388650b270b0bb291
Author: Hanisha Koneru <ha...@apache.org>
AuthorDate: Sat May 23 09:12:47 2020 -0700
RATIS-937. Loading of open segments always throws corrupted segment warning (#100)
---
.../org/apache/ratis/server/raftlog/segmented/LogSegment.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
index af5d32c..c27ec68 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/LogSegment.java
@@ -44,6 +44,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
+import static org.apache.ratis.server.raftlog.RaftLog.INVALID_LOG_INDEX;
+
/**
* In-memory cache for a log segment file. All the updates will be first written
* into LogSegment then into corresponding files in the same order.
@@ -145,6 +147,10 @@ public class LogSegment implements Comparable<Long> {
});
LOG.info("Successfully read {} entries from segment file {}", entryCount, file);
+ if (isOpen) {
+ end = segment.getEndIndex();
+ }
+
final int expectedEntryCount = Math.toIntExact(end - start + 1);
final boolean corrupted = entryCount != expectedEntryCount;
if (corrupted) {
@@ -181,7 +187,7 @@ public class LogSegment implements Comparable<Long> {
Preconditions.assertSame(expectedLastIndex, last.getTermIndex().getIndex(), "Index at the last record");
Preconditions.assertSame(expectedStart, records.get(0).getTermIndex().getIndex(), "Index at the first record");
}
- if (!isOpen && !corrupted) {
+ if (!corrupted) {
Preconditions.assertSame(expectedEnd, expectedLastIndex, "End/last Index");
}
}