feat: implement raft snapshot catchup
This commit is contained in:
@@ -3,12 +3,13 @@ namespace NATS.Server.Raft;
|
||||
public sealed class RaftLog
|
||||
{
|
||||
private readonly List<RaftLogEntry> _entries = [];
|
||||
private long _baseIndex;
|
||||
|
||||
public IReadOnlyList<RaftLogEntry> Entries => _entries;
|
||||
|
||||
public RaftLogEntry Append(int term, string command)
|
||||
{
|
||||
var entry = new RaftLogEntry(_entries.Count + 1, term, command);
|
||||
var entry = new RaftLogEntry(_baseIndex + _entries.Count + 1, term, command);
|
||||
_entries.Add(entry);
|
||||
return entry;
|
||||
}
|
||||
@@ -20,6 +21,12 @@ public sealed class RaftLog
|
||||
|
||||
_entries.Add(entry);
|
||||
}
|
||||
|
||||
public void ReplaceWithSnapshot(RaftSnapshot snapshot)
|
||||
{
|
||||
_entries.Clear();
|
||||
_baseIndex = snapshot.LastIncludedIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record RaftLogEntry(long Index, int Term, string Command);
|
||||
|
||||
Reference in New Issue
Block a user