OneSizeFitsQuorum commented on code in PR #1055:
URL: https://github.com/apache/ratis/pull/1055#discussion_r1536550269
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java:
##########
@@ -327,12 +332,30 @@ private boolean shouldTakeSnapshot() {
if (autoSnapshotThreshold == null) {
return false;
} else if (shouldStop()) {
- return triggerSnapshotWhenStopEnabled && getLastAppliedIndex() -
snapshotIndex.get() > 0;
+ return shouldTakeSnapshotAccordingToConfAndStatus() &&
getLastAppliedIndex() - snapshotIndex.get() > 0;
}
return state == State.RUNNING &&
getStateMachineLastAppliedIndex() - snapshotIndex.get() >=
autoSnapshotThreshold;
}
+ /**
+ * In view of the three variables triggerSnapshotWhenStopEnabled,
triggerSnapshotWhenRemoveEnabled and isRemoving,
+ * we can draw the following 8 combination:
+ * true true true => true
+ * true true false => true
+ * true false true => false
+ * true false false => true
+ * false true true => true
+ * false true false => false
+ * false false true => false
+ * false false false => false
+ * @return result
+ */
+ private boolean shouldTakeSnapshotAccordingToConfAndStatus() {
+ return (triggerSnapshotWhenStopEnabled || isRemoving)
+ && (triggerSnapshotWhenRemoveEnabled || !isRemoving);
Review Comment:
The codes looks much clearer!
--
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]