Skip to content

Add IsLeader property to ClusterInfo#182

Merged
stidsborg merged 1 commit into
mainfrom
cluster-info-is-leader
Jul 4, 2026
Merged

Add IsLeader property to ClusterInfo#182
stidsborg merged 1 commit into
mainfrom
cluster-info-is-leader

Conversation

@stidsborg

Copy link
Copy Markdown
Owner

Introduces the concept of a cluster leader: the replica with the lowest replica id (guid) is the leader.

Rather than storing a separate flag, ClusterInfo.IsLeader is derived from state the ReplicaWatchdog already maintains — CalculateOffset orders all replica ids ascending, so the replica with the lowest guid is exactly the one with Offset == 0. Leadership therefore updates automatically each watchdog iteration as replicas join or crash.

A ReplicaCount > 0 guard ensures a replica does not report itself as leader before ReplicaWatchdog.Initialize has run.

The existing ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted template test is extended with IsLeader assertions, verifying leadership hand-off as replicas are added and deleted across all four store implementations (in-memory, PostgreSQL, MariaDB, SqlServer).

🤖 Generated with Claude Code

@stidsborg stidsborg merged commit c493b44 into main Jul 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant