Skip to content

2394 Adding storage tx lifecyle management to runtime API - #2511

Open
murraystewart96 wants to merge 8 commits into
heroiclabs:masterfrom
murraystewart96:2394-adding-storage-txs-to-runtime
Open

2394 Adding storage tx lifecyle management to runtime API#2511
murraystewart96 wants to merge 8 commits into
heroiclabs:masterfrom
murraystewart96:2394-adding-storage-txs-to-runtime

Conversation

@murraystewart96

Copy link
Copy Markdown

#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.

murraystewart96 and others added 5 commits June 5, 2026 22:34
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>
@CLAassistant

CLAassistant commented Jun 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@murraystewart96

Copy link
Copy Markdown
Author

depends on - heroiclabs/nakama-common#226

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/txRollback runtime 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.

Comment thread server/core_storage.go
Comment thread server/core_storage.go
Comment thread server/core_storage.go Outdated
Comment thread server/runtime_go_nakama.go
Comment thread server/runtime_go_nakama.go
Comment thread server/runtime_go_nakama.go
Comment thread server/runtime_lua_nakama.go
Comment thread server/runtime_go_nakama.go
Comment thread server/runtime_go_nakama.go
Comment thread server/runtime_go_nakama.go
murraystewart96 and others added 3 commits June 10, 2026 16:00
- 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>
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.

3 participants