0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-17 14:46:55 +00:00
Commit Graph

54 Commits

Author SHA1 Message Date
2b9ad5ccbc server: fix stats sending performance and ns creation ()
* server: create debug logging

* server: fix stats sending performance

This change fixes how we send stats to the pulse server. This is done by
not serially sending stats on the same task that we extract events from.
The reason for this is that if the event buffer (stats_sender) gets full
it will block namespace create requests.

With this change, we now submit stats http requests off the main stats
task and restrict the stats sending to 128 concurrent requests. This
will allow us to accept more create namespace requests and efficiently
send stats.
2024-06-04 17:10:35 +00:00
5021f9fb0c add session_token for AWS short-term credentials ()
Co-authored-by: Ryan Dsouza <r.dsouza@newmotion.com>
2024-05-29 13:23:23 +00:00
1093eaf16b fix metastore deadlock ()
* non-blocking is_snapshotted

* prevent infinite blocking in bottomless wal

* finer grained locking in meta store to prevent deadlock

* review edits
2024-05-17 16:13:02 +00:00
e37b644395 libsql-wal: SealedSegment ()
* add libsql-wal crate

* add error module

* segment module, header structs on helper functions

* sealed log

* add missing deps

* silence warnings

* segment list

* fmt

* fix lockfile

* fix bottomless because of conflict on cargo.lock

* document db size

* fix typo in comment

* fix proto
2024-04-26 11:10:54 +00:00
67eae4c461 bottomless: upgrade s3 sdk to 1.0 ()
* bottomless: upgrade s3 sdk to 1.0

* fix behavior version
2024-04-10 23:13:15 +00:00
45920ed30a bottomless: emit restored snapshot for waiters ()
This fixes an issue where a db gets restored from bottomless and doesn't
get any writes until shutdown. At this point, the current generation is
the same as the restored one but the graceful shutdown process expects
to wait for that generation to be uploaded which never happens because
there are no writes. This change adds a snapshot generation emit call at
restore time to allow graceful shutdown to happen when there are no
writes without having to checkpoint and upload a new snapshot.
2024-03-22 20:57:10 +00:00
56e3fe23ac write queue cleanup () 2024-03-21 12:21:03 +00:00
427421b9f3 Bottomless skip snapshot ()
* skipp inject_replication_index on checkpoint

* bottomless: LIBSQL_BOTTOMLESS_SKIP_SNAPSHOT param

* restore required when generation is empty but dependency exists

* add tracing, limit busy handler retries

---------

Co-authored-by: ad hoc <postma.marin@protonmail.com>
2024-03-21 10:13:09 +00:00
3de73ef356 Namespace::destroy: add parameter to perform soft delete (preserve backup) ()
* Namespace::destroy: add parameter to perform soft delete (preserve backup)

* make sure that log statement won't panic
2024-03-13 11:14:45 +00:00
aa2490cd36 Bottomless savepoint ()
* bottomless: added ability to wait for uploaded frames without shutting down

* bottomless: savepoint tracker

* expose bottomless backup savepoint through PrimaryDatabase API

* tests for detached progression updates in bottomless progression tracker

* bottomless: reset savepoint tracker on new generation

* bottomless: expose savepoint tracker on PrimaryDatabase
2024-03-04 09:51:48 +00:00
52619b4deb fix bottomless bugs () 2024-02-21 14:33:06 +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
71a7cfc727 chore: fix feature flags for encryption () 2024-02-12 20:36:28 +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
e1cc9ff829 return number of committed frames on insert_frames () 2024-01-25 16:39:29 +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
ded615ba53 fmt 2023-12-21 18:38:44 +01:00
93fc274648 use WrapWal for bottomless wal 2023-12-21 17:54:52 +01:00
51de23b04b namespace: add bottomless checks in exists()
Even if the namespace doesn't exist locally, it might have a functional
backup.
2023-12-19 09:55:02 +01:00
63a90bfe8e Update bottomless documentation 2023-12-17 13:12:05 +05:30
0e025264b2 fix missing commit frame on local_client inject from snapshot 2023-12-13 13:18:07 +01:00
2167bed5e8 Merge pull request from tursodatabase/prevent-checkpoint-on-close
prevent checkpoint on WAL close for InhibitCheckpointWal
2023-12-12 19:20:08 +00:00
3286992d35 prevent checkpoint on WAL close for InhibitCheckpointWal 2023-12-11 16:04:28 +01:00
35e351471c Trim env keys and set to None if empty 2023-12-07 15:37:57 +05:30
e4ded4f64f bottomless db snapshot: add more logging 2023-12-06 20:13:59 +09:00
ae9daa8b74 Use NonZeroU32 for frame_no and page_no 2023-12-05 09:20:44 +01:00
0197fd4154 Apply suggestions from code review
Co-authored-by: ad hoc <postma.marin@protonmail.com>
2023-12-01 09:00:10 -05:00
29bb970559 sqld: add in process s3 for bottomless tests
This adds in process mock s3 backend via the `s3s` crate. This allows us
to run tests without requiring a user run `minio` or hook up their real
aws account.
2023-11-30 17:42:01 -05:00
85279bdaf3 Merge pull request from tursodatabase/wal-hook-v2
WallHook v2
2023-11-30 10:46:51 +00:00
05f6d47643 make pager's wal a pointer 2023-11-30 11:26:44 +01:00
e1a912c3c9 post-rebase fixes 2023-11-30 11:25:49 +01:00
ff53bcbc57 rename libsql_create_wal to libsql_wal_manager 2023-11-30 11:25:22 +01:00
4c982346fb remove Deref impl for BottomlessWal 2023-11-30 11:24:52 +01:00
ba3721368c remove bottoless legacy WAL code 2023-11-30 11:24:49 +01:00
320855c1f4 introduce BottomlessWal 2023-11-30 11:24:49 +01:00
ad01831821 make all crates depend on libsql-sys 2023-11-30 11:24:49 +01:00
436dc9e9b8 bottomless shutdown: don't drop channel used by completion notifiers 2023-11-30 15:45:26 +09:00
1475e9fe4b bottomless shutdown: drop flush trigger to complete complete WAL copier loop 2023-11-29 20:30:32 +09:00
ef00da6739 bottomless: add method to wait for all background tasks to complete 2023-11-29 20:12:45 +09:00
78db3721c4 fix(release): mark other packages as dist=false 2023-11-17 08:43:09 -06:00
1151955e8a fix(manifest): update and/or comment out Cargo.toml repo keys 2023-11-17 08:42:27 -06:00
0c631155c7 bottomless/backup: do not cache WAL file descriptor
... because we end up reading stale data. The WAL file is recreated
after a TRUNCATE-level checkpoint and a new one is open, while we keep
reading from the old one, kept alive by the descriptor.

Fixes 
2023-11-14 13:07:32 +01:00
6ac769eb48 bottomless: make WAL checksums work across matching endianness
This is a partial fix to  - it makes the checksumming
work as long as it's produced and checked on an arch with matching
endianness. Most of modern machines, including the ones we run on
our platform, CI, and home devices are just little endian anyway.
The proper fix is to also store the checksum computation endianness
in our .meta file, just like SQLite stores it in the WAL header,
but that's not implemented yet.

Tested locally.
2023-11-14 11:24:39 +01:00
4a71b2072a bottomless-cli: add restoring from a directory
Convenience function for manual restoration.
2023-11-09 12:17:15 +01:00
3aa0955768 Make s3 retry op configurable and set default to 10 2023-10-31 14:50:08 +05:30
a9481c8326 remove unused deps 2023-10-30 17:26:20 +01:00
acda80301a bottomless: switch to zstd as default
Gzip does not perform well on data in form of libSQL 4KiB pages,
and zstd performed uniformly better in all test cases I covered
locally (and not worse in case of random data with super high entropy).
2023-10-18 11:17:11 +02:00
6f96daa955 bottomless: actually, add zstd
During stress tests, xz turned out to spontaneously fail to compress,
same with bzip2. All compression algos are supported by separate
crates, so these were simply ruled out.
Zstd proved to be:
 - fast
 - correct
 - more than acceptable on compression ratio
2023-10-18 11:08:51 +02:00