0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-08-14 01:22:58 +00:00
Commit Graph

127 Commits

Author SHA1 Message Date
ad hoc
0d5dc18ce1 rename migration tables (#1200)
* rename __libsql_migration_tasks to sqlite3_libsql_tasks

* rename job tables
2024-03-13 11:03:55 +00:00
ad hoc
b9ab41c485 ignore legacy auth when new auth is present (#1192) 2024-03-13 06:30:53 +00:00
ad hoc
c79cec3ee2 move migration api to user api (#1198) 2024-03-12 20:09:07 +00:00
ad hoc
a95bdf4d35 job status notifier & wait for dry run success (#1197) 2024-03-12 19:55:41 +00:00
ad hoc
153c8382d8 remove broken test (#1199) 2024-03-12 18:00:30 +00:00
Bartosz Sypytkowski
d945d41566 Hrana: don't close the stream at the end of prepared statement execution (#1185)
* Hrana: don't close the stream at the end of prepared statement execution

* hrana stream and transaction: check for tokio runtime existence on drop

* standalone::execute_transaction test: raise simulation duration

* hrana: added comments to conditions for stream closing

* hrana: added comments to conditions for stream closing
2024-03-12 11:57:07 +00:00
ad hoc
fe2ebffe28 check schema migration auth (#1191) 2024-03-11 17:09:43 +00:00
ad hoc
5ece28f4fe gid tag token claim (#1190) 2024-03-11 16:14:52 +00:00
ad hoc
1528128fce allow ddl override (#1187) 2024-03-11 15:00:26 +00:00
ad hoc
998d330428 extend test timeout (#1182) 2024-03-09 11:39:39 +00:00
Avinash Sajjanshetty
226fba9a12 Add tests for data migration in schema dbs (#1176)
- Added a test which performs data migration including
  inserts, updates and deletes
- Added a test which shows that schema migration fails
  if there is any conflicting data in the linked dbs
2024-03-08 16:11:26 +00:00
Avinash Sajjanshetty
ae708f8952 Fork a new DB when creating from shared schema (#1154)
* Fork a new DB when creating from shared schema

* Use the correct db type to get the wal logger

* Add a test for a new db in shared schema

- When a new db is created with a shared schema, it should have
  the same schema and the schema version
- When a new migration is done, the new db and all the existing
  dbs should have the same schema and version

* Move schema db fork logic inside namespace mod

* clean up and remove unnecessary store call
2024-03-08 14:32:22 +00:00
ad hoc
c9ba69245e Handle dry run failure, and abort migration (#1163)
* test snasphots

* add test

* handle dry run failure, and abort all tasks

* fmt
2024-03-08 11:01:32 +00:00
Avinash Sajjanshetty
73909accf6 Update tests to check if all schema versions are same (#1170) 2024-03-08 08:58:27 +00:00
Lucio Franco
405f605705 libsql: prevent database overwrite misuse (#1153)
Closes #1145
2024-03-07 11:59:46 +00:00
ad hoc
bf19f3e1d7 reject migration containing migration statements (#1149) 2024-03-06 18:12:45 +00:00
ad hoc
75321d56d3 use custom query builder to collect migration error (#1146)
use custom query builder to collect migration error
2024-03-06 15:31:46 +00:00
Piotr Jastrzębski
8f897d510e Block writes during schema migration (#1139)
* Add block_writes to Connection

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* Add block_writes to PrimaryDatabase

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* Use block_writes in Connection::run

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* Unblock writes once migration is finished

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* Block writes on startup if there are pending migration tasks

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* Block writes when a migration task is enqueued

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* twix

---------

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
Co-authored-by: ad hoc <postma.marin@protonmail.com>
2024-03-05 22:17:36 +00:00
Pekka Enberg
4e0ce557a8 libsql: Rename periodic_sync to sync_interval (#1125)
Rename the configuration option for periodic sync to `sync_interval` to
align with what we're doing with the rest of the SDKs.
2024-03-05 19:05:46 +00:00
Bartosz Sypytkowski
bb1dd03748 Migrations status admin api (#1134)
* added an endpoint to ask for a general migration status

* return detailed information about individual migration job progress

* integrated migrations API in tests

* post-rebase

* adjusted code after rebase
2024-03-05 16:20:30 +00:00
Pekka Enberg
6b13d77519 libsql: Deasyncify some Conn trait methods (#1135)
There's no reason to have `is_autocommit()`, `changes()` or
`last_insert_row()` methods async because they're all fully local and
cannot block. Deasyncify them.
2024-03-05 13:44:53 +00:00
ad hoc
50648a6b4b prevent task enqueue when pending task (#1131)
check for already enqueued job for schema + migrate schema db ops to
schema module.
2024-03-05 10:31:06 +00:00
Piotr Jastrzębski
1826582133 Embedded replicas encryption test (#1124)
* Embedded replicas encryption test

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* Fix encryption embedded replica test

* ci: add encryption tests

* add clean cipher build dir

---------

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
2024-03-04 16:09:02 +00:00
ad hoc
2b06b6b7d8 schema migration (#1110)
happy path schema migration
2024-03-04 13:15:29 +00:00
Avinash Sajjanshetty
612aae4277 server: trim quotes in namespace string in attach statement (#1117)
* Add a regression test when UUIDs are used in attach
statements

Also, added a test to check if the UUID is wrapped
in quotes

* bugfix: trim namespace string if it is wrapped in quotes

the client might send namespace wrapped in quotes in case of uuids,
so we will just trim the string.
2024-03-01 15:08:01 +00:00
ad hoc
adf36104ad fix bad attach name (#1113)
* add test

* fix auth using attach alias instead of target
2024-02-29 14:15:43 +00:00
Piotr Jastrzębski
4b2732c5e2 Go: Reset connection when it's returned to a pool (#1100)
* Make all methods of Conn trait async

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

* C bindings: Add libsql_reset

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>

---------

Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
2024-02-29 10:09:07 +00:00
ad hoc
16c6e40335 fix auth malformed token (#1102)
* add tests

* allow legacy tokens with no perm claims

* fmt
2024-02-28 14:16:27 +00:00
ad hoc
52d8b8f1c4 Multi-scopes auth & Attach fix (#1076)
* test snapshots

* allow multi-scope auth

* hors-sujet: fix C compile warning

* update jwt and add hashbrown feature

* replace Auth with RequestContext

* extract RequestContext

* fix auth check for multi-scopes

* pass NamespaceName in StmtKind::Attach

* fallback to global auth if key is not set in ns config

* add allow_attach to namespace creation

* return meta store from namespace store

* test attach

* fmt

* review edits
2024-02-26 13:56:20 +00:00
Piotr Sarna
eb7dadd6a0 libsql: attach databases from other namespaces as readonly (#784)
* libsql: attach databases from other namespaces as readonly

With this proof-of-concept patch, other namespaces hosted
on the same sqld machine can now be attached in readonly mode,
so that users can read from other databases when connected
to a particular one.

* connection: add allow_attach to config

Default is false, which means connections are blocked from attaching
databases. If allowed, colocated databases can be attached in readonly
mode.

Example:
→  attach another as another; select * from another.sqlite_master;
TYPE      NAME     TBL NAME     ROOTPAGE     SQL
table     t3       t3           2            CREATE TABLE t3(id)

* libsql,namespaces: add client-side ATTACH support

* attach: support ATTACH x AS y aliasing

We're going to need it, because the internal database names in sqld
are uuids, and we don't expect users to know or use them.

* attach: fix quoted db names

In libsql-server, raw db names are uuids that need to be quoted,
so that needs to be supported in the ATTACH layer.
As a bonus, "names" that are actually file system paths are refused
to prevent abuse.

* libsql-server: drop stray serde(default) from allow_attach

* libsql-replication: update proto files

* libsql-replication: regenerate protobuf

* tests: move attach to its own test

* libsql-replication: fix proto number after rebase
2024-02-14 10:41:45 +00:00
Piotr Sarna
cd82068edf libsql_server,bottomless: add encryption support (#928)
* namespace,replication: add LogFile encryption

Anything that uses our LogFile format can now be encrypted
on-disk.
Tested locally by seeing that `wallog` file contains garbage
and no sensible plaintext strings can be extracted from it.

* test fixups

* libsql-ffi: add libsql_generate_initial_vector and...

... libsql_generate_aes256_key to make them reachable from Rust.

* connection: expose additional encryption symbols

* libsql-server: derive aes256 from user passphrase properly

And by properly, I mean calling back to SQLite3MultipleCiphers' code.

* replication: rename Encryptor to FrameEncryptor

Encryptor sounds a little too generic for this specific use case.

* replication: add snapshot encryption

It uses the same mechanism as wallog encryption, now abstracted
away to libsql-replication crate to be reused.

* replication: add an encryption feature for compilation

* cargo fmt pass

* fix remaining SnapshotFile::open calls in tests

* logger: add an encryption test

* replication: use a single buffer for encryption

Ideally we could even encrypt in place, but WalPage is also
used in snapshots and it's buffered, and that makes it exceptionally
annoying to explain to the borrow checker.

* bottomless: restore with libsql_replication::injector

... instead of the transaction page cache. That gives us free
encryption, since the injector is encryption-aware.

This patch doesn't hook encryption_key parameter yet, it will
come in the next patch.

* bottomless: pass the encryption key in options

For WAL restoration, but also to be able to encrypt data that gets
sent to S3.

* bottomless: inherit encryption key from db config if not specified

* libsql-sys: add db_change_counter()

The helper function calls the underlying C API to extract
4 bytes from offset 24 of the database header and return it.
It's the database change counter, which we can use to compare
two databases and decide which one is newer than the other.

* bottomless: use sqlite API to read database metadata

With encryption enabled, we can no longer just go ahead and read data
from given offsets, we must go through the VFS layer instead.
Fortunately, we can just open a database connection and ask for all
the metadata we need.

* libsql-sys: make db change counter actually read from the db file

* bottomless: treat change counter == 1 as a new database

... which it is, after setting the journal mode. Otherwise we decide
too eagerly that the local database is the source of truth.

* libsql-server: fix a local embedded replica test

rebase conflict with encryption

* bottomless-cli: allow passing the encryption key

* replication: rebase new test to the new api

* snapshots: do not try to decrypt headers

They are not encrypted, so we shouldn't attempt to decrypt the data.

* logger: restore encrypted frames during recovery

Instead of decrypting and encrypting back, we just copy encrypted
frames as is during the recovery process, saves IO.

* compaction: clear unused encryption_key parameter

It wasn't used since for compaction we only need headers,
which are unencrypted.

* replication: switch to FrameBorrowed::new_zeroed

Following MarinPostma's suggestion.

Co-authored-by: Marin Postma <postma.marin@protonmail.com>

* replication: rebase chores, fixing parameters

* libsql-replication: use page_mut() to decrypt data in-place

* rustfmt

* bottomless: use 0 for disabling autocheckpoint

... instead of u32::MAX. Effectively it's similar, but 0 is the correct
choice.

* rustfmt

* libsql-server: make cbc, aes optional for encryption only

* post-rebase fixes

* libsql-replication: suppress warnings when no encryption

* libsql: add encryption support for local databases

* libsql: add bytes dependency for encryption

* libsql-ffi: build libsqlite3mc without debug symbols

Technically it should just depend on cargo build mode,
but that's left for a follow-up.

* bindings: an attempt to compile bindings with releasemode

... partially to save space, but also to make them faster.

---------

Co-authored-by: Marin Postma <postma.marin@protonmail.com>
2024-02-09 14:27:39 +00:00
Lucio Franco
aeb32c299b libsql: add embedded replica freeze mode (#997) 2024-02-07 18:07:41 +00:00
Lucio Franco
c18caa49e6 libsql: add periodic background sync (#995)
This adds a new periodic sync configuration item to the `Builder` that
will allow users to set a duration at which they want the background
sync to sync.
2024-02-07 08:39:06 +00:00
Lucio Franco
954029e31f libsql: add Builder to construct the db (#993)
This adds a new `Builder` type that can now be used to construct the
`Database` type. This will scale better as we add more varied options.
This commit also deprecates the old builder types and will produce a
warning that will push users to using the new `Builder` type. This will
then allow us to remove the old deprecated constructors at some point in
the future.
2024-02-06 13:59:11 +00:00
ad hoc
c659eb2215 reset replica when injector detects potential corruption (#947)
* reset replica when injector detects potential corruption

* fmt
2024-02-02 16:33:31 +00:00
Bartosz Sypytkowski
9183998374 libsql client: don't reset last_insert_rowid (#966) 2024-02-02 14:59:23 +00:00
ad hoc
37fb629f50 run clippy (#971) 2024-01-31 08:42:20 +00:00
Bartosz Sypytkowski
6f67c65a40 Consolidate Hrana proto definitions in one source (#939)
* Hrana HttpConnection: use shared Hrana stream

* added is_autocommit flag setup during execute requests

* post-rebase fixes

* Hrana HttpConnection: use shared Hrana stream

* added is_autocommit flag setup during execute requests

* halfway

* deduplicated transaction scope counting

* applied changes on wasm connection

* moved the remaining proto definitions

* fixed libsql-sys feature issues
2024-01-29 11:56:07 +00:00
Bartosz Sypytkowski
ac6bf3a4a9 Libsql query multi-statements string (#902)
* Hrana HttpConnection: use shared Hrana stream

* added is_autocommit flag setup during execute requests

* Hrana client: enable passing multi-statement queries

* post-rebase fixes
2024-01-26 12:30:23 +00:00
Lucio Franco
45b609c163 server: add embedded replica usage stats (#946)
* server: add embedded replica usage stats

* add test for embedded replica stats
2024-01-26 09:03:26 +00:00
Lucio Franco
975646e034 libsql: add local sync write delegation (#940)
* libsql: add local sync write delegation

* add additional query check to local sync test
2024-01-24 20:39:04 +00:00
Bartosz Sypytkowski
080d1114cc stop swallowing errors 2024-01-23 07:09:30 +01:00
Bartosz Sypytkowski
522e90b556 conditional stream close on non-transactional executes 2024-01-23 07:09:30 +01:00
Bartosz Sypytkowski
20323aa898 adjusted tests 2024-01-23 07:09:30 +01:00
Bartosz Sypytkowski
1ab40778cc added is_autocommit flag setup during execute requests 2024-01-23 07:09:30 +01:00
Bartosz Sypytkowski
5a15ee014c Hrana HttpConnection: use shared Hrana stream 2024-01-23 07:09:28 +01:00
Piotr Sarna
ce3da312df namespaces: more quoting fixes 2024-01-19 08:22:57 +01:00
ad hoc
0c93c5f11a Merge pull request #798 from Horusiath/libsql-cursor-new-api
Libsql client: introduce async row fetcher
2024-01-17 10:31:45 +00:00
Piotr Sarna
da21747012 treewide: huge un-featurization
The passphrase parameter is now unconditional, we just don't use it
if not applicable.
2024-01-16 16:44:39 +01:00
Piotr Sarna
fc819a7fd4 embedded_replica/tests: same 2024-01-16 16:44:39 +01:00