feat: complete final jetstream parity transport and runtime baselines
This commit is contained in:
@@ -27,6 +27,36 @@ public sealed class RaftLog
|
||||
_entries.Clear();
|
||||
_baseIndex = snapshot.LastIncludedIndex;
|
||||
}
|
||||
|
||||
public async Task PersistAsync(string path, CancellationToken ct)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
var model = new PersistedLog
|
||||
{
|
||||
BaseIndex = _baseIndex,
|
||||
Entries = [.. _entries],
|
||||
};
|
||||
await File.WriteAllTextAsync(path, System.Text.Json.JsonSerializer.Serialize(model), ct);
|
||||
}
|
||||
|
||||
public static async Task<RaftLog> LoadAsync(string path, CancellationToken ct)
|
||||
{
|
||||
var log = new RaftLog();
|
||||
if (!File.Exists(path))
|
||||
return log;
|
||||
|
||||
var json = await File.ReadAllTextAsync(path, ct);
|
||||
var model = System.Text.Json.JsonSerializer.Deserialize<PersistedLog>(json) ?? new PersistedLog();
|
||||
log._baseIndex = model.BaseIndex;
|
||||
log._entries.AddRange(model.Entries);
|
||||
return log;
|
||||
}
|
||||
|
||||
private sealed class PersistedLog
|
||||
{
|
||||
public long BaseIndex { get; set; }
|
||||
public List<RaftLogEntry> Entries { get; set; } = [];
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record RaftLogEntry(long Index, int Term, string Command);
|
||||
|
||||
Reference in New Issue
Block a user