Commit Graph

166 Commits

Author SHA1 Message Date
Mario Montoya 8adef2b93b Support for the PG wire protocol (#2702)
# Description of Changes

Closes
[#2686](https://github.com/clockworklabs/SpacetimeDB/issues/2686).

Add support for listening using the [PG wire
protocol](https://www.postgresql.org/docs/current/protocol.html) so `pg`
clients could be used against the database.

# API and ABI breaking changes

The output of `duration` is changed to `rfc3339`, instead of the way is
made with `sats` because is what is done in `pg`, see note below.

# Expected complexity level and risk

2

~~There is open questions that are in the [ticket
#2686](https://github.com/clockworklabs/SpacetimeDB/issues/2686). Also
the crate used here require `RustTls`, so it could be good idea to
decide if~~:

* ~~Rewrite a big chunk of code to use `OpenSSL`~~
* ~~Move to `RustTls`
https://github.com/clockworklabs/SpacetimeDB/pull/1700~~
* ~~Pay for the extra compilation cost~~.

I open another port(`5433`) to listen for `pg` connections using `ssl`.
Need to be decided if this is the way or instead try to multi-plex the
current port for both protocols.

# Testing

Only manual testing so far. Solving the above questions allow me to
implement some unit tests. Also, not yet integrated into cloud for the
same reasons.

- [x] Adding some test for the binary encoding of special and primitive
types
- [x] Smoke test using `psql` that connect to the db instance and run
some queries
- [x] Manually inspect using a UI database explorer how infer the types,
some of this tools generate special widgets when displaying `json,
duration, etc`

---------

Co-authored-by: Noa <coolreader18@gmail.com>
2025-09-10 19:58:03 +00:00
Shubham Mishra 2c74f73550 Endpoint for pretty print migration plan (#3137)
# Description of Changes
- Adds endpoint for for pretty printing migration plan.
- It also changes current `publish` endpoint to optionally provide
`MigrationToken` and `MigrationPolicy` to allow migration with breaking
clients.

# API and ABI breaking changes
Backward compatible change to existing API and new Api

# Expected complexity level and risk
2

# Testing
- Existing smoketest should cover changes for `publish` endpoint.
- For pretty print endpoint, smoketests can be written only after cli
changes.

---------

Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Co-authored-by: James Gilles <jameshgilles@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2025-09-09 06:53:37 +00:00
Kim Altintop f394de32d9 Confirmed reads (#3133)
# Description of Changes

Implements [subscribing to durable
commits](https://github.com/clockworklabs/SpacetimeDBPrivate/issues/1594).

The setting works on a per-connection level, and essentially just delays
sending transaction updates until the transaction is reported as durable
by the database.

For connectionless SQL operations, the setting works per-request. No SQL
syntax is provided by this patch to toggle the configuration.

After some deliberation, I opted to obtain the offset when a transaction
commits (as opposed to when it starts). This creates some mild
inconvenience, because we prevent the transaction from committing until
the corresponding subscription updates are enqueued.
The strategy is, however, more correct should we ever support weaker
isolation levels, and it is easier to document.

Follow-ups include:

- Provide SQL syntax (`SET synchronous_commit = ON` or something)
- C# and TypeScript SDKs
- Reference docs?
 

# API and ABI breaking changes

Not breaking, but adds a parameter to the subscribe and sql endpoints.


# Expected complexity level and risk

4

To the author's understanding, ordering of outbound messages is not
changed by this patch, even if there are messages that don't have a
transaction offset (such as error messages). I.e. while waiting for the
transaction offset of a message to become durable, no message enqueued
after that message will be delivered. This may not be desirable in some
cases.

The patch may contain concurrency bugs, e.g. awaiting futures that may
never resolve.


# Testing

- [x] Implemented a new test in the `module_subscription_actor` module
- [x] Added unit tests for the core logic in `ClientConnectionReceiver` 

It would be desirable to also have integration-level tests, but I'm
currently unsure how to write those without being able to control if and
when the database reports an offset as durable.

---------

Signed-off-by: Kim Altintop <kim@eagain.io>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2025-09-08 17:51:04 +00:00
joshua-spacetime f9c8e72d8f fix incoming message queue length metric (#3172)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

We stopped incrementing the incoming queue length metric. This patch
increments it again and adds a regression test.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

1

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Regression test
2025-08-15 15:00:12 +00:00
Phoebe Goldman 3feed08ced Increase default incoming_queue_length limit, log warning when a client violates it (#3171)
# Description of Changes

Closes #3170 .

Commit messages:

### Increase the default incoming-queue-length limit

2048 turned out to be too low a value for BitCraft, as their world
upload process requests on the order of 6000 reducers very rapidly. We
still feel that having a limit is valuable to prevent malicious or
misguided clients from taking an arbitrarily large amount of host
memory, so we bump the value to give us a wide safety error for
BitCraft's needs but don't remove the limit entirely.

### Add log at `warn` when the host disconnects a client due to too many
requests

# API and ABI breaking changes

N/a

# Expected complexity level and risk

1

# Testing

- [x] @mamcx to run a BitCraft bot test.
2025-08-14 22:18:33 +00:00
Kim Altintop b445620f03 Fix module hotswapping for connected clients (#3159)
The `Clone` impl for `ClientConnection` would create an independent
instance that could not observe module hotswapping. This would result in
methods called on a replaced `ModuleHost` to fail, because that host
exited already.

Fix by reading the `ModuleHost` from the watch channel directly, instead
of maintaining a redundant copy.

Also fix `watch_module_host` to properly mark the current module host as
seen.

# Expected complexity level and risk

2

# Testing

- [x] test suite passes
- [x] ran @bfops repro script
2025-08-13 18:36:06 +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
Phoebe Goldman c18b291f12 Add additional logging to subscribe route and simplify calling client_connected (#2998)
# Description of Changes

Out-of-band discussions with the BitCraft team brought up questions
about whether it was possible for a rejected client connection to start
an expensive computation like a subscription before their connection was
killed, e.g. by sending a `Subscribe` message along the WebSocket before
`client_connected` had finished returning `Err`.

I don't believe this was actually possible, as `ClientConnection::spawn`
called and awaited `call_identity_connected` before invoking its `actor`
closure, and it was that `actor` which processed `Subscribe` messages.
But it was somewhat difficult to verify that behavior, and so I
re-organized the code so that the outer layer of the `subscribe` handler
obviously had that property without having to step into
`ClientConnection::spawn`.

I also added some additional logging to the subscribe route, including
the `X-Forwarded-For` header in more messages, as the BitCraft team
complained about having difficulty correlating IP addresses with
connections. The log levels remain the same as before, just with
additional information added:

- Successful connections are at `debug` level,
- Rejected connections are at `info` level (these are the ones BitCraft
cares about in this case).
- Failed connections are at `warn`.

As the levels are unchanged, this should not add undesirable log noise.

# API and ABI breaking changes

N/a

# Expected complexity level and risk

3? The `subscribe` route was complex and remains so. I believe this
change simplifies the code and makes the logic more obvious, but
reviewers should take care to verify that the behavior actually is
equivalent as I believe.

# Testing

- [ ] I would like a test deployment of BitCraft to staging or
something, or to include this patch in the next bot test that we do
anyways, just for sanity's sake.
2025-07-29 18:29:04 +00:00
ResuBaka 7fb4df4275 Update tungstenite to get client read performance improvement (#2966)
Co-authored-by: Kim Altintop <kim@eagain.io>
2025-07-24 17:06:43 +00:00
Kim Altintop 09717e97ad Make websocket configurable via config.toml (#2944) 2025-07-16 19:31:07 +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
Tyler Cloutier 20b087c248 Split datastore into its own crate (#2933) 2025-07-12 21:41:00 +00:00
Kim Altintop b63216aec9 client-api: Rewrite websocket loop (#2906)
Signed-off-by: Kim Altintop <kim@eagain.io>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2025-07-10 10:50:06 +00:00
joshua-spacetime e4d5c18f3c Wrap websocket flush in timeout (#2908) 2025-07-01 01:41:59 +00:00
joshua-spacetime 28186d8721 Track disconnects initiated by the client (#2893) 2025-06-25 23:28:29 +00:00
joshua-spacetime 718712a8f7 Record the size of a client's outgoing message queue on drop (#2877) 2025-06-18 17:28:55 +00:00
Mazdak Farrokhzad 1318e7e1f5 messages::serialize: take/put buffers from/into a SerializeBufferPool (#2823)
Co-authored-by: Noa <coolreader18@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2025-06-16 16:44:57 +00:00
Phoebe Goldman 1e3e8db9bc Database-specific Timestamp route (#2864) 2025-06-13 20:23:30 +00:00
Tyler Cloutier 013e268eb5 Fixed rename by using put instead of post (#2764)
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
2025-06-12 17:05:02 +00:00
Kim Altintop 4974676ce8 client-api: Don't debug-print dropped outgoing Ws messages at info (#2819) 2025-06-11 09:23:41 +00:00
Phoebe Goldman 0866fd39d5 Add an HTTP route to get the current Timestamp (#2850) 2025-06-09 17:26:25 +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 ac187906ad Per-database incoming and outgoing queue length metrics (#2773) 2025-05-28 16:17:48 +00:00
Kim Altintop c729c2100d Reintroduce replication factor parameter (#2718) 2025-05-19 06:55:09 +00:00
Phoebe Goldman 03a56e11a2 Check validity of modules before control DB modifications during initial publish (#2580) 2025-04-14 15:56:23 +00:00
Noa 483a9488e2 Update rand (#2568) 2025-04-11 17:39:41 +00:00
Noa 68d23d4c25 Remove spacetimedb-core as a dep of cli (#2244) 2025-04-09 19:37:44 +00:00
Noa 649ce34b01 Update tungstenite to 0.26 (#2539) 2025-04-02 18:09:13 +00:00
Mazdak Farrokhzad eb380e6a18 Repair transactionality of st_client removals after disconnect (#2446)
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
2025-04-01 14:04:16 +00:00
Jeffrey Dallatezza 64aef29d3c Add endpoints for heap profiling (#2517)
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2025-03-31 18:12:31 +00:00
Mario Montoya 98395ca530 Print back the # of rows affected (ins, upd, del) with timings (#2462)
Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-03-28 16:57:23 +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
Kim Altintop e32b00420b set names atomic (#2325)
Co-authored-by: Tyler Cloutier <cloutiertyler@aol.com>
Co-authored-by: Noa <coolreader18@gmail.com>
2025-02-28 21:59:23 +00:00
Jeffrey Dallatezza 909040f716 hacky auth check for database creation. (#2308) 2025-02-26 16:52:30 +00:00
Kim Altintop 55cd1e4587 sdk: Client ping on idle connections (#2309)
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2025-02-26 16:22:42 +00:00
Tyler Cloutier d147dff5b1 Added in a SQL execution time calculation (#2297) 2025-02-25 21:44:21 +00:00
Noa f307d531a5 Fixup comment for SpacetimeCreds (#2250) 2025-02-11 20:14:32 +00:00
Noa e76ba2bd35 Only support bearer auth (#2248) 2025-02-11 18:51:05 +00:00
Noa 6a8375260f Refactor HTTP api to better adhere to REST guidelines (real) (#2243) 2025-02-11 02:59:45 +00:00
Noa cf6822541f Remove janky schema from http API (#2181) 2025-02-11 00:56:07 +00:00
Phoebe Goldman aedc601145 Rename Address to ConnectionId (#2220)
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: James Gilles <jameshgilles@gmail.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2025-02-10 00:40:16 +00:00
Piotr Sarnacki 00c6aa0baf Add /health endpoint (#1989)
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2025-02-08 19:58:14 +00:00
joshua-spacetime 6aa75bd0eb Track compute metrics for sql dml with new engine (#2190) 2025-01-31 17:59:33 +00:00
Noa 293aebaef9 Bump to Rust 1.84 (#2001) 2025-01-28 23:11:29 +00:00
Noa 7c6af12b84 Use actual types for api responses, not ad-hoc json!() objects (#1931) 2025-01-21 03:13:22 +00:00
Noa cf6ac18eaf Lookup lifecycle reducers by lifecycle flag, not by name (#2132) 2025-01-17 23:21:52 +00:00
Noa c24042609e Split binaries (#2011) 2025-01-15 18:45:14 +00:00
Zeke Foppa 43ad8be2b0 CLI - Remove deprecated use of the --project-path flag (#915)
Co-authored-by: Zeke Foppa <github.com/bfops>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2024-12-30 18:41:44 +00:00
Kim Altintop 125ab58388 commitlog: Fix set_epoch (#2005) 2024-11-21 13:34:10 +00:00
Shubham Mishra 9c64d1fbd1 Durability Provider (#1864)
Signed-off-by: Shubham Mishra <shubham@clockworklabs.io>
Co-authored-by: Kim Altintop <kim@eagain.io>
2024-11-19 09:06:52 +00:00