未验证 提交 6e2fe072 编写于 作者: W William Song 提交者: GitHub

[To rel/1.0] fix snapshot init warning (#8226)

上级 f95389f3
...@@ -61,13 +61,13 @@ public class ApplicationStateMachineProxy extends BaseStateMachine { ...@@ -61,13 +61,13 @@ public class ApplicationStateMachineProxy extends BaseStateMachine {
public ApplicationStateMachineProxy(IStateMachine stateMachine, RaftGroupId id) { public ApplicationStateMachineProxy(IStateMachine stateMachine, RaftGroupId id) {
applicationStateMachine = stateMachine; applicationStateMachine = stateMachine;
groupId = id;
retryPolicy = retryPolicy =
applicationStateMachine instanceof IStateMachine.RetryPolicy applicationStateMachine instanceof IStateMachine.RetryPolicy
? (IStateMachine.RetryPolicy) applicationStateMachine ? (IStateMachine.RetryPolicy) applicationStateMachine
: new IStateMachine.RetryPolicy() {}; : new IStateMachine.RetryPolicy() {};
snapshotStorage = new SnapshotStorage(applicationStateMachine); snapshotStorage = new SnapshotStorage(applicationStateMachine, groupId);
applicationStateMachine.start(); applicationStateMachine.start();
groupId = id;
} }
@Override @Override
......
...@@ -20,6 +20,7 @@ package org.apache.iotdb.consensus.ratis; ...@@ -20,6 +20,7 @@ package org.apache.iotdb.consensus.ratis;
import org.apache.iotdb.consensus.IStateMachine; import org.apache.iotdb.consensus.IStateMachine;
import org.apache.ratis.protocol.RaftGroupId;
import org.apache.ratis.server.protocol.TermIndex; import org.apache.ratis.server.protocol.TermIndex;
import org.apache.ratis.server.storage.FileInfo; import org.apache.ratis.server.storage.FileInfo;
import org.apache.ratis.server.storage.RaftStorage; import org.apache.ratis.server.storage.RaftStorage;
...@@ -39,7 +40,6 @@ import java.nio.file.Path; ...@@ -39,7 +40,6 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
public class SnapshotStorage implements StateMachineStorage { public class SnapshotStorage implements StateMachineStorage {
...@@ -48,17 +48,28 @@ public class SnapshotStorage implements StateMachineStorage { ...@@ -48,17 +48,28 @@ public class SnapshotStorage implements StateMachineStorage {
private final String TMP_PREFIX = ".tmp."; private final String TMP_PREFIX = ".tmp.";
private File stateMachineDir; private File stateMachineDir;
private final RaftGroupId groupId;
private File snapshotStorageRoot;
private final ReentrantReadWriteLock snapshotCacheGuard = new ReentrantReadWriteLock(); private final ReentrantReadWriteLock snapshotCacheGuard = new ReentrantReadWriteLock();
private SnapshotInfo currentSnapshot = null; private SnapshotInfo currentSnapshot = null;
public SnapshotStorage(IStateMachine applicationStateMachine) { public SnapshotStorage(IStateMachine applicationStateMachine, RaftGroupId groupId) {
this.applicationStateMachine = applicationStateMachine; this.applicationStateMachine = applicationStateMachine;
this.groupId = groupId;
} }
@Override @Override
public void init(RaftStorage raftStorage) throws IOException { public void init(RaftStorage raftStorage) throws IOException {
this.stateMachineDir = raftStorage.getStorageDir().getStateMachineDir(); this.stateMachineDir = raftStorage.getStorageDir().getStateMachineDir();
if (getSnapshotDir() != null) {
snapshotStorageRoot = new File(getSnapshotDir(), groupId.toString());
} else {
snapshotStorageRoot = stateMachineDir;
}
if (!snapshotStorageRoot.exists()) {
FileUtils.createDirectories(snapshotStorageRoot);
}
updateSnapshotCache(); updateSnapshotCache();
} }
...@@ -168,7 +179,7 @@ public class SnapshotStorage implements StateMachineStorage { ...@@ -168,7 +179,7 @@ public class SnapshotStorage implements StateMachineStorage {
} }
public File getStateMachineDir() { public File getStateMachineDir() {
return Optional.ofNullable(getSnapshotDir()).orElse(stateMachineDir); return snapshotStorageRoot;
} }
public File getSnapshotDir(String snapshotMetadata) { public File getSnapshotDir(String snapshotMetadata) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册