You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2020/02/07 23:20:01 UTC

[incubator-ratis] branch master updated: RATIS-804. Race condition between cache evict and load in LogSegment.

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/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 46f255c  RATIS-804. Race condition between cache evict and load in LogSegment.
46f255c is described below

commit 46f255cbf81fda3d4556c8fe1086f91e05d6aa3f
Author: Tsz Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Fri Feb 7 15:19:33 2020 -0800

    RATIS-804. Race condition between cache evict and load in LogSegment.
---
 .../org/apache/ratis/server/raftlog/segmented/LogSegment.java     | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

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 34552c2..20a9afd 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
@@ -339,7 +339,7 @@ public class LogSegment implements Comparable<Long> {
   /**
    * Remove records from the given index (inclusive)
    */
-  void truncate(long fromIndex) {
+  synchronized void truncate(long fromIndex) {
     Preconditions.assertTrue(fromIndex >= startIndex && fromIndex <= endIndex);
     for (long index = endIndex; index >= fromIndex; index--) {
       LogRecord removed = records.remove(Math.toIntExact(index - startIndex));
@@ -368,18 +368,18 @@ public class LogSegment implements Comparable<Long> {
         (this.getEndIndex() < l ? -1 : 1);
   }
 
-  void clear() {
+  synchronized void clear() {
     records.clear();
     entryCache.clear();
     configEntries.clear();
     endIndex = startIndex - 1;
   }
 
-  public int getLoadingTimes() {
+  int getLoadingTimes() {
     return loadingTimes.get();
   }
 
-  void evictCache() {
+  synchronized void evictCache() {
     entryCache.clear();
   }