* 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.
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.
* 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
* libsql: Make encryption cipher configurable
Introduce a `EncryptionConfig` struct to configure both encrytion cipher
and key. Needed to support multiple ciphers.
Fixes#951
* libsql-ffi: Switch to SQLCipher as the default cipher
Fixes#893
* 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>
- 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`
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.
... 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#598
This is a partial fix to #598 - 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.
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).
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