Skip to content

fix(control): native gateway session txn_id for in-txn SQL reads#182

Merged
farhan-syah merged 2 commits into
NodeDB-Lab:mainfrom
pizofreude:fix/native-gateway-txn-overlay
Jul 16, 2026
Merged

fix(control): native gateway session txn_id for in-txn SQL reads#182
farhan-syah merged 2 commits into
NodeDB-Lab:mainfrom
pizofreude:fix/native-gateway-txn-overlay

Conversation

@pizofreude

Copy link
Copy Markdown
Member

What & why

Two small Control Plane fixes so native-protocol transactions stage and read correctly when dispatch goes through the gateway.

  1. fix(control): ensure native session on first-frame OpCode::Begin

    • OpCode::Begin as the first post-handshake frame could no-op: SessionStore::begin only mutates an existing session entry, and SQL-path ensure_session had not run yet.
    • Call sessions.ensure_session at the top of handle_begin (SQL BEGIN already ensures the session in sql.rs before calling here).
  2. fix(control): thread session txn_id through gateway local dispatch

    • Native SQL / direct-op reads inside an explicit transaction build a gateway QueryContext and call Gateway::execute.
    • The gateway previously hard-coded txn_id: None into DispatchRouteParams, and local dispatch used the txn-less SPSC path, so the Data Plane never resolved the per-transaction staging overlay.
    • Add QueryContext.txn_id, pass it into dispatch, and use dispatch_to_data_plane_with_txn for local routes. Native seams that hold a session txn stamp it; autocommit / system callers keep None.

This is the tip-based follow-up after closing #176 (obsolete wire groundwork). No WIRE_VERSION bumpExecuteRequest.txn_id already exists on main. No internal roadmap labels in source or tests.

How to test

cargo test -p nodedb --test native_gateway_txn_overlay
cargo test -p nodedb --test native_transactions_staging --test native_direct_op_txn_overlay
cargo fmt --all --check
cargo clippy -p nodedb --all-targets --all-features -- -D warnings

Locally verified: both new tests green; staging + direct-op overlay suites green; cargo check -p nodedb --lib and clippy -D warnings clean.

Tradeoffs / alternatives considered

  • Did not reopen feat(control): native SQL in-txn read-your-own-writes (U3) + cross-cluster txn_id groundwork #176 — that branch was 160+ commits behind and mixed a wire bump for an inert field with the useful single-node fixes.
  • Out of scope: materializing staged overlays on remote nodes for cross-node in-txn reads. This PR makes the gateway carry txn_id locally (and on the remote RPC field when present); full cross-node overlay reachability is separate work.
  • Streaming path receives task.txn_id on the context for consistency; execute_stream still does not fully consume session overlays end-to-end (same as prior streaming gap).

Notes for review

  • Control Plane only; plane separation unchanged.
  • Behavior-named tests only (native_first_frame_begin_buffers_following_write, native_in_txn_sql_select_reads_own_write).
  • Please add the run-ci label if CI is still opt-in.

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.
@farhan-syah
farhan-syah merged commit fd0c7da into NodeDB-Lab:main Jul 16, 2026
@pizofreude
pizofreude deleted the fix/native-gateway-txn-overlay branch July 16, 2026 13:35
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.

2 participants