Add GetCrashedReplicaMessages and SetReplica to IMessageStore#166
Merged
Conversation
GetCrashedReplicaMessages returns the (flow, position) identifiers of undelivered messages owned by a replica that is no longer alive (not in the supplied live-replica set). SetReplica re-assigns the messages at the given positions to a new replica, guarded by an expected-replica check so a concurrent takeover is not clobbered. Implemented across the in-memory, PostgreSQL, MariaDB and SqlServer stores, with shared message-store tests covering crashed-replica fetching and guarded re-assignment.
Introduces a named StoredIdAndPosition record (in Storage/Types.cs) for the GetCrashedReplicaMessages result instead of the anonymous Tuple<StoredId, long>, giving the (flow, position) pair meaningful member names.
…ssages The message replica is always populated (AppendMessage COALESCEs to the publisher replica, never null), so the column is now declared NOT NULL across all three stores. With non-null replicas the GetCrashedReplicaMessages query drops the redundant IS NOT NULL guard, the unneeded ORDER BY, and the empty-live-set conditional (the caller is always among the live replicas), leaving a plain WHERE replica NOT IN (...) / != ALL.
A set is the natural type for the membership test and matches how live replicas are already represented elsewhere (ReplicaWatchdog builds a HashSet). The in-memory store now uses the set's Contains directly instead of copying into a local HashSet.
Replaces the generated @position0, @Position1, ... parameters with a single comma-separated @positions parameter split server-side (CAST AS BIGINT), matching the STRING_SPLIT convention used elsewhere in the store. The message-store wrapper already short-circuits on an empty position list, so STRING_SPLIT never receives an empty string.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two methods to
IMessageStoreto support re-distributing messages stranded by crashed replicas:GetCrashedReplicaMessagesreturns the(StoredId, position)identifiers of undelivered messages whose owning replica is not in the supplied live-replica set — i.e. messages stranded by a replica that is no longer alive. It returns just the identifiers (not fullStoredMessagecontent), since the caller only needs them to hand off toSetReplica.SetReplicabulk-reassigns the messages at the givenpositionstonewReplica, guarded byexpectedReplica(optimistic concurrency) so a concurrent takeover/delivery is not clobbered.positionis the global identity PK in every store, so keying on positions alone is unambiguous.Changes
Core/.../Messaging/IMessageStore.cs)InMemoryFunctionStore,PostgreSqlMessageStore,MariaDbMessageStore,SqlServerMessageStore(+ each store'sSqlGenerator). EachGetCrashedReplicaMessagesselects onlyid, positionvia a lightweightReadStoredIdAndPositionsreader.MessageStoreTeststemplate (run against all four stores):CrashedReplicaMessagesAreFetched— only messages owned by crashed replicas are returned.MessageReplicaCanBeReassigned— positions owned by the expected replica are reassigned; one owned by a different replica is left untouched (verifies theexpectedReplicaguard).Testing
GetCrashedReplicaMessages/SetReplicatests pass on all stores: