You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2022/06/23 05:24:12 UTC
[iotdb] branch test_ratis_0623 updated: change snapshot threshold to 100K
This is an automated email from the ASF dual-hosted git repository.
xingtanzjr pushed a commit to branch test_ratis_0623
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/test_ratis_0623 by this push:
new 179ea4ebd3 change snapshot threshold to 100K
179ea4ebd3 is described below
commit 179ea4ebd3c0695e4be7fb62bc43bbb831be1815
Author: Jinrui.Zhang <xi...@gmail.com>
AuthorDate: Thu Jun 23 13:24:01 2022 +0800
change snapshot threshold to 100K
---
.../apache/iotdb/consensus/config/RatisConfig.java | 2 +-
.../ratis/ApplicationStateMachineProxy.java | 63 ++++++++++++----------
2 files changed, 35 insertions(+), 30 deletions(-)
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/config/RatisConfig.java b/consensus/src/main/java/org/apache/iotdb/consensus/config/RatisConfig.java
index 9f6882a4d2..7f4694bfc0 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/config/RatisConfig.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/config/RatisConfig.java
@@ -292,7 +292,7 @@ public class RatisConfig {
public static class Builder {
private boolean autoTriggerEnabled = true;
private long creationGap = RaftServerConfigKeys.Snapshot.CREATION_GAP_DEFAULT;
- private long autoTriggerThreshold = 10000L;
+ private long autoTriggerThreshold = 100_000L;
// RaftServerConfigKeys.Snapshot.AUTO_TRIGGER_THRESHOLD_DEFAULT;
private int retentionFileNum = RaftServerConfigKeys.Snapshot.RETENTION_FILE_NUM_DEFAULT;
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java
index 6588d5dbb4..e7d5ab7f60 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/ApplicationStateMachineProxy.java
@@ -142,41 +142,46 @@ public class ApplicationStateMachineProxy extends BaseStateMachine {
@Override
public long takeSnapshot() throws IOException {
- final TermIndex lastApplied = getLastAppliedTermIndex();
- if (lastApplied.getTerm() <= 0 || lastApplied.getIndex() <= 0) {
- return RaftLog.INVALID_LOG_INDEX;
- }
+ long startTime = System.nanoTime();
+ try {
+ final TermIndex lastApplied = getLastAppliedTermIndex();
+ if (lastApplied.getTerm() <= 0 || lastApplied.getIndex() <= 0) {
+ return RaftLog.INVALID_LOG_INDEX;
+ }
- // require the application statemachine to take the latest snapshot
- String metadata = Utils.getMetadataFromTermIndex(lastApplied);
- File snapshotDir = snapshotStorage.getSnapshotDir(metadata);
+ // require the application statemachine to take the latest snapshot
+ String metadata = Utils.getMetadataFromTermIndex(lastApplied);
+ File snapshotDir = snapshotStorage.getSnapshotDir(metadata);
- // delete snapshotDir fully in case of last takeSnapshot() crashed
- FileUtils.deleteFully(snapshotDir);
+ // delete snapshotDir fully in case of last takeSnapshot() crashed
+ FileUtils.deleteFully(snapshotDir);
- snapshotDir.mkdir();
- if (!snapshotDir.isDirectory()) {
- logger.error("Unable to create snapshotDir at {}", snapshotDir);
- return RaftLog.INVALID_LOG_INDEX;
- }
+ snapshotDir.mkdir();
+ if (!snapshotDir.isDirectory()) {
+ logger.error("Unable to create snapshotDir at {}", snapshotDir);
+ return RaftLog.INVALID_LOG_INDEX;
+ }
- boolean applicationTakeSnapshotSuccess = applicationStateMachine.takeSnapshot(snapshotDir);
- boolean addTermIndexMetafileSuccess =
- snapshotStorage.addTermIndexMetaFile(snapshotDir, metadata);
-
- if (!applicationTakeSnapshotSuccess || !addTermIndexMetafileSuccess) {
- // this takeSnapshot failed, clean up files and directories
- // statemachine is supposed to clear snapshotDir on failure
- boolean isEmpty = snapshotDir.delete();
- if (!isEmpty) {
- logger.warn(
- "StateMachine take snapshot failed but leave unexpected remaining files at "
- + snapshotDir.getAbsolutePath());
- FileUtils.deleteFully(snapshotDir);
+ boolean applicationTakeSnapshotSuccess = applicationStateMachine.takeSnapshot(snapshotDir);
+ boolean addTermIndexMetafileSuccess =
+ snapshotStorage.addTermIndexMetaFile(snapshotDir, metadata);
+
+ if (!applicationTakeSnapshotSuccess || !addTermIndexMetafileSuccess) {
+ // this takeSnapshot failed, clean up files and directories
+ // statemachine is supposed to clear snapshotDir on failure
+ boolean isEmpty = snapshotDir.delete();
+ if (!isEmpty) {
+ logger.warn(
+ "StateMachine take snapshot failed but leave unexpected remaining files at "
+ + snapshotDir.getAbsolutePath());
+ FileUtils.deleteFully(snapshotDir);
+ }
+ return RaftLog.INVALID_LOG_INDEX;
}
- return RaftLog.INVALID_LOG_INDEX;
+ return lastApplied.getIndex();
+ } finally {
+ logger.info("snapshot taking cost : {}ms", (System.nanoTime() - startTime) * 1.0 / 1000_000);
}
- return lastApplied.getIndex();
}
private void loadSnapshot(File latestSnapshotDir) {