kaijchen commented on pull request #616:
URL: https://github.com/apache/ratis/pull/616#issuecomment-1061709022


   @szetszwo @SincereXIA, Actually, there **is** a bug in current master.
   We need check the flush interval against first log pending to flush, not 
last flush.
   
   The following patch demonstrates the fix on current master 
(a4ffad20dfcc3f61d723e835db9aac075286deb3).
   
   ```java
   diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java
   index 9e5eb7e1..b6e10a4c 100644
   --- 
a/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLogWorker.java
   @@ -177,6 +177,7 @@ class SegmentedRaftLogWorker {
      private int flushBatchSize;
    
      private Timestamp lastFlush;
   +  private Timestamp firstArrival;
      private final TimeDuration flushIntervalMin;
    
      private final StateMachineDataPolicy stateMachineDataPolicy;
   @@ -218,6 +219,7 @@ class SegmentedRaftLogWorker {
        final int bufferSize = 
RaftServerConfigKeys.Log.writeBufferSize(properties).getSizeInt();
        this.writeBuffer = ByteBuffer.allocateDirect(bufferSize);
        this.lastFlush = Timestamp.currentTime();
   +    this.firstArrival = Timestamp.currentTime();
        this.flushIntervalMin = 
RaftServerConfigKeys.Log.flushIntervalMin(properties);
      }
    
   @@ -355,7 +357,10 @@ class SegmentedRaftLogWorker {
        } else if (pendingFlushNum >= forceSyncNum) {
          return true;
        }
   -    return pendingFlushNum > 0 && queue.isEmpty() && 
lastFlush.elapsedTime().compareTo(flushIntervalMin) > 0;
   +    if (lastFlush.compareTo(firstArrival) >= 0) {
   +      firstArrival = Timestamp.currentTime();
   +    }
   +    return pendingFlushNum > 0 && queue.isEmpty() && 
firstArrival.elapsedTime().compareTo(flushIntervalMin) > 0;
      }
    
      @SuppressFBWarnings("NP_NULL_PARAM_DEREF")
   -- 
   2.27.0
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to