ratis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject incubator-ratis git commit: RATIS-448. IllegalStateException seen when log to be truncated does not exist. Contributed by Lokesh Jain
Date Wed, 05 Dec 2018 22:13:38 GMT
Repository: incubator-ratis
Updated Branches:
  refs/heads/master 046782430 -> 27a8cbb49


RATIS-448. IllegalStateException seen when log to be truncated does not exist.  Contributed
by Lokesh Jain


Project: http://git-wip-us.apache.org/repos/asf/incubator-ratis/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ratis/commit/27a8cbb4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ratis/tree/27a8cbb4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ratis/diff/27a8cbb4

Branch: refs/heads/master
Commit: 27a8cbb49db95327d1c70b8665944510083de3d4
Parents: 0467824
Author: Tsz Wo Nicholas Sze <szetszwo@apache.org>
Authored: Wed Dec 5 14:12:18 2018 -0800
Committer: Tsz Wo Nicholas Sze <szetszwo@apache.org>
Committed: Wed Dec 5 14:12:18 2018 -0800

----------------------------------------------------------------------
 .../ratis/server/storage/RaftLogWorker.java     | 27 ++++++++++----------
 1 file changed, 13 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ratis/blob/27a8cbb4/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftLogWorker.java
----------------------------------------------------------------------
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftLogWorker.java
b/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftLogWorker.java
index 06eda5e..da8daa9 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftLogWorker.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/storage/RaftLogWorker.java
@@ -297,8 +297,8 @@ class RaftLogWorker implements Runnable {
   }
 
   void rollLogSegment(LogSegment segmentToClose) {
-    LOG.info("{}: Rolling segment to index:{}", name,
-        (segmentToClose.getEndIndex() + 1));
+    LOG.info("{}: Rolling segment {} to index:{}", name,
+        segmentToClose.toString(), segmentToClose.getEndIndex());
     addIOTask(new FinalizeLogSegment(segmentToClose));
     addIOTask(new StartLogSegment(segmentToClose.getEndIndex() + 1));
   }
@@ -369,27 +369,26 @@ class RaftLogWorker implements Runnable {
   }
 
   private class FinalizeLogSegment extends Task {
-    private final LogSegment segmentToClose;
+    private final long startIndex;
+    private final long endIndex;
 
     FinalizeLogSegment(LogSegment segmentToClose) {
-      this.segmentToClose = segmentToClose;
+      Preconditions.assertTrue(segmentToClose != null, "Log segment to be rolled is null");
+      this.startIndex = segmentToClose.getStartIndex();
+      this.endIndex = segmentToClose.getEndIndex();
     }
 
     @Override
     public void execute() throws IOException {
       IOUtils.cleanup(LOG, out);
       out = null;
-      Preconditions.assertTrue(segmentToClose != null);
 
-      File openFile = storage.getStorageDir()
-          .getOpenLogFile(segmentToClose.getStartIndex());
+      File openFile = storage.getStorageDir().getOpenLogFile(startIndex);
       Preconditions.assertTrue(openFile.exists(),
-          () -> name + ": File " + openFile + " does not exist, segmentToClose="
-              + segmentToClose.toDebugString());
-      if (segmentToClose.numOfEntries() > 0) {
+          () -> name + ": File " + openFile + " to be rolled does not exist");
+      if (endIndex - startIndex + 1 > 0) {
         // finalize the current open segment
-        File dstFile = storage.getStorageDir().getClosedLogFile(
-            segmentToClose.getStartIndex(), segmentToClose.getEndIndex());
+        File dstFile = storage.getStorageDir().getClosedLogFile(startIndex, endIndex);
         Preconditions.assertTrue(!dstFile.exists());
 
         FileUtils.move(openFile, dstFile);
@@ -403,12 +402,12 @@ class RaftLogWorker implements Runnable {
 
     @Override
     long getEndIndex() {
-      return segmentToClose.getEndIndex();
+      return endIndex;
     }
 
     @Override
     public String toString() {
-      return super.toString() + ": " + segmentToClose.toDebugString();
+      return super.toString() + ": " + "startIndex=" + startIndex + " endIndex=" + endIndex;
     }
   }
 


Mime
View raw message