szetszwo commented on code in PR #1055:
URL: https://github.com/apache/ratis/pull/1055#discussion_r1535866982
##########
ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java:
##########
@@ -341,6 +364,10 @@ private void notifyAppliedIndex(long index) {
appliedIndexConsumer.accept(index);
}
+ void setRemoving() {
+ this.isRemoving = true;
+ }
+
Review Comment:
Let's move it to right below `shouldTakeSnapshotAtStop()`.
##########
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:
Let's call it `shouldTakeSnapshotAtStop`. We may simply the logic as below:
```java
private boolean shouldTakeSnapshotAtStop() {
if (isRemoving) {
return triggerSnapshotWhenRemoveEnabled;
} else {
return triggerSnapshotWhenStopEnabled;
}
}
```
--
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]