Repository navigation
fix(msg): keep read sequences monotonic across devices - #3820
Open
John-Funcity wants to merge 1 commit into
Open
John-Funcity wants to merge 1 commit into
John-Funcity wants to merge 1 commit into
Conversation
John-Funcity
requested review from
FGadvancer,
skiffer-git and
withchao
as code owners
October 19, 2026 07:36
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
This branch has not been deployed
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.
Concurrent read reports from two devices can both pass the read-before-write check and then move
hasReadSeqbackwards. A delayed MongoDB cache fill or a bulk read update can also overwrite a newer Redis value, causing already-read messages to appear unread again.This change makes read progress monotonic per user and conversation:
read_seqwith MongoDB$max, enforce a unique user/conversation index, and retry concurrent duplicate-key upserts against the existing row. Other sequence fields retain their$setsemantics.Validation:
go test -mod=readonly -race ./pkg/common/storage/cache/redis ./pkg/common/storage/database/mgo ./pkg/common/storage/controller ./internal/rpc/msg -run '^TestReadSeq' -count=1 -timeout=90s.go build -mod=readonly ./...andgit diff --check.Rollout: resolve any existing duplicate
seq_userrows before deploying. Startup createsuser_conversation_unique; it does not delete or merge historical data. The index can coexist with the old non-unique index on MongoDB 5.0+; reconcile any manually installed equivalent unique index names beforehand. See rollout notes.The existing in-memory notification queue and MQ architecture are preserved. Reliable delivery/compensation for lost persistence events and reconciliation of existing Redis/MongoDB differences are outside this change.