26 lines
616 B
C#
26 lines
616 B
C#
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);
|