Add Logical Session & Transaction Management #313
Merged
+1,058
−0
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.
This PR introduces two new modules to PgDog’s frontend: logical session management and logical transaction management. Both aim to enforce correct behavior across a sharded backend without leaking complexity to clients.
LogicalSession
New struct
LogicalSession<'a>tracks allSET-style session variables.Clears and re-fans out variable settings to relevant shards on change.
APIs:
set_variable(name, value)– record a new setting and clear shard sync state.get_variable(name)– fetch current value, if any.sync_shard(shard)/is_shard_synced(shard)– mark/check shard as up-to-date.store_swapped_value/take_swapped_value– stash and retrieve prior shard values.reset/reset_after_take– clear state, returning any swapped values.Complete unit tests covering all methods and edge cases.
LogicalTransaction
New struct
LogicalTransactionenforces one-shard-per-transaction discipline.Tracks lifecycle:
Idle→BeginPending→InProgress→ (Committed/RolledBack).Shard routing:
soft_begin()– start a pending transaction.execute_query(shard)– touch a shard (first statement flips toInProgress).commit()/rollback()– finalize or abort.set_manual_shard(shard)– pin transaction to a specificShard::Direct(n).reset()– clear all state safely at any point.Errors enforce invalid transitions and multi-shard conflicts.
Exhaustive tests for all states, error paths, and shard-conflict rules.
Future improvements
SETfan-outs.Todo
client.in_transaction (bool)withclient.transaction (LogicalTransaction)and follow the compiler.