Commit Graph

53 Commits

Author SHA1 Message Date
Kim Altintop e2b4113ffb Async shutdown for database / durability (#3880)
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

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-12-17 18:28:42 +00:00
Kim Altintop 310d8eb7ae [teams 4/5] SQL authorization (#3525)
Permissions for evaluating SQL/DML are not generally "actions", but more
a set of permissions that are checked during evaluation.

To make this work with the teams feature, this patch extends `AuthCtx`
to allow checking a set of permissions as mandated by the spec. This set
is a bit more fine-grained than "is owner", so as to avoid baking in the
concept of teams/collaborators, or assumptions about what a role might
entail. Both are likely to evolve in the future, so evaluation of
permissions / capabilities should be confined to the impl of the
`Authorization` trait.

Unlike "actions", the `AuthCtx` must be able to evaluate permission
checks quickly and without side-effects, nor can it enter an `async`
context. In that sense, it is precomputed (if you will), and stored as a
closure in the `AuthCtx` for external authorization.

A challenge posed is how to thread through the constructed `AuthCtx` for
subscriptions.

A tempting approach would have been to equip the `HostController` with
the ability to summon an `AuthCtx`. That, however, would have created a
gnarly circular dependency, because the `HostController` also controls
the controldb, which itself demands an `AuthCtx`.

Instead, the `AuthCtx` is obtained in the endpoint handler and passed to
each method call that requires one. That's less pretty, but more
effective.

---------

Signed-off-by: Kim Altintop <kim@eagain.io>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2025-11-11 20:19:16 +00:00
Jeffrey Dallatezza dbc49b1fd6 Add AuthCtx to ReducerContext for rust (#3288)
# Description of Changes

This exposes client credentials in reducer calls for rust.

# API and ABI breaking changes

API Changes:

The main API change is the addition of `AuthCtx` and the `sender_auth`
in `ReducerContext`. This also adds JwtClaims, which has some helpers
for getting commonly used claims.

ABI Changes:

This adds one new functions `get_jwt`. This uses
`st_connection_credentials` to look up the credentials associated with a
connection id.

This adds ABI version 10.2.

# Expected complexity level and risk

2. This adds new ABI functions

# Testing

I've done some manual testing with modified versions of the quickstart.
We should add some examples that use the new API.
2025-10-17 21:03:54 +00:00
Zeke Foppa f6f0909ea4 Update all licenses (#3002)
# Description of Changes

We recently merged several repos together. This PR clarifies the license
terms for several subdirectories, as well as the relationship between
the licenses.

The licenses in our subdirectories have become symbolic links to
licenses in our toplevel `licenses` directory. For any particular
subdirectory's license file in the diff, you can click `... -> View
file` and then click on the text that says "Symbolic Link" on that page.
This will take you to the license file that it links to.

I have also updated the `tools/upgrade-version` script to update the
change date in the new `licenses/BSL.txt` file.

# API and ABI breaking changes

None.

# Expected complexity level and risk

1

# Testing

None. Only changes to license files.

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2025-08-12 18:20:58 +00:00
Noa 742303ca49 Bump rust-toolchain to rust 1.88 (#2749)
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-07-15 17:39:41 +00:00
Phoebe Goldman 6a9b524b4e Enable the datastore crate's test feature where necessary (#2937) 2025-07-14 18:29:21 +00:00
Tyler Cloutier 20b087c248 Split datastore into its own crate (#2933) 2025-07-12 21:41:00 +00:00
Viktor Szépe f6da9e1f5f Fix typos (#2812)
Signed-off-by: Viktor Szépe <viktor@szepe.net>
2025-06-04 16:33:32 +00:00
Phoebe Goldman 1e50c7d8ad Aggregate and broadcast DbUpdates off the main thread (#2793)
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-05-28 17:10:48 +00:00
Mazdak Farrokhzad 05e171ccec Cache with_label_values more & don't do metrics while holding lock (#2734) 2025-05-21 14:11:41 +00:00
Mario Montoya f9f38543c8 Add readmes to all implementation crates specifying that they do no offer stable interfaces (#2320) 2025-03-06 19:50:17 +00:00
joshua-spacetime f0361525bd Error handling for incremental evaluation (#2223) 2025-02-07 23:31:27 +00:00
Mario Montoya 17423a4cf0 Add missing LICENSE (#1960) 2024-11-07 22:33:15 +00:00
Mario Montoya a6a6c4f08f Put ExecutionContext inside the Tx context (#1876)
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2024-10-29 16:24:06 +00:00
Mazdak Farrokhzad 06cc688885 No Maps for you! (#1770) 2024-10-15 22:34:13 +00:00
joshua-spacetime a15f60bfbc feat: Integrate type checking into current query code (#1756) 2024-09-30 21:27:56 +00:00
Mazdak Farrokhzad 1e8e18d74b Add support for I256 and U256 (#1477) 2024-08-08 18:40:35 +00:00
Mazdak Farrokhzad 3340ceea8a SATS: Flatten AlgebraicType, getting rid of BuiltinType (#1559)
Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: joshua-spacetime <josh@clockworklabs.io>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2024-08-06 18:15:19 +00:00
Jeremie Pelletier da23401368 Jeremie/notify sql (#1198)
* Notify subscriptions from SQL code path

* Remove blocking_broadcast_event

(From another PR, but helps tests to pass)

* Update from review

* Update from rebase

* cargo fmt

* cargo fmt

* cargo fmt

* update space.rs
2024-06-03 22:51:05 +00:00
Mario Montoya 7d5eb1532d Slow query log (#1052)
* Slow query log

* Addressing some PR comments
2024-04-17 13:53:55 +00:00
Mazdak Farrokhzad d6815ebf9c Shrink AV and AT to 24 & 16 bytes respectively, and also friends. (#1047) 2024-04-13 16:51:18 +00:00
Kim Altintop 47048559b4 core: Integrate new commitlog + durability (#926)
This patch attempts to integrate the new commitlog with the minimum
changes.

Most of the diff comes from deletions of the legacy log and the need to
adjust tests due to the requirement for a tokio runtime when a durable
database is used in tests.

The "meat" of the patch are the `RelationalDB` constructors,
`RelationalDB::commit_tx`, and the replay logic in
`locking_tx_datastore`.

While `DataKey` is gone, there is still some redundant data being passed
around, which will be addressed in the follow-up patch.
2024-04-11 22:46:31 +00:00
Mazdak Farrokhzad 3f425a9483 fix: Optimize query plan in iter_filtered_chunks (#939)
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2024-03-16 07:21:49 +00:00
Mazdak Farrokhzad 913801e22a - Make RelValue into a cow-like structure. (#869)
- Move it and friends from sats to vm.
- MemTable now stores a Vec<PV>.
- Other related improvements.

Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-02-21 20:07:39 +00:00
Noa b4f75d272f Bump Rust to 1.76.0 (#811)
* Bump Rust to 1.76.0

* Fix new clippy lints

* Use rust-toolchain in smoketests
2024-02-09 19:40:03 +00:00
Noa 37658aae7e Add rust-version to Cargo.toml (#802)
* Add rust-version to Cargo.toml

* Use workspace inheritance to make bumping the spacetime version easier
2024-02-07 20:02:05 +00:00
John Detter d67c1db901 Cleanup SpacetimeDB name usages (#744)
* Small naming fix

* Fixed all instances of misspelled SpacetimeDB

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-23 18:21:10 +00:00
Shubham Mishra e152784c3b feat: subscription to use read type tx (#685)
* made MutTxId -> MutTx

* adopt using ass. type for tx

* fmt

* read tx in datastore

lint

test

lint

made MutTxId -> MutTx

adopt using ass. type for tx

fmt

added more methods to TxId

fix test

Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Shubham Mishra <shivam828787@gmail.com>

comments on Test

Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Shubham Mishra <shivam828787@gmail.com>

fmt

typo

* fix imports

* clippy

* read tx in datastore

lint

test

lint

added read tx in subs

fmt

fix iters

* comments

* comments

* fix schema_for_table

* fmt

* merge queue helped

* moved all_read_query anaylyzing to vm

* lint

* added StateView trait

* lint

* fix tests for read-tx-in-subs (#695)

Intention of this PR is to keep diff of main PR smaller - feat: subscription to use read type tx #685 by separating trivial unit test related changes from main logic.
naming changes begin_tx() -> begin_mut_tx() and begin_read_tx() -> begin_tx()

* rollback_tx -> release_tx

* Compiler should work with Write Tx

* execute sql with mut tx

* fix result len

* compiler to work with write tx (#716)

* Compiler should work with Write Tx

* merge queue helped
2024-01-21 19:59:26 +00:00
John Detter 8524d244f3 Version upgrade to 0.8.1 (#729)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-18 18:16:58 +00:00
joshua-spacetime fd6a5cecef refactor(query): Remove query string as metrics label (#721)
The purpose of this is to reduce high cardinality query metrics.
2024-01-13 01:43:01 +00:00
John Detter 79ff6dffc6 Version upgrade to 0.8.0 (#622)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-12-04 13:19:25 -06:00
james gilles 419cfca8b8 Add spacetimedb::sql::query_debug_info::QueryDebugInfo (#560)
Add spacetimedb::sql::query_debug_info::QueryDebugInfo

---------

Signed-off-by: james gilles <jameshgilles@gmail.com>
2023-11-21 22:09:04 +00:00
Mario Montoya f12a238237 Moving object defs to SATS (#460)
* Moving object defs to SATS

* move ColumnIndexAttribute to primitives, nix path attr

* revert unnecessary reformating

* ProductValue: don't take ColId
ProductValues can be more than rows and can be nested

* simplify sats::db::def wrt. Constraints + impl ser/de

* cargo fmt

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2023-11-13 12:21:56 +00:00
John Detter dff23de939 Version upgrade to v0.7.3 (#536)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2023-11-07 21:55:14 -06:00
joshua-spacetime 23b2e6c713 perf(461): Record metrics for rows [inserted|deleted] on commit (#462)
Closes #456.
Closes #461.

Define an execution context for database operations.
Store the database id in RelationalDB.
Record metrics for rows [inserted|deleted] on commit.
2023-10-25 15:28:26 -07:00
Noa bc54b735b5 Update/upgrade dependencies (#266)
* Update and dedup some deps

* Upgrade dependencies
2023-10-25 01:19:29 +01:00
Mazdak Farrokhzad 1168b61939 1. change fmt & map notation (#405)
2. refer less to BuiltinType
2023-10-11 15:46:56 +00:00
Mazdak Farrokhzad ff69ec4a10 flatten BuiltinValue into AlgebraicValue (#389) 2023-10-09 18:58:52 +02:00
Mazdak Farrokhzad a45c30c3d9 sats: misc refactoring (#382)
- more conversions
- prepare for getting rid of BuiltinValue & BuiltinType
- prepare for slim slices
2023-10-08 02:05:25 +02:00
Phoebe Goldman fca7c27946 Clippy: forbid println and friends (#305)
We've had recurring issues with `println` calls sneaking in
where `log` crate macros would be more appropriate.
This commit adds a Clippy warning for uses of the global I/O macros,
i.e. `print`, `println`, `eprint`, `eprintln` and `dbg`.

The lint is disabled by a more-specific `clippy.toml` in the `cli` and `sqltest` crates,
as well as using `allow` attributes in `standalone`'s `subscommands` module.

Additionally, this commit converts a handful of prints in `core/utils` to `log::info`.
2023-09-20 13:24:26 -04:00
Mazdak Farrokhzad 12a7e7f572 use derive_more::From (#281) 2023-09-13 11:40:23 +00:00
joshua-spacetime cc36a2e87c perf: read DataKey instead of recomputing it in subscriptions (#276)
Fixes #259 

(1) Updates MemTable to use RelValue instead of ProductValue
(2) Adds a DataKey member to DataRef and RelValue
(3) Subscriptions compute DataKey only when not present on row
2023-09-12 15:16:09 -07:00
joshua-spacetime 987b0091f8 Revert "perf: subscriptions compute DataKey only when not present with row (#268)" (#274)
This reverts commit a328108a5e.
2023-09-11 19:08:27 +00:00
joshua-spacetime a328108a5e perf: subscriptions compute DataKey only when not present with row (#268)
Fixes #259 

(1) Updates MemTable to use RelValue instead of ProductValue
(2) Adds a DataKey member to DataRef and RelValue
(3) Subscriptions compute DataKey only when not present on row
2023-09-08 15:39:24 -07:00
joshua-spacetime e72b8f3d1b perf(datastore): disable fsync mode by default (#221) 2023-08-23 18:22:53 -07:00
Mario Montoya 80a0a29704 Move cargo deps to the workspace (#172)
* Moving deps to workspace

* Merge
2023-08-11 15:24:31 -07:00
George Kulakowski 26c49f2571 Allow spacetimedb to run in an in-memory mode (#137)
* Allow spacetimedb to run in an in-memory mode

* cargo fmt and review comments

* Fix test code

* Ensure the db directory is always created
2023-08-04 10:56:57 -07:00
Mazdak Farrokhzad d5b37e9c90 Document + Refactor SATS (#66)
* Document most of SATS

* sats: simplify Serialize impls

* sats: simplify Deserialize impls

* improve sats::de docs

* document sats::bsatn

* simplify sats fmt/map notation

* value serializer: docs + opt

* docs/refactor sats::algebraic_value::{ser,de}

* sats: document serde conversions

* cargo fmt

* small fixes

* fix tests

* fix serde feature

* sats: address pheobe's review

* fix doc comment

* fix test failure

* Remove unusued import

* Fix a borrowing issue introduced by the merge of master

The definitions of these were tweaked in some way, I think,
such that references to them are no longer automatically 'static?

---------

Co-authored-by: George Kulakowski <george@clockworklabs.io>
2023-08-01 23:17:03 +02:00
Mario Montoya 300e9050a1 Remove implicit transactions and thread the Tx instead (#65)
* Remove implicit transactions and thread the Tx instead

* Split logic for proper Tx handling
2023-08-01 23:17:03 +02:00
Mario Montoya c154e3a6df Private tables (#17)
* Initial bootstrap for private tables

* Separate Access (private, public) for kind o table (system, user)

* Validates the access to private tables

* Check auth for drop table
2023-08-01 23:17:02 +02:00