Unify vector selector queries #1276
Merged
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.
Unify vector selector queries by updating
DBBasedCursorUpdater.readto usequeries.SelectVectorClockand mapOriginatorNodeIDtoOriginatorSequenceIDThe cursor updater switches to the vector clock query and aligns sequence mapping to originator values, and the SQL layer removes the latest cursor query while changing sequence selection to read from the latest table via
COALESCE.DBBasedCursorUpdater.readto callqueries.SelectVectorClockand mapOriginatorNodeIDtoOriginatorSequenceIDin cursor_updater.goGetLatestCursornamed query and generated accessors in envelopes.sql.goGetLatestSequenceIdtoCOALESCE((SELECT originator_sequence_id FROM gateway_envelopes_latest WHERE originator_node_id = @originator_node_id), 0)::BIGINTin envelopes.sql📍Where to Start
Start with
DBBasedCursorUpdater.readin cursor_updater.go to see the switch toqueries.SelectVectorClockand the updated node-to-sequence mapping.📊 Macroscope summarized 4994e4d. 1 file reviewed, 2 issues evaluated, 2 issues filtered, 0 comments posted
🗂️ Filtered Issues
pkg/api/metadata/cursor_updater.go — 0 comments posted, 2 evaluated, 2 filtered
cu.storeis nil.read()callsqueries.New(cu.store).SelectVectorClock(cu.ctx)(line 93). If the*sql.DBpassed toNewCursorUpdaterwas nil,queries.Newstores a nil DBTX, andSelectVectorClockwill invokeq.db.QueryContext(...)on a nil receiver, which will panic at runtime. There is no guard inNewCursorUpdaterorread()to prevent this. Add a nil check onstoreat construction or before invoking the query and return an error if nil. [ Low confidence ]GetLatestCursortoSelectVectorClock, and the mapped field fromrow.MaxSequenceIDtorow.OriginatorSequenceID(line 100). If these two queries/fields are not semantically equivalent (e.g.,GetLatestCursorreturned a per-node maximum andSelectVectorClockreturns something else or has different grouping/ordering), the computed cursor may change, potentially causing missed or extra subscriber notifications or an incorrect cursor state. Verify thatSelectVectorClockreturns exactly one record perOriginatorNodeIDwith the correct latest sequence and thatOriginatorSequenceIDis the intended value. If not, adapt the mapping or query to preserve the previous externally visible behavior. [ Low confidence ]