Commit Graph

78 Commits

Author SHA1 Message Date
PThorpe92
84ffed709a Round up allocation for wal frame arena to next page multiple of 64 2025-08-08 10:55:29 -04:00
Pekka Enberg
81da795a66 Turso 0.1.4-pre.6 2025-08-08 16:50:24 +03:00
Nikita Sivukhin
d2a8162e10 sync bootstrapped files in the end 2025-08-08 16:40:29 +04:00
Nikita Sivukhin
2ccdafd2a5 update sync engine wrapper 2025-08-08 16:40:19 +04:00
Nikita Sivukhin
3f0162307f configure cargo for napi-rs 2025-08-08 15:45:05 +04:00
Nikita Sivukhin
d25acf3c2c small adjustments in the sync engine js 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
ca20af6f89 fix package.json 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
4595d5b7a3 fix Cargo.toml 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
50588c5edf cargo fmt 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
572a910c52 add simple example 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
3c181939ad adjust js package 2025-08-08 15:44:42 +04:00
Nikita Sivukhin
e6a3ee59d2 turso-sync-js package 2025-08-08 15:44:41 +04:00
Nikita Sivukhin
405e7f56a6 small adjustments in the sync-engine 2025-08-08 15:40:57 +04:00
Pekka Enberg
b603ee7062 Merge 'JavaScript improvements' from Pekka Enberg
Closes #2467
2025-08-07 14:01:07 +03:00
Nikita Sivukhin
bfacc141b0 remove unnecessary change 2025-08-06 22:09:29 +04:00
Nikita Sivukhin
ae0dff6a55 cargo clippy --tests --fix 2025-08-06 22:09:29 +04:00
Nikita Sivukhin
09daa97150 format fixes 2025-08-06 21:53:03 +04:00
Nikita Sivukhin
b1f1526673 add DB file for tests 2025-08-06 21:47:18 +04:00
Nikita Sivukhin
253b4933f7 more small fixes 2025-08-06 19:30:16 +04:00
Nikita Sivukhin
1763e9bbf9 small fixes 2025-08-06 19:26:55 +04:00
Nikita Sivukhin
b612259a3a more friendly copmletely runtime agnostic turso-sync-engine crate 2025-08-06 19:26:55 +04:00
Pekka Enberg
53acd22950 serverless: Fix Statement.all() in expanded mode 2025-08-06 09:22:35 +03:00
Pekka Enberg
2a36d133e3 serverless: Improve pragma() after close() error 2025-08-06 09:09:47 +03:00
Pekka Enberg
c9cec67d94 serverless: Improve exec() after close() error 2025-08-06 08:08:19 +03:00
Pekka Enberg
f53adab4a8 serverless: Improve error when prepare() called after close() 2025-08-06 07:50:12 +03:00
Nikita Sivukhin
d504f9b1ac fix turso-sync tests 2025-08-06 01:03:49 +04:00
Nikita Sivukhin
2e23230e79 extend raw WAL API with few more methods
- try_wal_watermark_read_page - try to read page from the DB with given WAL watermark value
- wal_changed_pages_after - return set of unique pages changed after watermark WAL position
2025-08-04 16:55:50 +04:00
Nikita Sivukhin
83b1e99a61 fix compilation 2025-08-04 12:53:07 +04:00
Nikita Sivukhin
0adb40534c hind dangerous methods behind conn_raw_api feature 2025-08-04 12:40:28 +04:00
Pekka Enberg
29688e69d1 serverless: v0.1.1 2025-08-01 15:56:39 +03:00
Pekka Enberg
47860b6df5 serverless: Fix bind parameters 2025-08-01 14:21:04 +03:00
Pekka Enberg
335d4a19c8 serverless: Implement Statement.raw() 2025-08-01 14:19:54 +03:00
Pekka Enberg
86581197bf serverless: Fix Statement.get() to return undefined
...aligns with the native bindings semantics.
2025-08-01 14:01:44 +03:00
Pekka Enberg
9bd053033a serverless: Fix Connection.run() implementation 2025-07-30 21:42:45 +03:00
Pekka Enberg
fff7bf52f3 serverless: Add support for named parameters 2025-07-30 21:42:45 +03:00
Pekka Enberg
1b8d95a79f serverless: Implement Connection.close() 2025-07-30 21:42:45 +03:00
Pekka Enberg
d0f57584ad Merge 'turso-sync: bidirectional sync for local db' from Nikita Sivukhin
This PR introduces initial protocol for bidirectional sync with conflict
resolution.
The main addition to the usual `Database` interface are two methods:
1. `push` - push all local changes to the remote. Note, that new changes
from the remote will not be visible during request execution after this
procedure.
2. `pull` - pull all remote changes and apply them locally. Note, that
this procedure require temporary block of writes to the local DB as
internally we will manipulate with opened connections and juggle with
few things under the hood.
## Limitations
* Current implementation exposes only query methods on top of the
**database** - because more careful orchestration will be needed when we
will expose `Connection` and `Statement`
* Schema changes are possible to make through synced Database - but they
are actually not synced to the remote
* Current implementation will amplify storage use by 2x
## Implementation overview
Current approach uses pretty stupid idea to maintain 2 copies of the
database and WAL files:
1. `Draft` - this copy will hold local changes and accept all writes
made to the database
2. `Synced` - this copy will hold DB file and WAL synced with remote
This obviously lead to 2x space amplification, but allow us to implement
sync with conflict resolution without changing `turso-core`.
Under the hood, implementation of main operations looks like this:
1. `push`:
  a. Pull all recent changes from the remote to `Synced` DB
  b. Transfer local changes from `Draft` to `Synced` with the help of
CDC table
  c. Push new WAL frames from `Synced` DB to remote
2. `pull`:
  a. Pull all recent changes from the remote to `Synced` DB
  b. Transfer local changes from `Draft` to `Synced` with the help of
CDC table
  c. Copy `Synced` files (DB and WAL) to the `Draft`
  d. Reset `Synced` WAL in order to remove frames made by local changes
from it
As operation 2.c can't be made safely without extra work - `turso-sync`
package internally maintains `active` database which can be either
`Draft` or `Synced` and switch will happen exactly before/after step 2.c
as we will need to move all requests from `Draft` DB to `Synced` due to
explicit copy which we will need to perform.
This switch between Databases creates additional troubles and that's why
in this PR only `Database::query` and `Database::execute` methods are
exposed without prepared statements.
<img width="2062" height="977" alt="Untitled-2025-07-14-1259"
src="https://github.com/user-
attachments/assets/64eb5046-d7cb-4af2-87a0-810c0db7eeb5" />
<img width="2062" height="977" alt="Untitled-2025-07-14-1259(1)"
src="https://github.com/user-
attachments/assets/5c20360c-41db-4100-b0ff-9e47c2682e56" />

Closes #2334
2025-07-30 16:54:21 +03:00
Nikita Sivukhin
f3da874fd5 fix clippy 2025-07-30 14:38:29 +04:00
Nikita Sivukhin
aad0460bd1 rename methods 2025-07-30 14:23:18 +04:00
Nikita Sivukhin
16ed251cc5 remove turso_assert 2025-07-30 14:18:47 +04:00
Nikita Sivukhin
2b5dbba2df set tokio_unstable cfg at workspace root
- cargo commands invoked from workspace root do not capture custom configuration of RUSTFLAGS
  from workspace members
- see relevant issue https://github.com/rust-lang/cargo/issues/7004
2025-07-30 14:13:41 +04:00
Nikita Sivukhin
b78ce17022 properly configure TLS and use default features for rustls/hyper-rustls deps 2025-07-30 11:47:36 +04:00
Nikita Sivukhin
d341ac1d10 fix clippy 2025-07-30 02:10:18 +04:00
Nikita Sivukhin
979299d5b7 add binary asset 2025-07-30 01:56:57 +04:00
Nikita Sivukhin
7cf296c7ab update deps 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
63968ff522 add simple example 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
f08417af6c add lib 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
43bbc34455 add public interface for synced database 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
fedecd8e60 add main implementation of synced database 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
a47582c62b add more errors specific to sync 2025-07-30 00:58:36 +04:00