feat: add peer management with stream reassignment (Gap 2.4)

Add ProcessAddPeer/ProcessRemovePeer to JetStreamMetaGroup for
peer-driven stream reassignment. Includes AddKnownPeer/RemoveKnownPeer
tracked in a HashSet, RemovePeerFromStream, RemapStreamAssignment with
replacement-peer selection from the known pool, and DesiredReplicas on
RaftGroup for under-replication detection. Go ref: jetstream_cluster.go:2290-2439.
This commit is contained in:
Joseph Doherty
2026-02-25 08:53:05 -05:00
parent 0f8f34afaa
commit e5f599f770
2 changed files with 445 additions and 0 deletions

View File

@@ -14,6 +14,18 @@ public sealed class RaftGroup
public string Cluster { get; set; } = string.Empty;
public string Preferred { get; set; } = string.Empty;
/// <summary>
/// Optional desired replica count for this group.
/// When set, ProcessAddPeer uses this to detect under-replication.
/// Go reference: jetstream_cluster.go:2284 sa.missingPeers() — len(Peers) &lt; Config.Replicas.
/// </summary>
public int DesiredReplicas { get; set; }
/// <summary>
/// True when <see cref="DesiredReplicas"/> has been explicitly set (non-zero).
/// </summary>
public bool HasDesiredReplicas => DesiredReplicas > 0;
public int QuorumSize => (Peers.Count / 2) + 1;
public bool HasQuorum(int ackCount) => ackCount >= QuorumSize;
}