0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-05-31 10:32:43 +00:00

98 Commits

Author SHA1 Message Date
68d5000f9f Make libsql-ffi workspace dependency () 2025-03-20 11:54:11 +00:00
04362acf6d Add libsql-ffi to workspace depedencies 2025-03-20 13:38:11 +02:00
687d23eb1a fix(libsql-sys): support non-Unix when rusqlite feature is disabled ()
Currently the codepath used when rusqlite is disabled, is
Unix-platform-dependent.

For instance, here is the error we compiling from Windows:

```
error[E0433]: failed to resolve: could not find `unix` in `os`
   --> C:\Users\runneradmin\.cargo\git\checkouts\libsql-311658d335deb3b1\9b04f1d\libsql-sys\src\connection.rs:276:26
    |
276 |             use std::os::unix::ffi::OsStrExt;
    |                          ^^^^ could not find `unix` in `os`
    |
note: found an item that was configured out
   --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\std\src\os\mod.rs:27:9
note: the item is gated here
   --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\std\src\os\mod.rs:19:1
note: found an item that was configured out
   --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\std\src\os\mod.rs:65:9
note: the item is gated here
   --> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14\library\std\src\os\mod.rs:64:1

error[E0599]: no method named `as_bytes` found for reference `&OsStr` in the current scope
   --> C:\Users\runneradmin\.cargo\git\checkouts\libsql-311658d335deb3b1\9b04f1d\libsql-sys\src\connection.rs:277:73
    |
277 |             let path = std::ffi::CString::new(path.as_ref().as_os_str().as_bytes())
    |                                                                         ^^^^^^^^
    |
help: there is a method `as_encoded_bytes` with a similar name
    |
277 |             let path = std::ffi::CString::new(path.as_ref().as_os_str().as_encoded_bytes())
    |                                                                         ~~~~~~~~~~~~~~~~

Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `libsql-sys` (lib) due to 2 previous errors
```

This patch is adding a platform-independent branch.

The database path is expected to be UTF-8 by the libsql native library.
However, in the real world, all Unix paths are not necessarily UTF-8.
For this reason, I understand why the Unix codepath is attempting a
direct conversion from OsString to CString.
However, it’s not possible to do something similar on other platforms.
For these platforms, we are enforcing correct UTF-8 using `to_str`. At
least, it should work reasonably well in most cases.
2025-03-20 10:47:30 +00:00
d1c95e227c Revert "Add libsql-ffi to workspace depedencies"
This reverts commit e736e13742.
2025-03-20 12:45:24 +02:00
e736e13742 Add libsql-ffi to workspace depedencies 2025-03-20 12:32:21 +02:00
78b90d5a37 Improve project package manifests 2025-03-20 12:04:37 +02:00
8ea257afe9 fix(libsql-sys): support non-Unix when rusqlite feature is disabled
Currently the codepath used when rusqlite is disabled, is
Unix-platform-dependent. This patch is adding a platform-independent
branch. The database path is expected to be UTF-8 by the libsql native
library. However, in the real world, all Unix paths are not necessarily
UTF-8. For this reason, I understand why the Unix codepath is attempting
a direct conversion from OsString to CString. However, it’s not possible
to do something similar on other platforms. For these platforms, we
are enforcing correct UTF-8 using to_str. At least, it should work
reasonably well in most cases.
2025-03-20 09:25:40 +09:00
b601185cc7 libsql-sys: Fix checkpoint logging to use trace level
The instrument macro uses info level by default. Let's switch to trace
level instead to avoid spamming logs like crazy.
2025-03-11 10:56:34 +02:00
ed837f0834 libsql: Add Statement::interrupt() 2025-02-21 09:48:13 +02:00
18f893e9c5 fix default busy timeout from insane ~1.3 hours to 100 milliseconds 2025-02-13 15:26:03 +04:00
09715e4821 Merge pull request from tursodatabase/revert-checkpoint-gen-api
Remove libsql_wal_checkpoint_seq_count() API
2025-01-23 11:18:59 +00:00
e2de2504b4 Revert "libsql: Wire up xCheckpointSeqCount"
This reverts commit bb7f011f79.
2025-01-23 13:01:39 +02:00
d3a156caf5 bundle SQLean extensions
A common complain with libSQL is how to run extensions. The main
mechanism, with a .so, has a lot of issues around how those .so are
distributed.

The most common extensions are the ones in the sqlean package. We can
improve this experience by bundling them in our sqlite build.

Not all SQLean extensions are kosher: some of them, like fileio, use
the vfs. Others, are deemed too complex.

The extensions included here are a subset that we deem important enough,
and low risk enough, to just be a part of the main bundle.
2025-01-16 22:25:16 -05:00
bb7f011f79 libsql: Wire up xCheckpointSeqCount 2024-12-11 10:37:23 +02:00
61558b2a9e libsql-{sqlite3,ffi}: Add xReadFrameRaw() to the virtual WAL API
This adds a new xReadFrameRaw() function to the virtual WAL API, which
upper layers can use to fetch the full frame, including the page number,
that is useful for appending frames to a WAL.
2024-10-29 13:30:27 +02:00
3ac4aa1689 libsql-{sqlite3,ffi}: Add xFrameCount() to the virtual WAL API 2024-10-29 13:30:27 +02:00
1de0aaa4d5 libsql: prepare v0.6.0 release 2024-09-20 15:36:46 -04:00
a68f042914 libsql: release v0.5.0 2024-08-02 09:26:28 -07:00
7dacca2728 bump rust version, fix warnings 2024-07-31 22:47:53 +02:00
fbce426619 Use the namespace resolver to extract namespace ()
* Move `NamespaceName` from `libsql-wal` to `libsql-sys`

* Use the namespace resolver in durable WAL
2024-06-14 17:01:01 +00:00
43ec7b378c libsql: prepare v0.4.0 release () 2024-06-11 14:27:13 +00:00
07a679e745 Generate Eitherxx variants ()
* Create a drop in replacement for `Either` with `Any`

* generate Eitherxx variants

* generate Eitherxx variants

---------

Co-authored-by: ad hoc <postma.marin@protonmail.com>
2024-06-04 12:35:00 +00:00
5129bdb2a3 libsq wal integration ()
* integrate libsql-wal

* fix wal bug

* shutdown registry on shutdown

* fmt
2024-06-03 09:30:40 +00:00
49e28c6911 Prepare release ()
Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
2024-04-17 15:00:11 +00:00
1869f70f5c Release libsql-sys ()
Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
2024-04-17 14:15:45 +00:00
966757ab03 add libsql-hrana crate () 2024-03-25 23:07:55 +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
1158b506e4 libsql: prepare v0.3.0 release () 2024-03-07 12:57:53 +00:00
c8902c3bf6 libsql-sys: Disable SQLCipher support ()
The SQLCipher cipher does not work with frame injection:

https://github.com/tursodatabase/libsql/issues/1122

Therefore, disable the cipher for now and switch default to "aes256cbc".
2024-03-06 08:55:19 +00:00
2ee5a4726e sys: feature flag pager creator ()
* sys: feature flag pager creator

* fix feature flag pghdr_creator
2024-02-29 00:07:17 +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
e373d67e7e fix hrana proto ()
* fix missing default in hrana proto

* lockfile changed
2024-02-10 10:15:35 +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
37fb629f50 run clippy () 2024-01-31 08:42:20 +00:00
6f67c65a40 Consolidate Hrana proto definitions in one source ()
* 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
e1cc9ff829 return number of committed frames on insert_frames () 2024-01-25 16:39:29 +00:00
62f61dbf14 review edits 2024-01-19 12:16:25 +01: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
5f558342bc libsql-sys: make Sqlite3Db::as_ptr() public 2024-01-19 08:22:56 +01:00
6ae8c83a28 libsql-sys: expose leaking pager to callers 2024-01-19 08:22:56 +01:00
eb0daf65f2 libsql-sys: de-featurize set_encryption_key's error type 2024-01-16 16:44:39 +01:00
6025112d20 libsql-sys: wrap conn.handle() in unsafe {} 2024-01-16 16:44:39 +01:00
99e19d8fde fix the rusqlite-vs-no-rusqlite error 2024-01-16 16:44:39 +01:00
77737daa70 error-out if encryption is not compiled-in, and the key is passed 2024-01-16 16:44:39 +01:00
4cd8656023 treewide: rename the feature to just "encryption" 2024-01-16 16:44:39 +01:00
0f315a3ac2 drop the debug key leak 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