0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-17 10:06:58 +00:00
Commit Graph

96 Commits

Author SHA1 Message Date
15fe600c40 update tonic to 0.11 () 2024-04-11 17:54:36 +00:00
724f6db925 libsql: fix malformed db and add test ()
* add malformed db test

* continue to debug output sql

* reduce sql

* reset connection on injection

* remove println in test

* address comments
2024-04-04 18:20:17 +00:00
ef446125f7 write queue ()
* introduce connection manager

* remove unused wal methods

* remove lock stealer

* Make use of ConnectionManager in LibsqlConnection

it now takes a W: WalWrap instead of a WalManager. This is because we
want to inject the connection manager at the bottom of the wal wrapping
chain.

* add missing deps

* turn ReplicationLogger into a WrapWal

* update spots to to pass wal wrapper instead of wal manager

* remove dbg

* fmt

* fix sqlite3 rust tests
2024-03-20 22:27:13 +00:00
e154693fbd Fixed typos in replicator ()
Some more typo fixes in comments and messages.
2024-03-12 10:26:59 +00:00
1158b506e4 libsql: prepare v0.3.0 release () 2024-03-07 12:57:53 +00:00
405f605705 libsql: prevent database overwrite misuse ()
Closes 
2024-03-07 11:59:46 +00:00
9dbf604843 libsql: prefix client_wal_index file ()
* libsql: prefix client_wal_index file

* remove create_dir_all
2024-03-04 12:43:39 +00:00
62275b5bc7 Parametrize namespace creation for shared schema db ()
* initial parameters for creation of shared schema db

* store shared schema config persistently

* add StmtKind::DDL and block DDL schema changes on databases using shared schema

* Revert "add StmtKind::DDL and block DDL schema changes on databases using shared schema"

This reverts commit 5a5c0d62c91d72151a1c92309d8746116c518ad5.
2024-02-20 14:21:55 +00:00
d2fcc25094 limit row size ()
* update proto

* limit row size
2024-02-20 12:45:24 +00:00
bdb526e459 replica wait when snapshot not found () 2024-02-19 18:34:00 +00:00
c4438e0897 Make encryption cipher configurable and switch default to SQLCipher ()
* libsql: Make encryption cipher configurable

Introduce a `EncryptionConfig` struct to configure both encrytion cipher
and key. Needed to support multiple ciphers.

Fixes 

* libsql-ffi: Switch to SQLCipher as the default cipher

Fixes 
2024-02-19 15:37:42 +00:00
eb7dadd6a0 libsql: attach databases from other namespaces as readonly ()
* 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
3022908784 Fix replication bug ()
fix replicatioon bug
2024-02-12 15:38:03 +00:00
cd82068edf libsql_server,bottomless: add encryption support ()
* 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
a72c066a8e Wal related changes ()
wal extensions
2024-02-06 17:44:23 +00:00
c659eb2215 reset replica when injector detects potential corruption ()
* reset replica when injector detects potential corruption

* fmt
2024-02-02 16:33:31 +00:00
37fb629f50 run clippy () 2024-01-31 08:42:20 +00:00
e1cc9ff829 return number of committed frames on insert_frames () 2024-01-25 16:39:29 +00:00
2c0d47db61 Merge pull request from tursodatabase/checkpoint-callback
Introduce checkpoint callback
2024-01-19 16:26:16 +00:00
69a8e2da59 fmt 2024-01-19 09:33:22 +01:00
bca3f12761 update rust code for checkpoint callback
- add the checkpoint callback to Wal::checkpoint
- use dynamic dispatch for callbacks (correctness issue)
- pass `frames_in_wal` and `backfilled` as ref to `Wal::checkpoint`
  because sqlite can set them despite returning `SQLITE_BUSY`
2024-01-19 09:33:19 +01:00
e4905983a4 update proto 2024-01-18 20:50:02 +01:00
a3466b01da udeps: fix replication dependency 2024-01-16 16:44:39 +01:00
fdeb1c5a1f treewide: refactor string passphrase to vec<u8> key 2024-01-16 16:44:39 +01:00
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
9960e4e021 libsql-replication: add passphrase support
It allows registering a passphrase to enable encryption at rest
for replicas, embedded or regular.
2024-01-16 16:44:39 +01:00
089571dba9 libsql-replication: pass pager to virtual WAL interface
It wasn't needed so far, but SQLite3MultipleCiphers integration
relies on the fact that the pPager pointer is engaged
and points to the pager instance. Fortunately, it's always available,
since we inject frames by producing a dummy frame, which comes
with a proper pager pointer.
2024-01-16 16:44:39 +01:00
7358e3f78b treewide: add opt-in passphrase param for encryption at rest
You can now choose a passphrase and use it (plain text for now, sorry)
to set up an encryption-at-rest key.

Example:
cargo run -F encryption-at-rest -- --passphrase pekka
2024-01-16 16:44:39 +01:00
bb53d21c8a server: expose config version and refactor replication log 2024-01-12 12:13:36 -05:00
8d10b634d7 server: add jwt_key to database config 2024-01-11 09:42:38 -05:00
b21d23e9db server: switch to protobuf for meta store 2024-01-11 09:40:05 -05:00
7992ae11c8 replication: add config to handshake 2024-01-09 16:19:22 -05:00
7902fadbd9 libsql: final prep for libsql release 2024-01-08 15:04:13 -05:00
5690150e1b libsql: add cargo toml info for replication crate 2024-01-08 10:11:01 -05:00
88217e43a1 send commit timestamp to replicas to compute replication latencies 2023-12-26 11:17:10 +01:00
971dbb842a add timestamp to replication protocol 2023-12-26 11:16:16 +01:00
17f5135923 fix missig feature in libsql-replication 2023-12-26 11:14:52 +01:00
6b0a8a3033 libsql: improve failed handshake error message 2023-12-18 16:10:53 -05:00
3286992d35 prevent checkpoint on WAL close for InhibitCheckpointWal 2023-12-11 16:04:28 +01:00
89e595d12b migrate from bytemuck to zerocopy 2023-12-05 17:51:38 +01:00
ae9daa8b74 Use NonZeroU32 for frame_no and page_no 2023-12-05 09:20:44 +01:00
17acd27aa4 treewide: apply clippy
... so that it spams less hints when run locally.
2023-12-04 16:31:36 +01:00
fef697834c fmt 2023-11-30 11:27:13 +01:00
49b11abce0 homogenise rust wal naming 2023-11-30 11:26:49 +01:00
05f6d47643 make pager's wal a pointer 2023-11-30 11:26:44 +01:00
ff53bcbc57 rename libsql_create_wal to libsql_wal_manager 2023-11-30 11:25:22 +01:00
f2a14deb6d rename Header::as_ptr to Header::as_mut_ptr 2023-11-30 11:24:49 +01:00
a59d4388cf remove replication legacy wal hooks 2023-11-30 11:24:49 +01:00
2a407d3b06 introduce InjectorWal 2023-11-30 11:24:49 +01:00
ad01831821 make all crates depend on libsql-sys 2023-11-30 11:24:49 +01:00