Commit Graph

3186 Commits

Author SHA1 Message Date
Kim Altintop 06d5481dfb commitlog: Support traversal without opening the log (#1103)
Traversing the commitlog without also making it available for writing
would still require upfront I/O imposed by the `open` constructor.

Avoid that by introducing free-standing functions which start traversal
right away.
2024-04-19 18:08:41 +00:00
Kim Altintop dcfbf685c8 cli: Suggest to make new identity the default for server (#1109)
When a server key rotation is suspected, suggest to make the new
identity the default.

This usually happens during development using an ephemeral instance. If
one follows the instructions, the `default_identity` is not set for the
existing server, which makes the CLI generate a fresh identity every
time.

See also: #333
2024-04-19 10:12:01 +00:00
Kim Altintop bee6ae188d Re-instantiate replay progress reporting (#1096)
* durability: Introduce a method to obtain the max tx offset of a history

Useful for reporting replay progress.
Include note that it is somewhat similar to `std::iter::Iterator::size_hint`.

* core: Re-instantiate replay progress reporting

The percentage is calculated as starting from the zero offset, although
that may change in the future.
2024-04-19 09:38:52 +00:00
joshua-spacetime 18bf7ee5e5 fix(1115): Identify subscribers by Identity AND Address (#1121)
Closes #1115.

Previously subscribers were only identified by their Identity.
However the same Identity can be associated to different Addresses.
2024-04-19 02:01:32 +00:00
Mazdak Farrokhzad ce7d9b0565 slow query log: only use Instant::now when needed + refactor (#1110)
* slow query log: only use Instant::now when needed + refactor

* address Joshua's review
2024-04-18 21:41:35 +00:00
Kim Altintop 2894d364fb core: Store inputs (reducer info + args) in commitlog (#1091)
Prerequisite for auto-disconnect after a database crash, requested for
analytics purposes.
2024-04-18 20:16:52 +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 f560101551 Make Table::clone_structure cheaper by: (#1090)
- Arcing `TableSchema`, and this has benefits elsewhere too.
- Arc<[_]>ing the visitor program instructions.

The data behind the Arcs very rarely change,
which is the perfect case for an Arc.
2024-04-16 19:07:36 +00:00
Mazdak Farrokhzad b428844c67 simplify ExecutionContext constructors (#1098) 2024-04-16 09:25:41 +00:00
Mazdak Farrokhzad 5e78223ae7 nuke DataKey (#1093) 2024-04-16 06:49:14 +00:00
james gilles f42383869a Fix iai-callgrind rustc version mismatch (#1025)
* Fix iai-callgrind rustc version mismatch

* Two spaces

* Future-proof
2024-04-15 18:49:21 +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 4cd17d7e00 core: Don't persist empty transactions (#1086)
Fix a minor bug where completely empty transactions would still be
written to the commitlog. The bug is minor because, once we start
logging inputs, all transactions will be non-empty.

The check is done in relational DB rather than the durability crate,
because in principle empty transactions are permissible, and may be used
in the future (e.g. to confirm a certain offset).
2024-04-12 16:45:21 +00:00
james gilles 1c2e63e0a4 Table: skip alignment checks in eq_row_in_page and hash_row_in_page (#1085)
* Table: skip alignment checks in eq_row_in_page and hash_row_in_page

* Whoops, those comments can stay the same.
2024-04-12 16:05:34 +00:00
Kim Altintop 838e8696ec core,commitlog: Re-instantiate commitlog disk usage reporting (#955)
Disk usage reporting was left unimplemented in previous patches of the
series, as its semantics are slightly different from before.

Namely, inspecting the size of the commitlog now requires to `stat(2)`
the segment files, and is thus fallible.

Also, a size reporting function is only defined for local durability
(i.e. the commitlog). The behaviour when the database is in a follower
state is left unspecified.
2024-04-12 08:49:34 +00:00
Kim Altintop be67d1aa27 core: More compact TxData (#950)
`TxData` is the representation of a transaction after it was committed,
and is passed around for evaluation of subscription queries and sending
the result to clients.

With the new commitlog, it can be represented more compactly, such that
copies for writing to the log can be avoided.

Note that this patch stops short of refactoring `DatabaseUpdate`, which
is another representation of the same information as sent to clients.
This means that `ProductValue`s need to be cloned from `TxData`, just as
before.
2024-04-12 08:06:52 +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
james gilles b9cee3d09f Swap the location of tags in the BFLATN encoding (#1063)
* Swap the location of tags to go before variant data in the BFLATN encoding

* Fix a comment

* Apply suggestions from code review (@gefjon @Centril)

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

* Implement memcpy consolidation for sums

* Vanquish clippy

---------

Signed-off-by: james gilles <jameshgilles@gmail.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2024-04-11 20:10:00 +00:00
Mario Montoya 29970d219a Implement 'sql' parsing for 'Identity, Address' in hex format (#786) 2024-04-11 17:31:08 +00:00
Kim Altintop 02be002416 Durability: Traits and implementation in terms of commitlog (#922)
Defines traits intended to abstract over the kind of persistence a
database utilizes. The only implementation is (host-)local durability in
terms of the new commitlog crate.

The trait definitions may not be considered stable yet, but are in their
tentative form needed for further integration of the new commitlog.
2024-04-11 09:44:58 +00:00
Kim Altintop 29c997cb9d core: Make init_module_host consistent with update_module_host (#977)
`spawn_module_host` was changed in #904 to ensure that the supplied
program is indeed the database's current program. There are, however,
uses which would call `spawn_module_host`, followed by either
`init_database` or `update_database` on the returned `ModuleHost`.

This would fail because the condition is not met.

While we cannot prevent misuse, this patch documents the various
lifecycle methods, and adjusts the signature of `init_module_host` to be
(somewhat) consistent with `update_module_host`. Namely, it will
optionally return the result of the `init` reducer call.
2024-04-11 04:33:01 +00:00
Noa abdaf88563 Move lib::{name,recovery} to client-api-messages (#570) 2024-04-10 20:24:05 +00:00
Shubham Mishra b928387c60 disable iter metrics (#1074)
* disable iter metrics

* not comment out for non-iters

* remove explicit drop as clippy cried
2024-04-10 12:46:25 -05:00
Phoebe Goldman 8902b08bfc Drop commitlog logging to trace to avoid spamming host logs (#1073) 2024-04-10 15:26:54 +00:00
joshua-spacetime 5203b01fa6 refactor(1058): Remove feature flag for disabling metrics (#1059)
Closes #1058.
2024-04-09 20:25:32 +00:00
joshua-spacetime 530cdaa062 fix: Disable unused metrics (#1056)
This patch:

(1) Disables unused WasmInstanceEnv metrics,
(2) Removes unused query compilation metrics,
(3) Removes unused RelationalDB metrics
2024-04-09 19:43:10 +00:00
joshua-spacetime c69ab121eb fix(1051): Reset queue length metrics on module restart (#1053)
Fixes #1051.

Queue length metrics were not being reset in all cases for module restarts.
2024-04-09 19:19:33 +00:00
Tyler Cloutier 593c1d4f64 Metrics were not measuring the time it took to commit the tx. I am now measuring that time. Commitlog appending is still not measured but should be measured separately in the future. (#1045) 2024-04-09 17:05:50 +00:00
Phoebe Goldman 6d91d57f3c Detect unsatisfiable range queries; warn and short-circuit. (#1036)
* Detect unsatisfiable range queries; warn and short-circuit.

This commit fixes a panic caused by unsatisfiable range bounds on an index query,
e.g. `WHERE x < 5 AND x > 5`.
These unsatisfiable bounds made Rust's `BTreeMap` angry
(See https://doc.rust-lang.org/src/alloc/collections/btree/search.rs.html#106-124),
and panicked.
They also represent probable bugs,
as it's silly to write a query which statically will return no rows.

With this commit, we detect statically unsatisfiable bounds in two cases:
- When compiling queries, we log a message at `WARN` containing the offending query.
- When evaluating queries, we silently construct an `EmptyRelOps`
  rather than a real query iterator.

This commit also adds a test that the offending queries can be compiled and executed
without panicking, and select no rows.

* Per Joshua's review, add comments that this is a suboptimal solution

* Fix typo

---------

Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2024-04-09 01:23:20 +00:00
Mazdak Farrokhzad 98363888ff IndexSemijoin::next: do a bit less cloning and work (#1044)
* IndexSemijoin::next: do a bit less cloning and work

* address Joshua's review
2024-04-08 23:48:41 +00:00
Phoebe Goldman c394044c2e Reject large SQL queries (#1037)
This avoids a stack overflow when compiling deeply-nested `AND` and `OR` expressions.
2024-04-05 19:28:38 +00:00
Noa abbb7b0db9 Preserve debuginfo through wasm-opt (#1013) 2024-04-05 18:13:55 +00:00
Mazdak Farrokhzad 344861f290 use nohasher_hash and ahash instead of siphash13 (#1040)
* use nohasher_hash and ahash instead of siphash13

* re-export types in spacetimedb_data_structures::map
2024-04-05 17:30:51 +00:00
Phoebe Goldman 82ef1db791 Consistently use --identity -i for identity args to CLI (#1041)
* Consistently use `--identity` `-i` for identity args to CLI

Prior to this commit, some subcommands used `--as-identity` as the long,
some of them used `-I` as the short, and there was no clear pattern.

With this commit, we just use `--identity` as the long everywhere,
and `-i` as the short.

* Rename variables per John's review
2024-04-05 15:16:30 +00:00
Mazdak Farrokhzad af846dd994 remove dead code in subscription (#1039) 2024-04-05 12:08:07 +00:00
Shubham Mishra 84071b5629 Batch metrics with ctx (#916)
* Commit iter metrics

* test: Make full-join benchmark async

* use Vec instead of Hash

* Revert "test: Make full-join benchmark async"

This reverts commit eed5aa8a55.

* rebase on master

* lint

* refector api

* remove lifetime from ctx (#1017)

* move ctx to higher level

* fix boilterplate

* batch more

---------

Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2024-04-05 06:57:40 +00:00
Ingvar Stepanyan 02d0428151 C#: add experimental NativeAOT-LLVM support (#713)
* Add experimental NativeAOT-LLVM support

* Fix codegen ambiguity

* Restore logging redirect
2024-04-03 18:23:39 +00:00
Mario Montoya 56887f50ce Implement 'sql' parsing for simple 'Enums' (#1018) 2024-04-03 17:57:00 +00:00
Noa 99b2fd426f Bump to reqwest 0.12 (uses hyper 1.0) (#1031) 2024-04-03 01:54:53 +00:00
Noa 7d3bdc308b Prune deps from bindings dependency tree (#1014) 2024-04-03 01:54:36 +00:00
Mario Montoya 0ecaf9905c Make 'op_type' an Enum (#1032) 2024-04-02 10:10:48 +00:00
Kim Altintop 1d316d991e Commitlog: Add canonical txdata payload (#921)
Defines the canonical commitlog payload, and how to encode / decode it.

Also exposes folds alongside iterators, which allows the common case of
replaying the commitlog onto a database to be further optimized (the
`Txdata` does not have to be constructed in this case). This
optimization is, however, left for a future patch.
2024-04-02 09:54:19 +00:00
Kim Altintop 73cd78231e Commitlog: Add I/O based on regular files (#920)
Provides a commitlog backing store based on files, and defines the
exported `Commitlog` type which fixes the store to the file-based one.
2024-04-02 09:10:21 +00:00
Kim Altintop 3b343e4eb1 Commitlog: Base implementation "sans I/O" (#919)
First in a series of patches to implement the new commitlog format.

This patch implements the base format, leaving the transaction payload
generic. Segment handling, writing and reading is implemented based on
an in-memory backend, which greatly simplifies testing.

As a notable deviation from the previous implementation, segments are
never implicitly trimmed. Instead, faulty commits are ignored if and
only if the next commit in the log sequence is valid and has the right
offset. On the write path, this entails closing the active segment when
an (I/O) error occurs, but retaining the commit in memory such that it
is written to the next segment.

Note that this patch does not define the final public API.
2024-04-02 06:18:30 +00:00
Phoebe Goldman acecc522bf brotli-decompress received binary websocket messages (#41)
Re: https://github.com/clockworklabs/SpacetimeDB/pull/1026
2024-03-29 14:53:44 -04:00
Phoebe Goldman 2d971f374f Binary WebSocket API: Brotli-compress all outgoing messages (#1026)
* Binary WebSocket API: Brotli-compress all outgoing messages

* Decrease buffer size; comment on future work

Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>

* Note experimental compression ratio

---------

Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
release-alpha-1
2024-03-29 17:27:28 +00:00
Ingvar Stepanyan e649c49e80 Add Brotli decompression (#75)
C# client counterpart for https://github.com/clockworklabs/SpacetimeDB/pull/1026.
2024-03-29 11:45:52 -04:00
Dylan Hunt 7b3b96cdd2 Dylan/onboarding-upgrades (#28)
* doc: Onboarding impr, fixes, consistency, cleanup

refactor: Whats next cleanup, +unity, -bloat

Removed redundant text while there

refactor: Unity quickstart fixes, impr, prettify

refactor: Unity pt1 fixes, impr, prettify

fix(README): Rm "see test edits below" ref

* !exists

refactor(minor): General onboarding cleanup

* Shorter, prettier, consistent

fix(sdks/c#): Broken unitypackage url

feat(sdks/c#): Add OneTimeQuery api ref

* doc: Onboarding impr, fixes, consistency, cleanup

* fix: Rm redundant 'module_bindings' mention

* fix: Floating period, "arbitrary", "important":

- PR review change requests
- Additionally: hasUpdatedRecently fix and reformatting

* fix: Mentioned FilterBy, used FindBy

- Used FindBy since that was what the tutorial used, and also looking for a single Identity.
- Note: There may be a similar rust discrepancy in the Unity pt1 tutorial. It'll work with Filter, but just simply less consistent. Holding off on that since my Rust syntax knowledge !exists.

* fix(Unity-pt1): Rm copy+paste redundant comments

* Duplicate comments found both above and within funcs

* fix(unity): Rm unused using statement +merged info

* Removed `System.Runtime.CompilerServices`
* SpacetimeDB.Module seems to already include this (merged the info)

* refactor(minor): Code spacing for grouping/clarity

* feat: 'Standalone mode runs in foreground' memo

* At general quickstart for `spacetime start`

* refactor(unity-pt1): Standalone mode foreground memo

* Also, removed the "speed" loss mention of C#

* fix(syntaxErr): Fix err, keep FilterBy, handle null

- After a verbose discussion, we will eventually swap to FindBy for single-result queries, but not in this PR.
- For now, the syntax err is fixed by making the var nullable and suffixing a LINQ FirstOrDefault(). Approved by Tyler in Discord.
- We never *actually* created a player in the tutorial. This creates the player. Approved by Tyler in Discord.

* fix: Remote player `is null` check removal
2024-03-29 17:16:35 +08:00
Tyler Cloutier 01ba5cd898 Fixed an issue which caused metrics to only be recorded for on-disk databases (#901)
* Fixed an issue which caused metrics to only be recorded for on-disk databases

* cargo fmt

* Removed unused args

* Fixed logic error
2024-03-28 23:21:57 +00:00
Mazdak Farrokhzad ddf6048547 Split DatabaseTableUpdate in deletes/inserts vecs (#1019)
* eval_incr: add RelValue::ProjRef(&PV) to avoid cloning PVs

* 1. rename `build_source_query` -> `in_mem_to_rel_ops`
2. `SourceExpr::{MemTable -> InMemory}`
3. clariy some commentary re. SourceExpr/SourceSet and friends
4. cleanup: simplify `compile_select_eval_incr`
5. remove ProgramStore; twas dead code.

* add SourceProvider, simplifying the source set stuff

* use MemTable less

* split DatabaseTableUpdate in deletes/inserts vecs

* incr-join: avoid temp Vec<_> allocs

* store deletes/inserts separately in eval_incr results; mostly cleanup
2024-03-27 20:12:30 +00:00