Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RATIS-2111] Reinitialize should load the latest snapshot #1111

Merged
merged 5 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void initialize(RaftServer server, RaftGroupId groupId,
@Override
public void reinitialize() throws IOException {
close();
storage.loadLatestSnapshot();
loadSnapshot(storage.getLatestSnapshot());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void initialize(RaftServer server, RaftGroupId groupId, RaftStorage raftS
*/
@Override
public void reinitialize() throws IOException {
storage.loadLatestSnapshot();
load(storage.getLatestSnapshot());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ public SingleFileSnapshotInfo getLatestSnapshot() {
}
}

public void loadLatestSnapshot() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it return SingleFileSnapshotInfo and then reuse it in getLatestSnapshot().

diff --git a/ratis-server/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorage.java b/ratis-server/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorage.java
index 88cc57dab5..7e8afbaa85 100644
--- a/ratis-server/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorage.java
+++ b/ratis-server/src/main/java/org/apache/ratis/statemachine/impl/SimpleStateMachineStorage.java
@@ -217,6 +217,10 @@ public class SimpleStateMachineStorage implements StateMachineStorage {
     if (s != null) {
       return s;
     }
+    return loadLatestSnapshot();
+  }
+
+  public SingleFileSnapshotInfo loadLatestSnapshot() {
     final File dir = stateMachineDir;
     if (dir == null) {
       return null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

final File dir = stateMachineDir;
if (dir == null) {
return;
}
try {
updateLatestSnapshot(findLatestSnapshot(dir.toPath()));
} catch (IOException ignored) {
}
}

@VisibleForTesting
File getStateMachineDir() {
return stateMachineDir;
Expand Down
Loading