fix(control): native gateway session txn_id for in-txn SQL reads#182
Merged
farhan-syah merged 2 commits intoJul 16, 2026
Merged
Conversation
OpCode::Begin can arrive before any SQL statement has called ensure_session. SessionStore::begin no-ops when the peer has no entry, so the following write autocommitted instead of entering InBlock. Ensure the session exists at the top of handle_begin (SQL BEGIN already does this in sql.rs before calling here). Guarded by native_first_frame_begin_buffers_following_write.
Native SQL and direct-op reads inside an explicit transaction route through Gateway::execute, which previously hard-coded txn_id: None into DispatchRouteParams and used the txn-less local SPSC path. The Data Plane staging overlay was never resolved, so in-transaction SELECTs could not see their own staged writes. - Add QueryContext.txn_id - Pass it into DispatchRouteParams for local and remote routes - dispatch_local uses dispatch_to_data_plane_with_txn - Native sql_gateway/direct_ops/streaming stamp the session task txn_id - Autocommit and system callers keep None (compile-driven field fill) No wire version bump; ExecuteRequest.txn_id already exists on main. Guarded by native_in_txn_sql_select_reads_own_write and native_first_frame_begin_buffers_following_write.
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.
What & why
Two small Control Plane fixes so native-protocol transactions stage and read correctly when dispatch goes through the gateway.
fix(control): ensure native session on first-frame OpCode::BeginOpCode::Beginas the first post-handshake frame could no-op:SessionStore::beginonly mutates an existing session entry, and SQL-pathensure_sessionhad not run yet.sessions.ensure_sessionat the top ofhandle_begin(SQLBEGINalready ensures the session insql.rsbefore calling here).fix(control): thread session txn_id through gateway local dispatchQueryContextand callGateway::execute.txn_id: NoneintoDispatchRouteParams, and local dispatch used the txn-less SPSC path, so the Data Plane never resolved the per-transaction staging overlay.QueryContext.txn_id, pass it into dispatch, and usedispatch_to_data_plane_with_txnfor local routes. Native seams that hold a session txn stamp it; autocommit / system callers keepNone.This is the tip-based follow-up after closing #176 (obsolete wire groundwork). No
WIRE_VERSIONbump —ExecuteRequest.txn_idalready exists on main. No internal roadmap labels in source or tests.How to test
Locally verified: both new tests green; staging + direct-op overlay suites green;
cargo check -p nodedb --liband clippy-D warningsclean.Tradeoffs / alternatives considered
txn_idlocally (and on the remote RPC field when present); full cross-node overlay reachability is separate work.task.txn_idon the context for consistency;execute_streamstill does not fully consume session overlays end-to-end (same as prior streaming gap).Notes for review
native_first_frame_begin_buffers_following_write,native_in_txn_sql_select_reads_own_write).run-cilabel if CI is still opt-in.