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



##########
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:
       For this case, it should removeStateMachineData no matter 
stateMachineCachingEnabled is true or false.  How about the following?
   ```
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/raftlog/segmented/SegmentedRaftLog.java
   @@ -385,13 +385,14 @@ public class SegmentedRaftLog extends RaftLog {
        if (LOG.isTraceEnabled()) {
          LOG.trace("{}: appendEntry {}", getName(), 
ServerProtoUtils.toLogEntryString(entry));
        }
   +    final LogEntryProto removedStateMachineData = 
ServerProtoUtils.removeStateMachineData(entry);
        try(AutoCloseableLock writeLock = writeLock()) {
          validateLogEntry(entry);
          final LogSegment currentOpenSegment = cache.getOpenSegment();
          if (currentOpenSegment == null) {
            cache.addOpenSegment(entry.getIndex());
            fileLogWorker.startLogSegment(entry.getIndex());
   -      } else if (isSegmentFull(currentOpenSegment, entry)) {
   +      } else if (isSegmentFull(currentOpenSegment, 
removedStateMachineData)) {
            cache.rollOpenSegment(true);
            fileLogWorker.rollLogSegment(currentOpenSegment);
            checkAndEvictCache();
   @@ -414,7 +415,7 @@ public class SegmentedRaftLog extends RaftLog {
              fileLogWorker.writeLogEntry(entry).getFuture();
          if (stateMachineCachingEnabled) {
            // The stateMachineData will be cached inside the StateMachine 
itself.
   -        cache.appendEntry(ServerProtoUtils.removeStateMachineData(entry));
   +        cache.appendEntry(removedStateMachineData));
          } else {
            cache.appendEntry(entry);
          }
   ```
   




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