- if (context.getReplicatedLog().dataSize() > dataThreshold) {
- // if memory is less, clear the log based on lastApplied.
- // this could/should only happen if one of the followers is down
- // as normally we keep removing from the log when its replicated to all.
+ boolean dataSizeThresholdExceeded = context.getReplicatedLog().dataSize() > dataThreshold;
+
+ boolean logSizeExceededSnapshotBatchCount =
+ context.getReplicatedLog().size() >= context.getConfigParams().getSnapshotBatchCount();
+LOG.debug("Log size: {}, getSnapshotBatchCount: {}",context.getReplicatedLog().size(),context.getConfigParams().getSnapshotBatchCount());
+ if (dataSizeThresholdExceeded || logSizeExceededSnapshotBatchCount) {
+ if(LOG.isDebugEnabled()) {
+ if(dataSizeThresholdExceeded) {
+ LOG.debug("{}: log data size {} exceeds the memory threshold {} - doing snapshotPreCommit with index {}",
+ context.getId(), context.getReplicatedLog().dataSize(), dataThreshold,
+ captureSnapshot.getLastAppliedIndex());
+ } else {
+ LOG.debug("{}: log size {} exceeds the snapshot batch count {} - doing snapshotPreCommit with index {}",
+ context.getId(), context.getReplicatedLog().size(),
+ context.getConfigParams().getSnapshotBatchCount(), captureSnapshot.getLastAppliedIndex());
+ }
+ }
+
+ // We either exceeded the memory threshold or the log size exceeded the snapshot batch
+ // count so, to keep the log memory footprint in check, clear the log based on lastApplied.
+ // This could/should only happen if one of the followers is down as normally we keep
+ // removing from the log as entries are replicated to all.