Commit Graph

905 Commits

Author SHA1 Message Date
Mario Montoya 114aa994bf Fix output of binary, Identity, Address for SQL output and the 'Display' of them to show a full hex value (#1087) 2024-06-10 16:49:46 +00:00
Zeke Foppa 2d09485f74 Bump version to 0.10.0 (#1349)
Co-authored-by: Zeke Foppa <github.com/bfops>
2024-06-10 16:25:02 +00:00
Ingvar Stepanyan d11c83e53c Add explicit parameter for table visibility (#1359) 2024-06-10 13:38:38 +00:00
joshua-spacetime c2831d06d0 test(1329): Row limit from system table (#1355) 2024-06-10 10:31:18 +00:00
Kim Altintop 1044ebc652 core: Store address, owner and program bytes in st_module (#1305) 2024-06-10 10:25:16 +00:00
joshua-spacetime ccaad88130 fix(1353): Remove underscore based table access checks (#1354) 2024-06-10 09:58:51 +00:00
Kurtis Mullins b5252479a1 Add Jenkinsfile to run internal automation (#1232) 2024-06-09 14:41:49 +00:00
joshua-spacetime 61ee5def83 feat: System table based slow query logging (#1350) 2024-06-07 21:37:34 +00:00
Noa a54399495d Prune bindings deps (#1290) 2024-06-07 20:36:33 +00:00
Ingvar Stepanyan d1033b5d93 Shared C# codegen for BSATN (#1312)
Signed-off-by: Ingvar Stepanyan <me@rreverser.com>
Co-authored-by: james gilles <jameshgilles@gmail.com>
Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-06-07 19:22:02 +00:00
Zeke Foppa 4af892a122 [bfops/update-quickstart]: do thing (#1348)
Co-authored-by: Zeke Foppa <github.com/bfops>
2024-06-06 20:40:45 +00:00
joshua-spacetime b3339c80bc feat(1329): System table for system variables (#1342)
Closes #1329.

Used to persist global parameters for slow query logging and cardinality limits.
2024-06-06 20:30:07 +00:00
Zeke Foppa 8f3f6bd9d7 Fix Config.save failing if /tmp is on a different filesystem (#1346)
* [bfops/fix-config-saving]:  do thing

* [bfops/fix-config-saving]: review

* [bfops/fix-config-saving]: fix smoketests

* [bfops/fix-config-saving]: use create_new to avoid race condition

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-06-06 16:28:17 +00:00
Snoppy 335c5b6e45 chore: fix typos (#1241)
* chore: fix typos

Signed-off-by: snoppy <michaleli@foxmail.com>

* Update lib.rs

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>

---------

Signed-off-by: snoppy <michaleli@foxmail.com>
Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2024-06-06 00:05:54 -04:00
Zeke Foppa b06b2e59f1 Fix bug with Lockfile sticking around (#1341)
* [bfops/fix-config-lock]: do thing

* [bfops/fix-config-lock]: review

* [bfops/fix-config-lock]: review

* [bfops/fix-config-lock]: fix

* [bfops/fix-config-lock]: TODOs

* [bfops/fix-config-lock]: review

* [bfops/fix-config-lock]: review

* [bfops/fix-config-lock]: review

* [bfops/fix-config-lock]: review

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-06-05 22:40:24 +00:00
Phoebe Goldman 8c5f40db8d Add the snapshot crate, which implements snapshotting at a low level (#1340)
* Add the `snapshot` crate, which implements snapshotting at a low level

- Requires making `BlobHash` be `Serialize` and `Deserialize`.
  For arcane macro-ology reasons, this requires writing `BlobHash::SIZE`
  instead of `Self::SIZE` (it gets embedded in a visitor struct or something).
- Requires adding two new operators to `BlobStore`.
- Adds a return value to `Page::save_content_hash`, for convenience.
- Impls `DerefMut` for `Pages`.
- **Scary change:** adds `Table::pages_mut`.
  I think possibly this operator should be `unsafe`,
  since write access to the `Pages` allows an undisciplined caller
  to violate the `Table`'s assumptions by corrupting a `Page`.
  It seems like an anti-pattern to mark a method `unsafe` on the grounds that
  misusing its return value can cause UB,
  but I don't see a plausible alternative
  without making most methods on `Page` unsafe.
  Open to feedback on this one!

* Nix `Table::pages_mut`

* Address Mazdak's feedback

* Use `thiserror` rather than `anyhow` for better error hygiene
2024-06-05 21:58:12 +00:00
Phoebe Goldman f9cc84e3b4 Define DirTrie, a git-like on-disk object store (#1336)
* Define `DirTrie`, a git-like on-disk object store

* Remove unused iteration code; add simple tests

* Address Mazdak's review
2024-06-05 17:16:59 +00:00
Mazdak Farrokhzad f08644f840 make update_database insensitive to table access changes (#1338) 2024-06-05 16:31:07 +00:00
Kim Altintop ff851ae5fa commitlog: Make bitflip test a proptest (#1333)
* commitlog: Make bitflip test a proptest

The test sometimes fails. As a proptest, we'll be able to seed it with
failing inputs.

Fixes: #1167

* commitlog: Fix the bitflip test

Turns out we sometimes flipped a bit in the CRC32 itself, which makes
things go wrong in not the expected way.
2024-06-05 05:53:41 +00:00
Phoebe Goldman 697a581886 Make both TX offset counters agree (#1332)
* Make both TX offset counters agree

Prior to this commit, `CommittedState::next_tx_offset` got out of sync
with the commitlog/durability's notion of the tx offset,
because the former counted all committed TXes,
while the latter excluded certain empty TXes
(namely, empty TXes
which were not `__identity_connected__` or `__identity_disconnected__` reducers).

With this commit, the skipping logic is moved earlier into `CommittedState`,
so that it can maintain a counter consistent with that used by the commitlog.

* Remove duplicated increment
2024-06-04 17:57:00 +00:00
Phoebe Goldman db34ff6a8e Create new crate fs-utils; move Lockfile and create_parent_dir (#1334)
* Create new crate `fs-utils`; move `Lockfile` and `create_parent_dir`

The snapshot crate will need to create lockfiles.
Rather than duplicating code to do so, we choose to move our definition of `Lockfile`
into a crate that can be depended on by both `cli` and `snapshot`.
No existing crate seems like an obvious choice for this
-- a `Lockfile` is not really a data structure, so `data-structures` seems wrong --
so we add a new crate, `fs-utils`.
Currently this contains only `Lockfile` and `create_parent_dir`,
but a follow-up PR will add `DirTrie`, a Git-like on-disk object store.

* Deduplicate `map_err` closure

* Zeke's nit: simplify control flow

Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>

---------

Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2024-06-04 16:57:28 +00:00
Phoebe Goldman a214f78f0b Impl Serialize, Deserialize for Page (#1335)
* Impl `Serialize`, `Deserialize` for `Page`

Snapshotting needs to write `Page`s to files and read them back again.
To that effect, this commit implements `Serialize` and `Deserialize` for `Page`.

* Address Mazdak's review

- Fix soundness in `FixedBitSet` by moving an assert.
- Add commentary to test.
- Add commentary to `spacetimedb-lib` dependency.
2024-06-04 15:49:27 +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
Phoebe Goldman 18aa1d4299 Fix commitlog fold_transactions_from ignoring requested offset (#1330)
* Fix commitlog `fold_transactions_from` ignoring requested offset

Prior to this commit, `fold_transactions_from` on a durability backed by a commitlog
would discard the requested offset and unconditionally yield all txes in the relevant segments.

This commit changes that behavior so that `fold_transactions_from`
skips commitlog commits (which contain many txes) less than the reqested offset,
and skips txes using `consume_record`.

* Add `Decoder::skip_record`

Lucky I asked Kim whether I was using `consume_record` and `decode_record` correctly,
because I wasn't.

This commit adds methods to `Decoder` and `Visitor` for skipping records and rows,
causing them to be extracted from the reader but not folded.

* Fix test

Add new methods to `Decoder` and `Visitor` hidden away in a test I missed.
2024-06-03 22:37:43 +00:00
Mazdak Farrokhzad be9c958d21 Flatten ColumnOp so that we box less (#1234) 2024-06-03 17:36:44 +00:00
Mazdak Farrokhzad 89aecd15e3 Split ColumnOp into one with row indices and one with FieldName & other enabled changes (#1207)
* 1. Split ColumnOp into ColumnOp & FieldOp, former storing ColId
2. Shrink SqlAst to 80 bytes, so it can be passed in registers
3. Store end-result Header in IndexSemiJoin
4. Remove operational use of Header in ColumnOp & build_query
5. Simplify RowRef::{get, project, project_owned}

* Make parts of build_query actually infallible.

1. Make IndexSemiJoin::filter infallible.
2. Make ColumnOp::compare and friends infallible.
3. Make RowRef::{get, project, project_owned} infallible.

* Make RelOps::next itself infallible

* 1. with_select{_cmp}: ensure type safety o query exec cannot panic
2. Document RelValue::{get, read_or_take_column, project_owned}
3. Refactor optimize_select
4. Ensure in optimize_select that conditions are merged with preceding selects

* remove RelOps::{head, row_count}; head is redundant & row_count is useless

* remove Relation trait; it does not carry its weight

* make build_query infallible

* simplify IndexSemiJoin, make it slightly less branchy

* simplify try_index_join

* split IndexSemiJoin into Left & Right parts

* move get_field_pos to test code

* move test version of build_query to test code
2024-06-03 16:45:32 +00:00
Zeke Foppa 2b66851560 More trace logs for TX locking (#1253)
* [bfops/logtrace]: do thing

* [bfops/logtrace]: empty

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-06-03 16:43:10 +00:00
Mazdak Farrokhzad f6b39c0abc IndexJoin/JoinInner: store ColId (#1166)
* IndexJoin/JoinInner: store ColId

* QueryExpr: carry full Header info for resulting query

* refactor and dedup build_query
2024-06-03 15:26:49 +00:00
Mazdak Farrokhzad 5e47b61f8a Tables only become public explicitly via #[spacetimedb(table(public))] (#1278)
* make user tables private by default and define privacy via attribute

* switch to spacetimedb(table(public)) syntax

* accept codegen snap changes

* sdk: use public in define_tables!

* bindings-macro: adjust some doc comments

* sdk-test-connect-disconnect: make Connected/Disconnected public tables

* Make Public Private again
2024-06-03 11:22:58 +00:00
Noa a8549457e9 Re-add execute_sql_mut_tx (#1313) 2024-06-03 09:49:03 +00:00
Mazdak Farrokhzad 74bcecd9d4 Restrict multi-col index scans to = (OpCmp::Eq) on all columns (#1316)
* add test test_multi_column_two_ranges, which should fail but doesn't

* restrict multi-col index scans to OpCmp::Eq
2024-06-01 13:25:06 +00:00
james gilles 638445293d Automated bot tests (#1255)
* Add script to dispatch bot tests to BitCraftBots

* Make sure results are named correctly, whoops

* Move results to a private bucket, whoops

* Pull in various fixes

* Safer for merge, don't run bot tests on every PR...

* Fix tracing patch

* Remove accidental file

* Test commit

* Test

* Test

* Fix results upload

* Address review comments
2024-05-31 17:52:22 +00:00
Shubham Mishra cf4b9aa282 metric for table size (#1319)
* table size metric

* feld blob_store_bytes in table

* address comments

* NumBlobBytes type

* table size metrics: adjust comments, visibility + harden test

---------

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2024-05-31 17:44:12 +00:00
Noa f8beb699c7 Implement new rand api (#1283)
* Implement new rand api

* Address comments
2024-05-31 17:42:58 +00:00
Ingvar Stepanyan 24d1750b1f Bump ABI version for C# AOT (#1311)
Looks like these constants got missed during upgrade, making AOT version ABI-incompatible.

Unfortunately, there's no way to use a central constant here, so we probably should add it to some "steps to do during ABI version bump" doc.
2024-05-31 17:40:49 +00:00
Ingvar Stepanyan 9e1e66f708 Fix FilterBy regression in C# (#1309)
* Fix FilterBy regression in C#

Fixes regression accidentally introduced in #1277: if FindBy returns null, FilterBy will return an iterable with a single null item instead of an empty iterable.

* Fix snapshots
2024-05-31 17:40:26 +00:00
Ingvar Stepanyan c76c3a0a77 NFC: use record struct for auto-equality in C# (#1318)
The new `record struct` construct is the same as `struct`, but automatically derives equality and hashing by walking through the fields - exactly what we need for those 2 types.
2024-05-31 17:40:01 +00:00
joshua-spacetime 6512f35c6b feat(1231): Add a configurable row limit for queries (#1293)
Closes #1231.

Queries that are estimated to exceed this row limit are rejected.
And the same holds for subscriptions.
2024-05-30 21:35:48 +00:00
Zeke Foppa 0bc42bfe48 Bump version to 0.9.3 (#1224)
* [bfops/bump-version]: empty

* [bfops/bump-version]: version bump

* [bfops/bump-version]: update

* [bfops/bump-version]: bump C# module versions too

* [bfops/bump-version]: bump 0.9.3

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-29 17:22:51 +00:00
Mazdak Farrokhzad 2d045b6bb4 fn (walk_)sources: use internal iteration to avoid allocations (#1304) 2024-05-28 22:06:23 +00:00
Mazdak Farrokhzad 4ac49e564d execution_set.check_auth(...) on initial subscription (#1274) 2024-05-28 19:44:32 +00:00
Kim Altintop 2c3fc66f21 Commitlog: panic on fsync failure (#985)
* commitlog: Panic on fsync failure

Errors returned by `fsync(2)` are particularly nefarious, as it is
mostly undefined what the state of the page cache is in this case.

Since the log is synced asynchronously and not after every write, it is
impossible to know up to which commit data can be considered durable --
except by reading the most recent segment from disk.

Therefore, the reasonable thing to do is to prevent any further use of
the log, and force users to re-load it from disk.

Note that this is only half of the solution: an application restart may
still read data from the page cache, which could be gone after a system
restart.

To fix this, we would need to employ direct I/O (i.e. `O_DIRECT`), which
however is beyond the scope of this patch as it invalidates the use of
most of `std::io`.

* commitlog: Handle duplicate commits when iterating

We cannot exclude the possibility of a false failure in I/O operations.
In particular, `EIO` errors are difficult to attribute to a particular
write, as they happen asynchronously during flush of the page cache.

Because we do not bypass the page cache, the possibility exists that a
particular commit is lost when it isn't, or that it is considered
durable when it isn't. The former could lead to duplicate commits
appearing in the log, while the latter could lead to a matching offset
number, but with different commit payload.

This patch thus ignores duplicates, and introduces a new error variant
in the event the offset matches but the checksum doesn't.

* durability: Manage the flush-and-sync task in this crate

Since syncing the commitlog may now panic, it is more obvious to handle
all async tasks here, so as to be able to handle the panic cases.

Namely, if the `FlushAndSyncTask` panics, the `PersisterTask` is
aborted. This will lead to the channel receiver being dropped, which in
turn will cause the next `append_tx` call to panic.

* commitlog: Remove async flush-and-sync

Due to panic behaviour, it is now preferable to manage periodic sync at
the use site of the commitlog crate.

Hence remove `flush_and_sync_every` method, and with it the dependency
on tokio.
2024-05-28 18:22:38 +00:00
Mazdak Farrokhzad c8225db8f5 1. Reduce visibilities, preparing to extract datastore crate (#1306)
2. More direct imports, preparing to extract datastore crate
3. Remove some dead code
2024-05-28 17:46:07 +00:00
Zeke Foppa 3b33f22c07 CLI - Drop Config lock earlier for spacetime logs (#1303)
* [bfops/lockfiles]: do thing

* [bfops/lockfiles]: empty

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-28 16:08:09 +00:00
Zeke Foppa be74474721 CLI - Fix Lockfile error message format strings (#1302)
* [bfops/lockfile-err]: do thing

* [bfops/lockfile-err]: empty

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-28 16:05:05 +00:00
Ingvar Stepanyan ac0c097f3d Implement consistent filtering rules for TypeScript (#1276)
- Limit types to those defined in the consistent filtering proposal (#1256).
- Make `filterBy` a lazy iterable for consistency and performance reasons.
- Add `findBy` for unique fields as per proposal.
2024-05-28 14:23:25 +00:00
Ingvar Stepanyan 307dfeebd3 Update C# codegen to consistent filtering rules (#1277)
* Update C# codegen to consistent filtering rules

- Limit types as per proposal.
- Add `Query` client-side SDK helper for API parity with server-side modules (on client-side it's a simple wrapper around Iter + Where).
- Change return type of `FilterBy` to always be iterable, with new `FindBy` function for unique fields.
- Simplify the way primary keys are handled - must go with https://github.com/clockworklabs/spacetimedb-csharp-sdk/pull/93 for the client SDK counterpart.

* Add using for System.Linq

* Update snapshot
2024-05-28 14:22:12 +00:00
Ingvar Stepanyan a7c75751f2 Implement consistent filtering rules for C# modules (#1282) 2024-05-28 14:08:40 +00:00
Ingvar Stepanyan f5a13b6f26 Consistent filtering in Rust client + minor fixes (#1275)
* Extend codegen tests to Rust

* Replace cursive-chat module_bindings with symlink

* Implement consistent filtering rules for Rust

* Fixup

* Regenerate tests

* Fix non-deterministic import order

* cargo fmt

* Fix chat examples

* Change symlinks to files themselves

* Revert accidental change

This needs to wait for server-side API break to be implemented as well.
2024-05-28 13:02:25 +00:00
Mazdak Farrokhzad 0e74beed16 merge_apply_inserts/deletes: do metrics work once per table, not per row (#1286)
* merge_apply_inserts: bulk update metrics

* merge_apply_deletes: bulk update metrics
2024-05-28 08:49:22 +00:00