feat: implement jetstream governance runtime parity semantics

This commit is contained in:
Joseph Doherty
2026-02-23 14:54:30 -05:00
parent 0413ff6ae9
commit 148ff9ebb6
4 changed files with 56 additions and 2 deletions

View File

@@ -7,6 +7,8 @@ public sealed class JetStreamMetaGroup
{
private readonly int _nodes;
private readonly ConcurrentDictionary<string, byte> _streams = new(StringComparer.Ordinal);
private int _leaderIndex = 1;
private long _leadershipVersion = 1;
public JetStreamMetaGroup(int nodes)
{
@@ -25,13 +27,18 @@ public sealed class JetStreamMetaGroup
{
Streams = _streams.Keys.OrderBy(x => x, StringComparer.Ordinal).ToArray(),
ClusterSize = _nodes,
LeaderId = $"meta-{_leaderIndex}",
LeadershipVersion = _leadershipVersion,
};
}
public void StepDown()
{
// Placeholder for parity API behavior; current in-memory meta group
// does not track explicit leader state.
_leaderIndex++;
if (_leaderIndex > Math.Max(_nodes, 1))
_leaderIndex = 1;
Interlocked.Increment(ref _leadershipVersion);
}
}
@@ -39,4 +46,6 @@ public sealed class MetaGroupState
{
public IReadOnlyList<string> Streams { get; init; } = [];
public int ClusterSize { get; init; }
public string LeaderId { get; init; } = string.Empty;
public long LeadershipVersion { get; init; }
}