runzhiwang commented on a change in pull request #317:
URL: https://github.com/apache/incubator-ratis/pull/317#discussion_r535198688
##########
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 The problem is `cache.appendEntry(entry)` will put entry with
`StateMachineData` into `LogSegment#entryCache`. For example, each entry occupy
8KB after remove `StateMachineData`, each `StateMachineData` is 80MB, the
segment.size.max is 8MB, when `isSegmentFull` returns true, open segment has
1000 entry, and `LogSegment#entryCache` is 80MB * 1000, i.e. 80GB.
```
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]