Commit Graph

6768 Commits

Author SHA1 Message Date
Pekka Enberg
b7cb4a3ed4 core/mvcc: Switch to parking_lot RwLock 2025-07-30 20:25:45 +03:00
Pekka Enberg
951bebfac3 Merge 'Add vector_concat and vector_slice support' from bit-aloo
Closes: #2323
This PR adds support for two new vector functions:
* vector_concat(x, y) – Concatenates two vectors of the same type.
* vector_slice(x, start_index, end_index) – Extracts a subvector from
the input vector.
Notes:
* Negative start_index or end_index is not supported

Reviewed-by: Nikita Sivukhin (@sivukhin)

Closes #2336
2025-07-30 16:58:38 +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
bit-aloo
a828b9f29b add start > end condition and corresponding test 2025-07-30 14:49:11 +05:30
bit-aloo
bf58ede567 make vectortype copy and cloned variant's accordingly 2025-07-30 14:28:15 +05:30
bit-aloo
44707495b9 add more test covering the edge cases 2025-07-30 14:19:37 +05:30
bit-aloo
6f45cb9770 update vector slice to adhere to start..end and not start, length 2025-07-30 14:10:43 +05:30
bit-aloo
c546261010 update as_int to return Option, instead of panicking. Update vector_slice and vector_concat accordingly 2025-07-30 13:54:55 +05:30
bit-aloo
96a99ca48a rename subvector to vector_slice 2025-07-30 13:34:49 +05:30
Nikita Sivukhin
b78ce17022 properly configure TLS and use default features for rustls/hyper-rustls deps 2025-07-30 11:47:36 +04:00
Pekka Enberg
2eed2745d3 Merge 'Change more function signatures to return Completions' from Pedro Muniz
Closes #2330
2025-07-30 10:42:45 +03:00
Pekka Enberg
2443b8db3c Merge 'bindings/rust: Add Connection::execute_batch()' from Rohith Suresh
Fixes #2184

Closes #2215
2025-07-30 10:19:03 +03:00
Pekka Enberg
81c86d42b4 Merge 'Clean up conversion between InsnFunctionStepResult and StepResult' from Diego Reis
Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #2332
2025-07-30 09:11:35 +03:00
Pekka Enberg
9ab26b3ac2 Merge 'core/mvcc: simplify mvcc cursor types' from Pere Diaz Bou
We have so many cursor types that it will be unbearable to properly make
all of them work. Let's simplify this and only focus on lazy cursor
which in the future will load from database in case we need it.

Closes #2333
2025-07-30 09:10:44 +03:00
bit-aloo
b5d46803b5 update compact.md with vector concat and subvector listings 2025-07-30 09:51:08 +05:30
bit-aloo
a5dce2b50b add subvector execution flow 2025-07-30 09:51:08 +05:30
bit-aloo
24c260a05f add as int method in Value 2025-07-30 09:51:07 +05:30
bit-aloo
c8ba6a7d49 update subvector implementation to make handle out of bound cases correctly and correctly parse the vector 2025-07-30 09:51:03 +05:30
bit-aloo
e4d79a6516 add vec_concat execution flow 2025-07-30 06:07:03 +05:30
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
Nikita Sivukhin
7481573cf1 add test to the DatabaseTape 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
4269a1fe7a add helper WalSession RAII-wrapper 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
e0aeb032f0 add sync server module 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
241cad65cd add filesystem module 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
da287f84b1 add blocking implementation of filesystem for tests 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
904eef7628 add tokio-based implementation of filesystem 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
649cc3f367 add local implementation of sync server for tests 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
9c5a849f19 add implementation of TursoSyncServer 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
949801951e add local database metadata 2025-07-30 00:58:36 +04:00
Nikita Sivukhin
db2f8fa61c add TestContext in order to simplify fault injection 2025-07-30 00:58:36 +04:00
Pere Diaz Bou
caa5fe3ef4 core/mvcc: simplify mvcc cursor types
We have so many cursor types that it will be unbearable to properly make
all of them work. Let's simplify this and only focus on lazy cursor
which in the future will load from database in case we need it.
2025-07-29 20:13:52 +02:00
Diego Reis
e0b099f5ad refactor: Implement conversion between InsnFunctionStepResult and
StepResult
2025-07-29 15:02:09 -03:00
bit-aloo
5a0622b937 add test for subvector method 2025-07-29 23:12:19 +05:30
bit-aloo
cae4ead606 add vector concat test 2025-07-29 23:10:48 +05:30
bit-aloo
0e6708575d add vector subvector method 2025-07-29 22:58:08 +05:30
bit-aloo
3ca87a823f add vector concat method 2025-07-29 22:57:49 +05:30
pedrocarlo
a1c5a6efae begin_sync should return a Completion 2025-07-29 13:40:58 -03:00
pedrocarlo
9c4ce745ba wait_for_completion was not implemented for MemoryIO and VFS 2025-07-29 13:23:45 -03:00
Pekka Enberg
d72ba0c153 Merge 'bindings/java: Throw UnsupportedOperationException for unimplemented …' from Pekka Enberg
…methods

Closes #2329
2025-07-29 19:07:51 +03:00