Commit Graph

3186 Commits

Author SHA1 Message Date
joshua-spacetime 2c9ad210c8 fix: Put query metrics behind feature flag (#784)
A call site for record_query_duration_metrics was missed in #749.
2024-02-02 17:45:37 +00:00
Zeke Foppa 3429ce647b applyfix (#783) 2024-02-02 17:19:38 +00:00
Shubham Mishra db87b21cb0 oneshot to receive feedback (#776) 2024-02-01 19:48:28 +00:00
Mazdak Farrokhzad b336fba700 Integrate mem arch into locking_tx_datastore (#769)
* datastore: impl mem arch using spacetimedb_table

* instance_env/iters: write bflatn -> bsatn directly

* Make tests build, fix 1 failure (of 4)

Commit message from SpacetimeDBPrivate 0ae26519d181cb4b13f748af53d036c322d4f642:

Bug fix in `delete_by_rel`: don't trigger unique constraints in dummy insert

Prior to this commit, `MutTxId::delete_by_rel` on a table with a unique constraint
would fail, because the `delete_by_rel` would attempt an insert of the row to be deleted,
with the intention of rolling back the insertion later.
This would trigger the unique constraint, aborting the `delete_by_rel`,
and the actual row would not be deleted.

With this commit, `MutTxId::delete_by_rel` properly uses
`Table::insert_internal_allow_duplicate` and `Table::delete_internal_skip_pointer_map`
to bypass unique constraints.
This requires exporting some methods from `Table` which were previously internal.

* Remove forgotten `dbg`

* `bflatn_to`: panic rather than UB on an ill-typed `ProductValue`

The docs in `bflatn_to.rs` claim that we'll panic
if the `ProductValue` passed to `write_row_to_pages`
does not conform to the type.

Prior to this commit, we would panic if some element of the `val`
had a different type constructor than the corresponding element of the `ty`,
but for `ProductValue`, we would not panic if the value had more or fewer elements
than the type.
When the value had more elements, this was merely a logic bug;
we'd drop the tail elements and go about our lives.
When the value had fewer elements, this invoked UB;
we'd leave the remainder of the row in the page uninit,
and later access uninitialized memory e.g. when hashing the row.

This commit adds a check that in `write_product`
that the `val` and `ty` have the same length.
If they do not, this commit panics.
This will need to be revised to return an `Err`, as spacetimedb-core has tests
that attempting to insert an ill-typed value returns an `Err` rather than panicking.

* Error handling, runtime schema mutations

This commit makes two sorts of changes:

- It begins filling in the error-handling story of the new mem-arch
  by defining a few new error enums in the `spacetimedb-table` crate,
  and converting them into `TableError` in `spacetimedb-core`.
- It implements `drop_table`, `rename_table` and friends to mutate a schema at runtime.
  These operations are broken in master in that they violate transactionality,
  and they're broken here too.

* Re-enable metrics

* Resolve some TODOs, incl. error type in `page.rs`

* Fixes for Tyler's comments

- Restrict some `pub` to `pub(crate)`
- Rename `MutTxId::delete_by_rel` to `delete_by_row_value`, since it deletes only one row.
- `relations` -> `relation`.
- Rename `ignore_duplicate_insert` -> `ignore_duplicate_insert_error` and add docs.
- nix `with_table_*` methods in favor of imperative `get_table_*`.

* Note correctness of `state_view::Iter` and add test in `relational_db`.

Tyler had concerns about the behavior of `state_view::Iter`
w.r.t. the edge case of a committed-deleted-inserted row,
since the new datastore maintains the invariant that
the committed and inserted tables are disjoint,
where the previous datastore did not.

This commit adds comments describing that invariant to the iterator,
and adds a test in `relational_db` that the external semantics are preserved.

* Add notes for future MVCC implementors re: disjoint committed and insert tables

Tyler convinced me via video call that, in MVCC, it is no longer valid
to treat the committed and insert tables as disjoint,
i.e. to elide inserts of already-present rows.

Doing so is still valid, and is more performant, in the current locking model,
so we retain that behavior here.

This commit adds comments to relevant code paths so that, when we move to MVCC,
we do not forget to remove the optimization.

---------

Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-02-01 19:43:17 +00:00
Noa a58bfd4071 Use rayon for broadcast_commit_event (#779)
* Use rayon for broadcast_commit_event

* Don't short-circuit on error
2024-01-31 03:36:41 +00:00
Kim Altintop e67fe0936e core: Lock unwritten_commit across I/O (#775)
A database may continue to write to the log after a previous write
failed (due to an I/O error). At that point, offsets have already been
updated, which results in gaps in the offset sequence (which we can't
tolerate currently).

To fix this, the lock on `unwritten_commit` is acquired and held across
the write to the log segment. Only after that succeeded, offsets and
parent hash are updated.
2024-01-29 22:23:05 +00:00
Mazdak Farrokhzad 097937bb0e pointers_yielded -> num_pointers_yielded (#773) 2024-01-28 09:20:04 +00:00
Mazdak Farrokhzad 145e588c36 Split old datastore more (#770)
* 1. sort some `Cargo.toml`s
2. expose 'pointers_yielded'
3. move SequenceError

* datastore: TxId -> tx.rs

* datastore: extract datastore.rs

* fix test imports
2024-01-28 04:14:49 +00:00
Tyler Cloutier ecd366e266 Fixed issue with perfcnt not working on certain platforms and architectures (#768)
* Fixed issue with perfcnt not working on certain platforms and architectures

* Update var_len_visitor.rs
2024-01-27 10:06:52 +00:00
joshua-spacetime 5df73e89e7 feat(748): Add compile time feature flag for db metrics (#749)
Closes #748.

This patch adds a temporary feature flag for enabling db metrics.

Metrics are recorded synchronously at the moment.
This can have a noticable impact on latency.

Compiling with this flag will enable metrics collection.
This new flag will be turned on by default.
Hence metrics will be collected by default.

Note this flag is temporary.
It will be removed once metrics are recorded async.
2024-01-27 01:33:26 +00:00
Mazdak Farrokhzad e395e4ee30 spacetimedb_table: nix spacetimedb-core dep (#767)
Readd `BTreeIndex::name` to report unique constraint violations on sys tables.
Add a unique_violation_test
2024-01-26 21:44:50 +00:00
joshua-spacetime 475924de59 perf(759): Track the number of active subscription queries (#760)
Closes #759.
2024-01-26 19:28:27 +00:00
Mazdak Farrokhzad 343e8ec5f1 Add the spacetimedb_table crate (#763)
* add spacetimedb-table crate

* pacify clippy
2024-01-26 17:05:04 +00:00
John Detter cc733d92c4 Fix more broken links (#762)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-26 09:29:42 -06:00
John Detter 1ba7eabfeb Fixed broken quickstart links in readme (#761)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-26 09:10:12 -06:00
Mazdak Farrokhzad 5307f255ab Split the old locking_tx_datastore (#757)
* datastore: extract SequencesState

* datastore: extract tx_state

* datastore: extract committed_state & iter

* datastore: extract mut_tx

* cargo fmt

* move some pure AV/AT sats logic to sats

* pacify lints and cargo fmt

* datastore: iter -> state_view + move in StateView
2024-01-25 20:23:05 +00:00
Shubham Mishra c80cd359e2 made subscription broadcast multithreaded (#741)
added type alias for Subscription Vec

fix tx init  seq

parallelising incr eval

lint

remove uneccessary _arc()
2024-01-25 20:06:00 +00:00
Mazdak Farrokhzad 13a637b5d6 fix some bugs in concat_byte_chunks, serialize_bsatn (#755) 2024-01-25 14:17:04 +00:00
james gilles 72f1550453 Check benchmarks on CI + disable callgrind benchmarks on non-Linux (#752)
* Check benches on CI + disable callgrind benches on Windows

* Fix cfg syntax
2024-01-25 13:48:18 +00:00
Tyler Cloutier 00e3cada4a Update README.md 2024-01-24 12:26:38 -08:00
Mazdak Farrokhzad 80d9372b48 SATS: add support needed for BFLATN => BSATN directly (#750)
* sats: add support needed for bflatn -> bsatn directly

Also some associated refactoring

* integrate phoebe's suggestions

Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>

* bflatn -> bsatn: add 'debug_assert's

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2024-01-24 16:53:47 +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
Mario Montoya be606912a2 Fix row count for the 'sql' command (#745) 2024-01-23 18:07:06 +00:00
John Detter 602f1bac26 Fix for reducer queue metric - tested on staging (#737)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-22 21:53:25 +00:00
Noa 6f8d48060c Implement disk usage metering (#724)
* Reorganize energy types

* Implement disk usage metering

* Address review

* Remove task spawning from withdraw_energy

* Make EnergyQuanta unsigned

* Address review
2024-01-22 21:23:14 +00:00
Mazdak Farrokhzad 9436544c3d misc ColList usage improvements (#738) 2024-01-22 18:55:23 +00:00
John Detter b905b68ead Fix --delete-files command without using --force (#739)
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-01-22 00:16:02 +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
Mazdak Farrokhzad a68ad8f85f add ColList: a compact repr of NonEmpty<ColId>, 8 vs 32 bytes (#730) 2024-01-19 23:44:19 +00:00
Noa 3a733965fd Fix _delete_by_rel (#733)
Signed-off-by: Noa <coolreader18@gmail.com>
2024-01-18 16:06:52 -08: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
james gilles bcffb5de80 Fix callgrind action again (#718) 2024-01-18 17:36:19 +00:00
james gilles 3e46d52996 Fix local callgrind runs (#723)
* Fix local callgrind runs

* Rust version sanity check
2024-01-18 17:36:08 +00:00
james gilles 4cc3edb133 Expand callgrind benches (#728) 2024-01-18 17:35:58 +00:00
Mario Montoya ffd22de280 Allows to convert into/from micros_since_epoch:u64 for TimeStamp (#731) 2024-01-18 16:56:58 +00:00
Kim Altintop 9441409d8c core: Sort constraint definitions before comparing (#727)
When updating a database, we may falsely report schemas as not
compatible due to the `ConstraintDef`s coming out in different orders in
the proposed and existing schemas.

Not sorting them was an oversight in 9bb2b215.
2024-01-18 07:35:53 +00:00
joshua-spacetime acbff825e8 fix: Reset max queue length and reducer wait time metrics (#725)
Max value metrics are currently reset to zero after each collection period.
However this won't be reflected in the metrics store immediately.

Once the database records new values for said metrics,
only then will the reset be reflected in the metrics store.

This subtlety is imperceptible for metrics that are frequently updated.
But if a metric is not frequently updated,
or for periods of reduced load in general,
the metrics store may present stale max value metrics.

This anomaly was thought to have been fixed by #709.
However it only fixed it for DB_METRICS.
This patch removes the anomaly for WORKER_METRICS as well.
2024-01-17 02:56:05 +00:00
Ingvar Stepanyan 79b2d04210 C# SDK tests (#706)
* Add C# SDK tests

* Add memoization

* Increase timeout

* Mark module_bindings as LF

* Regenerate from Rust again

* Sort tables & reducers for determinism

* cargo fmt

* Lint & fmt fixups

* Lint fixups

* Allow dirs ending in .wasm
2024-01-16 18:09:43 +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
joshua-spacetime 7ad87cbc0b chore: Disable query compilation metrics (#720)
Query metrics have very high cardinality.
The current metrics store does not handle high cardinality particulary well.
Query compilation contributes very little to overall resource consumption.
Therefore they have been disabled until the cardinality issue has been addressed.
2024-01-13 01:00:45 +00:00
joshua-spacetime b0e80c6697 chore: Move table size metrics back into core (#719)
* chore: Remove unused metrics

* chore: Move table size metrics back into core

Table size metrics were previously moved out of core.
This was due to the query planner needing access to them.
However that dependency was ultimately managed differently via #677.
2024-01-12 22:07:00 +00:00
joshua-spacetime 39baf1773c chore: Remove unused metrics (#717) 2024-01-12 21:35:05 +00:00
james gilles 11cd68a299 Fix benchmark actions (#715)
* Clean up after callgrind action

* Remove extraneous step in callgrind action

* Also fix regular benchmarks

* Additional callgrind benchmarks fix
2024-01-11 23:18:22 +00:00
Shubham Mishra 5116ae3da1 read tx implemented in datastore (#679)
* 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

* fix schema_for_table

* merge queue helped

* added StateView trait

* lint
2024-01-11 07:46:49 +00:00
joshua-spacetime eed3be2ad2 fix(683): Label table metrics with table name (#712)
Fixes #683.

Previously we were labeling metrics with the table id only.
However the table name is almost always desired for diagnostics.
2024-01-11 01:21:49 +00:00
james gilles 26263cbd5f Rebase callgrind benchmark work (#619) 2024-01-10 18:53:51 +00:00
Noa 395c527d23 Try bumping actions/checkout to fix benchmarks please (#710) 2024-01-09 20:25:38 +00:00
Ingvar Stepanyan e88bda0aaa Lower log verbosity (#703)
* Lower log verbosity

* cargo fmt
2024-01-09 12:05:11 +00:00
joshua-spacetime 906803f52e fix(684): Reset max value metrics (#709)
Fixes #684.

Prometheus does not reset metrics.
It only updates them with new values that it collects.
If it does not receive a new value for a metric, it will keep the old value.

Therefore it is important to periodically reset certain metrics.
Namely gauge metrics that only receive updates occasionally.

Maximum reducer duration is one such example,
since some reducers run much more infrequently than others.
2024-01-09 02:02:47 +00:00
joshua-spacetime b532ad3109 fix(707): Collect table size metrics again (#708)
Fixes #707.

Previously the table size metric definition was moved to a different crate.
This was to facilitate its use in query optimization.
However as part of that change it was never added back into the prometheus registry.
This resulted in the metric no longer being collected by prometheus.
This patch reintroduces it back into the registry, forcing its collection, again.
2024-01-08 22:28:22 +00:00