feat: implement raft log replication and apply

This commit is contained in:
Joseph Doherty
2026-02-23 06:12:18 -05:00
parent 66ec378bdc
commit ecc4752c07
5 changed files with 113 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
namespace NATS.Server.Raft;
public sealed class RaftLog
{
private readonly List<RaftLogEntry> _entries = [];
public IReadOnlyList<RaftLogEntry> Entries => _entries;
public RaftLogEntry Append(int term, string command)
{
var entry = new RaftLogEntry(_entries.Count + 1, term, command);
_entries.Add(entry);
return entry;
}
public void AppendReplicated(RaftLogEntry entry)
{
if (_entries.Any(e => e.Index == entry.Index))
return;
_entries.Add(entry);
}
}
public sealed record RaftLogEntry(long Index, int Term, string Command);