2394 Adding storage tx lifecyle management to runtime API - #2511
Open
murraystewart96 wants to merge 8 commits into
Open
2394 Adding storage tx lifecyle management to runtime API#2511murraystewart96 wants to merge 8 commits into
murraystewart96 wants to merge 8 commits into
Conversation
Adds private txBegin/txCommit/txRollback/getTx helpers and an openTx struct to core_storage.go. All existing internal callers pass nil to preserve current auto-transaction behaviour. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds openTxs sync.Map, TxBegin/TxCommit/TxRollback methods, and updates StorageRead/Write/Delete to accept an optional *StorageTx via variadic arg. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds openTxs sync.Map, tx_begin/tx_commit/tx_rollback bridge functions, and updates storage_read/write/delete to accept an optional tx handle as a second argument. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds openTxs sync.Map, txBegin/txCommit/txRollback bridge functions, and updates storageRead/Write/Delete to accept an optional tx handle as a second argument. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests cover commit, rollback, and context-cancellation auto-rollback paths using core storage helpers directly. Existing test call sites updated to pass nil for the new tx parameter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
depends on - heroiclabs/nakama-common#226 |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements explicit storage transaction lifecycle management so runtime code can group multiple storage operations into a single atomic database transaction, across Go, Lua, and JavaScript runtimes.
Changes:
- Adds
txBegin/txCommit/txRollbackruntime APIs and plumbing to track open transactions. - Extends storage read/write/delete helpers to accept an optional transaction handle and preserves existing auto-transaction behavior when
nil/unset. - Updates internal server call sites and tests to use the new function signatures and adds transaction lifecycle tests.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| server/core_storage.go | Adds optional pgx.Tx parameter to storage ops and implements tx lifecycle helpers (txBegin/txCommit/txRollback/getTx). |
| server/core_storage_test.go | Updates existing tests for new function signatures and adds coverage for commit/rollback/context-cancel behavior. |
| server/runtime_go_nakama.go | Adds Go runtime tx APIs and optional tx support for storage read/write/delete. |
| server/runtime_lua_nakama.go | Adds Lua runtime tx APIs and optional tx handle parameter for storage read/write/delete. |
| server/runtime_javascript_nakama.go | Adds JS runtime tx APIs and optional tx handle parameter for storage read/write/delete. |
| server/api_storage.go | Updates API server storage calls to pass nil tx for unchanged behavior. |
| server/console_storage.go | Updates console storage calls to pass nil tx for unchanged behavior. |
| server/console_storage_import.go | Updates import paths to pass nil tx for unchanged behavior. |
| server/storage_index.go | Updates storage index reads to pass nil tx for unchanged behavior. |
| server/storage_index_test.go | Updates index tests for new storage function signatures. |
| CHANGELOG.md | Documents the newly added runtime transaction lifecycle APIs and optional tx parameters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add logger to txBegin and warn on rollback failure during context cancellation - Fix conn.Raw error handling: guard against double-send on txReadyCh when BeginTx fails vs conn.Raw failing before invoking the callback - Pass ctx (not context.Background()) to BeginTx so the begin itself respects request cancellation - Guard StorageRead/Write/Delete against multiple tx variadic args and nil/empty tx IDs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…egin doc. JS storageRead, storageWrite, and storageDelete were missing @PARAM tx entries. Lua txBegin incorrectly referenced storage_read_tx/write_tx/delete_tx which no longer exist; updated to reference storage_read, storage_write, storage_delete. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eDelete. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
#2394
Implement storage transaction lifecycle across Go, Lua, and JavaScript runtimes
When writing complex RPCs it's often necessary to group multiple storage operations into a single atomic transaction. Previously the storage APIs each managed their own transaction internally, making this impossible.
This adds txBegin/txCommit/txRollback functions to all three runtimes (Go, Lua, JS) and updates storageRead, storageWrite, and storageDelete to accept an optional transaction handle.
All existing call sites are unchanged in behaviour — they pass nil and continue using the internal auto-transaction path.