Skip to content

Comments

Async shutdown for database / durability#3880

Merged
kim merged 9 commits intomasterfrom
kim/db-shutdown
Dec 17, 2025
Merged

Async shutdown for database / durability#3880
kim merged 9 commits intomasterfrom
kim/db-shutdown

Conversation

@kim
Copy link
Contributor

@kim kim commented Dec 15, 2025

Controlled shutdown of a database should drain the outstanding transactions
queue(s) and flush them to the durability layer.

With the introduction of another queueing layer in #3868, it became harder to
observe when or if this process is completed.

This patch thus introduces an explicit (async) shutdown method for
RelationalDB and below, which will wait until all submitted transactions are
either reported durable, or an error occurs in the durability layer.

RelationalDB is made !Clone, such that shutdown can be initiated in the
Drop impl. Note that this requires access to a tokio runtime, which we thread
through via the Persistence services in order to allow control over which of
the various runtimes is being used for durability-related tasks.

Also moves RelationalDB::open to a blocking thread when a persistence-enabled
database is constructed by the HostController -- this process performs heavy
I/O and can take a substantial amount of time, during which we don't want to
block a worker thread.

API and ABI breaking changes

None

Expected complexity level and risk

3

Testing

  • some testing added
  • existing tests still pass
  • impl Drop for RelationalDB difficult to test, extra eyeballs needed

@kim
Copy link
Contributor Author

kim commented Dec 15, 2025

Merging also merges #3868

@kim kim requested a review from Centril December 15, 2025 12:30
Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

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

Looks good, just some minor stuff.

@bfops bfops added the release-any To be landed in any release window label Dec 15, 2025
@kim kim enabled auto-merge December 17, 2025 18:28
@kim kim added this pull request to the merge queue Dec 17, 2025
Merged via the queue into master with commit e2b4113 Dec 17, 2025
37 of 42 checks passed
KirstenWF pushed a commit to KirstenWF/SpacetimeDB that referenced this pull request Dec 17, 2025
Controlled shutdown of a database should drain the outstanding
transactions
queue(s) and flush them to the durability layer.

With the introduction of another queueing layer in clockworklabs#3868, it became
harder to
observe when or if this process is completed.

This patch thus introduces an explicit (async) shutdown method for
`RelationalDB` and below, which will wait until all submitted
transactions are
either reported durable, or an error occurs in the durability layer.

`RelationalDB` is made `!Clone`, such that shutdown can be initiated in
the
`Drop` impl. Note that this requires access to a tokio runtime, which we
thread
through via the `Persistence` services in order to allow control over
which of
the various runtimes is being used for durability-related tasks.

Also moves `RelationalDB::open` to a blocking thread when a
persistence-enabled
database is constructed by the `HostController` -- this process performs
heavy
I/O and can take a substantial amount of time, during which we don't
want to
block a worker thread.

# API and ABI breaking changes

None

# Expected complexity level and risk

3

# Testing

- [ ] some testing added
- [ ] existing tests still pass
- [ ] `impl Drop for RelationalDB` difficult to test, extra eyeballs
needed

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
@kim kim deleted the kim/db-shutdown branch January 9, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants