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
commit 72ec12b7c2276d5698ca1013b79ac08769048afa Author: Jinrui.Zhang <[email protected]> AuthorDate: Thu Jun 23 20:44:16 2022 +0800 revert some test changes --- .../apache/iotdb/consensus/config/RatisConfig.java | 4 +- .../ratis/ApplicationStateMachineProxy.java | 63 ++++++++++------------ server/src/assembly/resources/conf/logback.xml | 1 - 3 files changed, 31 insertions(+), 37 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 397389faf3..5a1574177c 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,8 +292,8 @@ public class RatisConfig { public static class Builder { private boolean autoTriggerEnabled = true; private long creationGap = RaftServerConfigKeys.Snapshot.CREATION_GAP_DEFAULT; - private long autoTriggerThreshold = 100_000L; - // RaftServerConfigKeys.Snapshot.AUTO_TRIGGER_THRESHOLD_DEFAULT; + private long autoTriggerThreshold = + RaftServerConfigKeys.Snapshot.AUTO_TRIGGER_THRESHOLD_DEFAULT; private int retentionFileNum = RaftServerConfigKeys.Snapshot.RETENTION_FILE_NUM_DEFAULT; public Snapshot build() { 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 e7d5ab7f60..6588d5dbb4 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,46 +142,41 @@ public class ApplicationStateMachineProxy extends BaseStateMachine { @Override public long takeSnapshot() throws IOException { - long startTime = System.nanoTime(); - try { - final TermIndex lastApplied = getLastAppliedTermIndex(); - if (lastApplied.getTerm() <= 0 || lastApplied.getIndex() <= 0) { - return RaftLog.INVALID_LOG_INDEX; - } + 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); - } - 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); } - return lastApplied.getIndex(); - } finally { - logger.info("snapshot taking cost : {}ms", (System.nanoTime() - startTime) * 1.0 / 1000_000); + return RaftLog.INVALID_LOG_INDEX; } + return lastApplied.getIndex(); } private void loadSnapshot(File latestSnapshotDir) { diff --git a/server/src/assembly/resources/conf/logback.xml b/server/src/assembly/resources/conf/logback.xml index babf9b66d5..286e99cc38 100644 --- a/server/src/assembly/resources/conf/logback.xml +++ b/server/src/assembly/resources/conf/logback.xml @@ -299,5 +299,4 @@ <logger level="info" name="COMPACTION"> <appender-ref ref="COMPACTION"/> </logger> - <logger level="debug" name="org.apache.ratis"/> </configuration>
