Commit Graph

3186 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 91f7e8c917 add PageHeader::unmodified_hash, a BLAKE3 hash for snapshotting (#1249) 2024-05-20 17:47:42 +00:00
james gilles 47595848d5 Slightly better logging of sled errors, pending sledectomy (#1248) 2024-05-20 17:15:13 +00:00
Noa f0c182e2b0 Atomically downgrade lock when committing tx to prevent deadlock (#1252)
* Atomically downgrade lock when committing tx to prevent deadlock

* Address review
2024-05-20 16:59:07 +00:00
Mazdak Farrokhzad e109385c1e remove BTreeIndex::name again (#1251) 2024-05-20 15:52:57 +00:00
Mazdak Farrokhzad d188f966c2 move static bsatn layout to module + harden test (#1254) 2024-05-20 15:52:35 +00:00
Mazdak Farrokhzad 0b89165cec - Table::get_fixed_row -> RowRef::get_row_data (#1250)
- Document some table methods
2024-05-20 07:14:35 +00:00
Ingvar Stepanyan c665503eb5 Remove unreachable branches from C# generate (#1247)
These branches are already inside of `if is_unique {} else { ... }` branch, so `is_unique` can never be `true`.
2024-05-18 01:55:35 +00:00
Mazdak Farrokhzad 267cf651b8 simplify MutTxId::table_exists (#1246) 2024-05-17 18:22:05 +00:00
Shubham Mishra 0c0567ecbf row_count field to table (#1242)
* rowcount

* added tests
2024-05-17 17:48:58 +00:00
Piotr Sarnacki d08e9845a4 Always send TransactionUpdate to the sender (#1111)
* Always send TransactionUpdate to the sender

This commit changes transaction update broadcast to always send an
update to the sender, even if the sender is not subscribed to any
data that was committed. In such case the transaction update is sent
with an empty database update.

* Remove debug printlns

* Update code after rebase

* Fix test

* Update crates/core/src/subscription/module_subscription_manager.rs

Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Signed-off-by: Piotr Sarnacki <drogus@gmail.com>

* Extract sending message with error handing in module_subscription_manager

* Bring back a new line

* SDK test that the client is notified of a reducer it called

* cleanup subscription code a bit

* Fix merge problem

* Lint + fmt

* Fix test

---------

Signed-off-by: Piotr Sarnacki <drogus@gmail.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-05-16 12:35:03 +00:00
Mazdak Farrokhzad 5bf6b6cae8 add compile_join_with_diff_col_names test (#1238) 2024-05-15 18:34:27 +00:00
Mazdak Farrokhzad 9546a22e17 refactor compile_read_only_query: dedup SideEffect errors (#1235) 2024-05-15 13:48:02 +00:00
Mazdak Farrokhzad 5154f7969e to_bsatn_extend/vec: use uninit instead of zeroed buffer (#1204) 2024-05-14 17:03:16 +00:00
joshua-spacetime 401ffe2709 feat(1229): Double client channel capacity (#1230)
Closes #1229.

And log warning when client channel capacity is exceeded.
2024-05-14 16:54:46 +00:00
John Detter f13a1433f0 Make identity naming more consistent + fix bugs (#1140)
* Prevent importing an identity with a name that already exists in the
config

* Make identity naming more consistent

* Fix clippy lints

* Several bug fixes and UX improvements

* Prevent someone from adding the same identity twice

* Fix lint

* [jdetter/make-identity-naming-more-consistent]: review

* [jdetter/make-identity-naming-more-consistent]: review

* [jdetter/make-identity-naming-more-consistent]: review

* Reverted file

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-14 16:38:42 +00:00
Zeke Foppa 8ab55d2f59 spacetime publish: Add confirmation for -c (#1038)
* [bfops/confirm-publish-clear]: spacetime publish: add confirmation for -c

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: rename

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: fix?

* [bfops/confirm-publish-clear]: fix smoketests

* [bfops/confirm-publish-clear]: review

* [bfops/confirm-publish-clear]: fix rest of smoketests?

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-14 16:34:20 +00:00
Zeke Foppa 70de033690 Add CODEOWNERS for CODEOWNERS (#1226)
* [bfops/codeowners]: empty

* [bfops/codeowners]: update CODEOWNERS

* [bfops/codeowners]: update

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-14 14:33:10 +00:00
Zeke Foppa 7d41e762ea Add CODEOWNERS for LICENSE.txt (#1225)
* [bfops/codeowners]: empty

* [bfops/codeowners]: update CODEOWNERS

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-14 13:58:18 +00:00
Ingvar Stepanyan 125c5e7bc2 NFC: inline insert/delete update handling (#86)
## Description of Changes

Instead of a separate TableOp enum, and 4 fields to handle insert/delete
metadata in DbOp, use a nullable struct that contains non-nullable
object + bytes pair internally:

- if `insert` is present (non-nullable) and `delete` is nullable, that
naturally indicates insert operation
- if `insert` is nullable and `delete` is not, that's a delete
- if both are non-nullable, it's an update
- if both are null, it's an internal "no change" state

This simplifies and shortens update handling as well as reduces risk of
state getting out of sync - e.g. TableOp saying that the operation is
insert should exist but field containing inserted value being null. Now
nullable struct itself communicates whether there is an insert or not,
without a separate enum.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-05-14 12:48:52 +01:00
Ingvar Stepanyan 6ba3da5466 Minor refactoring of AuthToken (#84)
## Description of Changes

Initially just fixed the nullability issues / warnings, but in the
process did a few more minor drive-by refactorings.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-05-14 12:45:22 +01:00
Zeke Foppa 08ecaf8569 [bfops/cli-identity-refactor]: do thing (#1169)
Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-14 06:17:48 +00:00
Noa b3ea0f515f Fix select * from * (#1218)
* Add SDK test for `SELECT * FROM *`

Which doesn't pass, because we broke it.

* Fix select * from *

---------

Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-05-14 04:38:15 +00:00
Zeke Foppa 52c6df6531 Add CODEOWNERS for rust-toolchain.toml (#1221)
* [bfops/codeowners]: do thing

* [bfops/codeowners]: empty

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-14 04:00:12 +00:00
Zeke Foppa c7f191fb5d Bump version to 0.9.0 (#1055)
* [bfops/bump-version]:

* [bfops/bump-version]: bump lockfile

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-13 18:28:17 +00:00
Phoebe Goldman f6573c444e Create a lockfile when opening config files (#1196)
* Create a lockfile when opening config files

In the past, we've had issues where multiple concurrent CLI processes
would race to read and write the CLI config file,
leading to data loss.

We considered using `flock`/`LockFileEx` and blocking until the file became available,
but unfortunately it's not possible to atomically create and lock a nonexistent file,
which we need to do in the case where the configuration doesn't yet exist.

Instead, we opt for a classic lockfile-based scheme:
Before opening a config file `foo.conf`, attempt to exclusively create `foo.lock`,
and panic if the exclusive creation fails.
Once it becomes clear that we will not write the config any more,
i.e. in `Config::drop`,
delete the lockfile, allowing another process to operate.

This means that attempting to run multiple concurrent Spacetime CLI processes
with the same config file is now a hard error.

* Fix CI failures

This commit fixes two CI failures:

- `spacetime start`, and a few other CLI subcommands, do not access their `Config` at all,
  but the CLI constructs it unconditionally in `main`,
  which made it an error to run any CLI command while `spacetime start` was running.
  This is fixed by having subcommands which don't need a `Config`
  drop it before doing anything.
- Contrary to my assumption,
  the test configuration created by `Config::new_with_localhost` does get `drop`ped,
  because the test harness `clone`s is and passes an owned version to the CLI.
  This was causing it to attempt to delete the empty path, which failed.
  This is fixed by having the home configuration be `Option`al,
  and setting it to `None` in tests.

* Clap before config because they suppress destructors

Perform Clap argument parsing as the very first thing in a CLI process,
before locking the config,
because Clap calls `exit` directly on error rather than panicing
(presumably to have more control over error output),
which prevents destructors from running,
leaving stale lockfiles.

* Encapsulate lockfile logic in a type

Also deduplicate logic for finding config file paths.

* Define `create_parent_dir` helper with comments

* Replace `drop` calls with more explicit `Config::release_lock`.
2024-05-13 18:22:54 +00:00
Zeke Foppa 4cdb6609e4 Split up #735: auth.rs refactors (#871)
* [zeke/noa-router-shuffle]: bring over auth.rs changes from #735

* [zeke/noa-router-shuffle]: review
2024-05-13 17:33:53 +00:00
Zeke Foppa 669d48713b Fix #1180: Add PR status check that fails unless based on master (#1213)
* [bfops/fix-github-action]: fix?

* [bfops/fix-github-action]: empty

---------

Co-authored-by: Zeke Foppa <github.com/bfops>
2024-05-13 16:33:42 +00:00
Ingvar Stepanyan 8db08a7354 Switch to TaskCompletionSource (#89)
## Description of Changes

There is only one place where we use Channels, and it's to create and await a channel with one element - which is functionally the same as a more precise and low-weight TaskCompletionSource.

Switching also makes the SDK compatible with the widely supported .NET Standard 2.1 subset, which is supported natively in Unity and allows to remove a custom System.Threading.Channels package from Unity SDK dependencies.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-05-13 17:07:28 +01:00
Ingvar Stepanyan c8319ebb98 Simplify event dispatch in WebSocket (#90)
## Description of Changes

Instead of using custom class hierarchy of messages, we can just use
native C# lambdas stored as Actions.

OnConnectError case can be further simplified by merging two branches
for different exception types into one.

## API

 - [ ] This is an API breaking change to the SDK

*If the API is breaking, please state below what will break*


## Requires SpacetimeDB PRs
*List any PRs here that are required for this SDK change to work*
2024-05-13 17:05:43 +01:00
Ingvar Stepanyan 8ca04842c5 Add basic CI (#88) 2024-05-13 16:49:57 +01:00
Ingvar Stepanyan c925af1791 Fix conflict resolution shenanigans (#87) 2024-05-13 16:45:56 +01:00
Kim Altintop 61613ca7a8 commitlog: Allow folds to not allocate Mutations values (#1215)
The documentation promised to not collect payload values during folds
(i.e. replaying), but the code did so anyway. This patch makes it so
only values required to satisfy the `Visitor` trait are allocated when
folding.
2024-05-13 09:35:09 +00:00
Mazdak Farrokhzad 9a827f2f26 remove a few dead impls (#1214) 2024-05-13 08:41:08 +00:00
Ingvar Stepanyan 125ca70959 Switch to a better API for tagged enums for C# (#1177)
With C# records - which are available since C# 9, so covers Unity requirements as well - we can use subclassing and pattern matching to get sum types that look a lot more like Rust tagged enums.

This is a breaking change but IMO worth it for the better API going forward.
2024-05-10 22:05:18 +00:00
Ingvar Stepanyan 1bb67c59a9 Remove RowUpdate event (#83)
We talked about this for a while, so decided to do this in a separate PR.
2024-05-10 22:41:23 +01:00
Ingvar Stepanyan e252b0cf63 Remove RowUpdate event from C# (#1190)
We talked about this for a while, so decided to do this in a separate PR.
2024-05-10 21:41:16 +00:00
Mazdak Farrokhzad 4e444bdddd CrudExpr::{Delete, Insert, Update}: only DbTables are possible, so cleanup InMem path (#1211)
* remove dead code wrt. Table

* simplify DbProgram: Insert/Update/Delete only use DbTables

* consistency: move CrudExpr::Update logic to own function

* use TxMode::unwrap_mut more
2024-05-10 00:04:47 +00:00
Mazdak Farrokhzad 78696e5fc3 remove some dead code (#1210) 2024-05-10 00:02:42 +00:00
Ingvar Stepanyan ce38cd100b NFC: remove unused primaryKeyValue field (#85)
This field is only used in self-assignment, so can be safely removed.
2024-05-09 19:18:18 -04:00
John Detter b275dbfee8 spacetime build uses --project-path param (#1212)
* `spacetime build` uses `--project-path` param

* Fix smoketests

* Another small fix

* Another fix

---------

Co-authored-by: John Detter <no-reply@boppygames.gg>
2024-05-09 16:56:43 +00:00
Ingvar Stepanyan 6b5b23d5b8 Extract common logic from OnMessageProcessComplete (#81)
Minor refactoring that extracts common part of subscription and transaction update handling into a separate function, so that the main logic in `OnMessageProcessComplete` is a bit more straightforward and handles all event types with a sinlge `switch` instead of 3 separate `switch`es.

This is a small no-op step that makes further refactoring and optimisation of said common logic a bit easier.
2024-05-09 15:47:14 +01:00
Noa 3b754f10b1 Bump to Rust 1.78 (#1205)
* Bump to rust 1.78

* Fix lints
2024-05-08 14:20:12 +00:00
Ingvar Stepanyan eaa8fa0894 Merge ByteArrayComparers (#78)
* Merge ByteArrayComparers

Merge various mismatched implementation of byte array comparison/hashing into a single utils class (choosing the most efficient implementation already present).

* Forward hex conversion too

* Use const for Identity & Address sizes
2024-05-08 10:03:18 -04:00
Ingvar Stepanyan fe44011e4f C#: rename DbEventArgs to ReducerContext (#1191)
* C#: rename DbEventArgs to ReducerContext

This is no longer an event type, so remove subclassing and rename to match the Rust API.

* Update ReducerContext argument name
2024-05-08 14:00:32 +00:00
Mazdak Farrokhzad 1be912bddb subscription benches: reorder footprint fields (#1209) 2024-05-07 16:26:40 +00:00
Mazdak Farrokhzad 6dce129494 From.{join => joins} + remove Option layer + Remove RelOps::try_fold (#1208)
* refactor From sql ast type

* remove RelOps.:try_fold (dead code)
2024-05-07 16:26:27 +00:00
Mazdak Farrokhzad fcc326bff9 Fix unsoundness in AlgebraicValue::type_of by making it partial (#1189)
* cleanup bsatn ser/de roundtrip test

* fmt::Display for FieldExpr: don't use type_of

* make type_of partial and sound

* type_of: address review feedback
2024-05-03 22:12:09 +00:00
joshua-spacetime 9ce8fc8db7 feat(1168): Track subscription query duration for each reducer (#1195)
Closes #1168.
2024-05-03 18:24:45 +00:00
Ingvar Stepanyan 165f750d73 Remove C# GetArgsAsObjectArray (#1188)
* Remove C# GetArgsAsObjectArray

This is a weird "duck-typed" API that has one usage in BitCraft, but it's easy to replace with either real reflection or strong-typed interfaces.

* Update csharp.rs

Signed-off-by: Ingvar Stepanyan <me@rreverser.com>

---------

Signed-off-by: Ingvar Stepanyan <me@rreverser.com>
2024-05-03 01:48:05 +00:00
Phoebe Goldman 484ba824ba Make Page always fully init (#1193)
* Make `Page` always fully init

Per discussion on the snapshotting proposal,
this PR changes the type of `Page.row_data` to `[u8; _]`,
where previously it was `[MaybeUninit<u8>; _]`.

This turns out to be shockingly easy,
as our serialization codepaths never write padding bytes into a page.
The only place pages ever became `poison` was the initial allocation;
changing this to `alloc_zeroed` causes the `row_data` to always be valid at `[u8; _]`.

The majority of this diff is replacing `MaybeUninit`-specific operators
with their initialized equivalents,
and updating comments and documentation to reflect the new requirements.

This change also revealed a bug in the benchmarks
introduced when we swapped the order of sum tags and payloads
( https://github.com/clockworklabs/SpacetimeDB/pull/1063 ),
where benchmarks used a hardcoded offset for the tag which had not been updated.

* Update blake3

Blake3 only supports running under Miri as of 1.15.1, the latest version.
Prior versions hard-depended on SIMD intrinsics which Miri doesn't support.

* Address Mazdak's review.

Still pending his agreeing with me that `poison` is a better name than `uninit`.

* "Poison" -> "uninit"

Against my best wishes, for consistency with the broader Rust community's poor choices.

* Remove unnecessary `unsafe` blocks

* More unnecessary `unsafe`; remove forgotten SAFETY comments
2024-05-02 23:15:48 +00:00