feat: Add module lifecycle reducer#5487
Open
ritankarsaha wants to merge 1 commit into
Open
Conversation
Collaborator
|
Hi @ritankarsaha, what's the motivation for adding this reducer? |
Author
This is in context to an issue #5480 which mentions for a similar reducer during teardown. |
Author
Could you point me to more issues requiring attention? Do you guys have any community meet? @bfops |
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.
Description of Changes
Fixes #5480
Adds a
stopmodule lifecycle reducer, the symmetric counterpart toinit, invoked exactly once immediately before a database is permanently destroyed viaspacetime deleteor a reset. It does not fire on an ordinary module update/hot-reload or on replica scale-down, since the database's data survives both, and it's best-effort: a failing, trapping, or slowstopreducer is logged but never blocks the deletion it precedes.Implemented via
#[reducer(stop)](Rust),ReducerKind.Stop(C#), andspacetime.stop()(TypeScript). Core changes: newLifecycle::Stopvariant,ModuleHost::call_module_stop(wired through both the WASM and V8/JS instance paths), and a newis_final_teardownflag onHostController::exit_module_host, set only by the standalone control plane'sdelete_database/reset_databasepaths (not replica scale-down/decommission).Adds a
module-test-stopfixture module and an integration test verifyingstopfires exactly once on deletion and not on update.API and ABI breaking changes
None. This is a purely additive change: a new
Lifecycleenum variant and a new reducer-kind/attribute surface in each binding. No existing behavior changes for modules that don't declare astopreducer.Expected complexity level and risk
2.5 - touches the module lifecycle/shutdown path in
crates/core/src/hostThe main risk surface is theis_final_teardownthreading throughcrates/standalone/src/lib.rs's fourdelete_replicacall sites — getting one of those wrong could either misfirestopon routine replica scale-down or silently skip it on real deletion.Testing
cargo test -p spacetimedb-schema— new duplicate-lifecycle tests forStop(v9 + v10)cargo fmt --checkandcargo clippy -D warningsclean onspacetimedb-lib,spacetimedb-schema,spacetimedb-core,spacetimedb-standalone,spacetimedb-bindings-macro,spacetimedb,spacetimedb-testingtest_stop_reducer_fires_only_on_deletionagainst a real compiled module, confirmingstopdoes not fire on update and fires exactly once on deletiontsc --noEmit,eslint, andprettier --checkall clean; fullvitestsuite (232/232) passesstop, confirm no fire acrossspacetime publish, exactly one fire onspacetime delete, and rejection on a directspacetime call <module> stop