runzhiwang commented on a change in pull request #317:
URL: https://github.com/apache/incubator-ratis/pull/317#discussion_r535217053



##########
File path: 
ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java
##########
@@ -388,10 +388,12 @@ public TermIndex getLastEntryTermIndex() {
     try(AutoCloseableLock writeLock = writeLock()) {
       validateLogEntry(entry);
       final LogSegment currentOpenSegment = cache.getOpenSegment();
+      // The stateMachineData will be cached inside the StateMachine itself 
when enable stateMachineCaching.
+      LogEntryProto toAppendEntry = stateMachineCachingEnabled? 
ServerProtoUtils.removeStateMachineData(entry) : entry;
       if (currentOpenSegment == null) {
         cache.addOpenSegment(entry.getIndex());
         fileLogWorker.startLogSegment(entry.getIndex());
-      } else if (isSegmentFull(currentOpenSegment, entry)) {
+      } else if (isSegmentFull(currentOpenSegment, toAppendEntry)) {

Review comment:
       @szetszwo #317 (comment) need a minor change, otherwise it maybe add 
more entry in the open segment if stateMachineCachingEnabled is false. In the 
`else` branch of `isSegmentFull` , we pass `LogSegment.Op.WRITE_SEGMENT_FILE`, 
which count the size of entry after remove StateMachineData, but the 
segment.getTotalSize() is the total size of entry without remove 
StateMachineData. So `segment.getTotalSize() + entrySize > segmentMaxSize` 
becomes (total size of entries without remove StateMachineData) + (size of 
entry after remove StateMachineData) > segmentMaxSize
   
   ```
   @@ -431,7 +432,7 @@ public class SegmentedRaftLog extends RaftLog {
        if (segment.getTotalSize() >= segmentMaxSize) {
          return true;
        } else {
   -      final long entrySize = LogSegment.getEntrySize(entry);
   +      final long entrySize = LogSegment.getEntrySize(entry, 
LogSegment.Op.WRITE_SEGMENT_FILE);
          // if entry size is greater than the max segment size, write it 
directly
          // into the current segment
         return entrySize <= segmentMaxSize &&
             segment.getTotalSize() + entrySize > segmentMaxSize;
   ```




----------------------------------------------------------------
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.

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


Reply via email to