Skip to content

Syncing main branch with the upstream repo - #33

Closed
AryanSuvarna wants to merge 1169 commits into
Shopify:mainfrom
tursodatabase:main
Closed

AryanSuvarna wants to merge 1169 commits into
Shopify:mainfrom
tursodatabase:main

Conversation

@AryanSuvarna

Copy link
Copy Markdown

No description provided.

drh and others added 30 commits September 11, 2024 17:02
…n. It

does compile, but it does not work.

FossilOrigin-Name: fa06977b6db7fa745720561ec0b10570cf7e71598dc7a7c5ee650640e5bdf6f5
FossilOrigin-Name: 80461e0d724963aaf2646005298f1194c5f1c4c9ae41c1085d4d137ed485bd9f
…turns

a BLOB.

FossilOrigin-Name: fe65821a3b912f061026e6fd7174be26897010e6b474e2780350cac60faebaad
…sides

an opportunity to negotiate a suitable protocol number, for future
compatibility.  Send the page size as a power-of-two.

FossilOrigin-Name: df0623aae1154281157409f62d6d3fb3ce41829281d53bc55868ce44b3d36883
…mote

side, so that if the remote is the replica, it will have access to the
origin database name in case the replica name is really a directory.

FossilOrigin-Name: 435c30171d3c6073b7aaf5cc11cc4813f6a2d225ae6dce1b0e478f0cd5a0b532
debugging.

FossilOrigin-Name: b979d02ffd1370d8840328bce06c76c224f0fc1fb54b47d6c904547580a820a1
FossilOrigin-Name: e385525793c7d74ce8ee139c9d6cfc1248834754598f3fd45b22b9426ff106ee
… make the arg handling more robust.

FossilOrigin-Name: 53fb9b11807ff7accd8cd41f9cb6516d2503f161ea976940437a1d3aae868665
FossilOrigin-Name: b2a3497e5525dd33faf70961107a0529f476735fef756953c66e105747271c6d
PTRMAP entries that extend off the end of the database, as long as they
appear to be well-formatted.

FossilOrigin-Name: a9f95fe5ce90ab9864165e603f3a34013c3c98d03f1db689996f4a32086e2ed6
FossilOrigin-Name: 75d5a8eb3d4ece06900109ad4022ba2a3e82de2f0acb012e3a02bfb4326bfa6d
…invalid

entries that are within the range of the database file.  Continue to ignore
invalid entries beyond the end of the database file.

FossilOrigin-Name: 4cad385b90eaca2d90e3375e473472145af4134160b81097a8535d06638c2e4a
of 160.  This uses about 1/3rd fewer CPU cycles.

FossilOrigin-Name: 96c7f47a8f59e5078bd296979421c1b57fbcb7be261f8a7a0b1d22a4b5914db0
corrects that to just 6 rounds.

FossilOrigin-Name: 3c36f5814f25483586c4fd49ef2fe5c7c0ff8c59672b1622c92061ec0ba8547a
FossilOrigin-Name: e55e3e8ec2fe3a9190872d999cee55c85bde92667040cc166233faaa2fa34266
…1 feature, into this branch.

FossilOrigin-Name: d2f0d19936222911bc317efecc831007d3aba81f9b32877030ffb29d1728bbdc
…forum post, "sqlite3_analyzer not closing WAL-mode db cleanly" ].)

FossilOrigin-Name: 94ceac98845e31249b656dcdb8a58f456b9212dc83968ea333852a66d72a0dae
FossilOrigin-Name: 86e0219d977c493ac19d00c3ddcf560eb317d506c7cf6e4ef17e92daa91e1762
…toring the values of fts5 UNINDEXED column belonging to contentless tables.

FossilOrigin-Name: c51dc2a5e75baacbd905cf314e7b1a58a81993ff05ca656739e028d7db25d5b2
ATTACH-ed databases within the same transaction.

FossilOrigin-Name: 6aa9c8e79b440c6419e65990d9ceba8f00a6f975455138cf2aa82b113daec825
FossilOrigin-Name: dff76b7a3436031ea5a61b8a44ddfa1d40ea20c983f3d34a8501cd7074db68b8
…s it

is with regular rsync.  Only show the SSH command with two or more -v options,
or if there is an error in popen2().

FossilOrigin-Name: 105ec44b470318fc9ff1773027c4064343f224068c9b6e71c5618f18f7dfcc3f
FossilOrigin-Name: 452fb6de3984c3cb10d30b51dcdb2574578ca128a0c519b2bd43df0bdd343083
FossilOrigin-Name: 30e1b92d5663e24d2f325f2bab35f81b55848ef39d15688e40b9005269626303
…ons.

FossilOrigin-Name: fc05a5b7f77cdbfcc659d49eb09569a64a172362cb90199e2861028085178f10
If page 1 changes, always send it last.

FossilOrigin-Name: 2d8cd76691554578e987ce682cf0c42c083711dd1511a178148978182ef43ba2
FossilOrigin-Name: 9961334c8007e7cb6ae55885075b74acddc4fa701b359cf67e0f3c237d7eba4a
FossilOrigin-Name: 129aca54f6b791c222b51f3eb01569e1e569269860e153b005140eb65af378b9
…that can

extend or truncate the database.  Add the sqlite3-rsync utility program that
make a copy of a live database over SSH.

FossilOrigin-Name: b7a8ce4c8c5fc6a3b4744d412d96f99d2452eb4086ad84472511da3b4d6afec6
…d by

the prior check-in.

FossilOrigin-Name: 50762ba0783a04e0dcd9456a1ae17d875b0a9272f2f09854a23d9d5253761e9f
penberg and others added 23 commits May 27, 2026 11:18
The SQLITE_USER_AUTHENTICATION deprecation #warning (added upstream in
SQLite 3.46.0) is a hard error under MSVC's default traditional C
preprocessor (error C1021: invalid preprocessor command 'warning'),
breaking Windows builds. SQLite3MultipleCiphers force-enables
SQLITE_USER_AUTHENTICATION by default, so the directive is active even
though build.rs passes -DSQLITE_USER_AUTHENTICATION=OFF.

Guard the directive with !defined(_MSC_VER) so the deprecation notice is
kept for GCC/Clang and skipped on MSVC. This is purely a compile-time
diagnostic; the extension's runtime behavior is unchanged on all
platforms.

Upstream removed this extension entirely in SQLite 3.48.0 (commit
bc4df60), so this local patch becomes moot once the bundled SQLite is
updated past 3.47.0. The patch is applied in libsql-sqlite3/src and
mirrored into both regenerated bundled amalgamations.
The Windows job's `cargo build -p libsql --all-features` was being built
with the `x86_64-pc-windows-gnu` toolchain (MinGW/GCC), set as the default
host triple by `hecrj/setup-rust-action@v2`. MSVC was never exercised. So
breaks that only fail under MSVC -- like the SQLite 3.47.0 `#warning` that
errors with C1021 -- compiled green here. We discovered the gap when
libsql-js (which builds with `--target x86_64-pc-windows-msvc`) failed
downstream on the same code.

Add `--target x86_64-pc-windows-msvc --release` so the Windows job
actually compiles the bundled SQLite encryption amalgamation (sqlite3mc)
with MSVC, and breaks surface in CI.

`cargo clean -p libsql-ffi` runs first so sqlite3mc is rebuilt from source
rather than restored from a cached target/.
The Windows job's `cargo build -p libsql --all-features` was being built
with the `x86_64-pc-windows-gnu` toolchain (MinGW/GCC), set as the
default host triple by `hecrj/setup-rust-action@v2`. MSVC was never
exercised. So breaks that only fail under MSVC -- like the SQLite 3.47.0
`#warning` that errors with C1021 -- compiled green here. We discovered
the gap when libsql-js (which builds with `--target
x86_64-pc-windows-msvc`) failed downstream on the same code.

Add `--target x86_64-pc-windows-msvc --release` so the Windows job
actually compiles the bundled SQLite encryption amalgamation (sqlite3mc)
with MSVC, and breaks surface in CI.

`cargo clean -p libsql-ffi` runs first so sqlite3mc is rebuilt from
source rather than restored from a cached target/.
This updates the vendored SQLite3 Multiple Ciphers encryption extension
from 1.8.1 to 1.9.0, the release that targets upstream SQLite 3.47.0 (the
base version we now ship). The previous 1.8.1 vendoring lagged the SQLite
base and was missing several upstream fixes, including a crash in
sqlite3mcSetCodec().

The import replaces all upstream files with their v1.9.0 contents and
re-applies libSQL's local patches via 3-way merge (base v1.8.1, ours
libSQL, theirs v1.9.0). All merges were clean (no conflicts), and
`cargo build -p libsql-ffi --features multiple-ciphers` builds.

== Preserved as-is (not upstream sqlite3mc) ==

src/sqlite3.c, src/sqlite3.h — libSQL's own SQLite amalgamation, not
  sqlite3mc's vanilla copy. build.rs overwrites src/sqlite3.c with
  libsql-sqlite3's amalgamation at build time regardless, so these are
  left untouched.

== Re-applied libSQL patches (3-way merged onto 1.9.0) ==

CMakeLists.txt — libSQL build options (LIBSQL_ENCRYPTION,
  LIBSQL_CUSTOM_PAGER_CODEC, LIBSQL_EXTRA_PRAGMAS,
  LIBSQL_ENABLE_WASM_RUNTIME), AES256-only cipher selection, and the
  arm/aarch64 guards around -msse4.2/-maes.

src/sqlite3mc.c — `#include "sqlite3.c"` instead of "sqlite3patched.c"
  so the amalgamation pulls in libSQL's SQLite.

src/codecext.c, src/sqlite3mc_vfs.c — libSQL codec hooks
  libsql_db_has_codec(), libsql_pager_codec_impl() (replacing
  sqlite3mcPagerHasCodec()/sqlite3mcPagerCodec()), and the cached
  hasCodec update in the rekey success path.

src/cipher_config.c — libsql_extra_pragma().
src/cipher_wxaes256.c — libsql_generate_aes256_key().
src/codec_algos.c — libsql_generate_initial_vector().

== Notable upstream fixes now picked up ==

src/sqlite3mc_vfs.c — sqlite3mcSetCodec() now passes the VFS located by
  mcFindVfs() (pVfsMC) to mcFindDbMainFileName() instead of blindly
  casting db->pVfs. When the Multiple Ciphers VFS is not the top-level
  VFS (another VFS stacked on top), db->pVfs is not an sqlite3mc_vfs and
  the cast made mcFindDbMainFileName() dereference a bogus ->mutex and
  crash. This matches the fix already present in sqlite3mcGetCodec().

src/sqlite3mc_vfs.c — the mcRead* helpers now propagate codec errors via
  sqlite3mcGetCodecLastError() instead of silently resetting rc to
  SQLITE_OK after decryption.
libsql_stmt_interrupt() set a per-statement isInterrupted flag, but the
VDBE execution loop only ever checked the connection-wide
db->u1.isInterrupted. A statement already executing inside sqlite3_step()
therefore ran to completion regardless of the request; the flag was only
observed at the next step() entry.

Check p->isInterrupted alongside db->u1.isInterrupted at both VDBE
interrupt-check sites so an interrupt requested mid-execution aborts the
running statement promptly with SQLITE_INTERRUPT, without touching the
connection-wide interrupt state (other statements keep running). Set and
clear the flag atomically, mirroring sqlite3_interrupt(), since the
request may come from another thread.

Tests:
- test/interruptstmt.test: deterministic regression via a new
  sqlite_stmt_interrupt_count test hook, covering the in-loop check and
  the connection-flag-stays-clear property.
- test/interrupttest.c: standalone multi-threaded test of the real
  cross-thread case (interrupt a step() in flight) and statement-level
  granularity. Build and run with `make interrupttest`.
The 0.10.0-pre.3 version bump (61d629a) updated the workspace
Cargo.toml versions but not Cargo.lock, which stayed at 0.10.0-pre.2.
Any cargo invocation (including the c-bundle-validate CI job's
'cargo xtask build-bundled') rewrites the lockfile to match, leaving an
uncommitted Cargo.lock change that fails the job's 'git diff --quiet'
check. Regenerate the lockfile so it matches the committed Cargo.toml.
Two one-line typo fixes for duplicated "the" in `libsql-server`
doc-comments:
- `libsql-server/src/main.rs` — "By default, the the period is 30
seconds." → "By default, the period is 30 seconds."
- `libsql-server/src/rpc/streaming_exec.rs` — "/// Apply the response to
the the builder, and return whether..." → "/// Apply the response to the
builder, ..."

No code/behavior change.
…2248)

libsql_stmt_interrupt() set a per-statement isInterrupted flag, but the
VDBE execution loop only ever checked the connection-wide
db->u1.isInterrupted. A statement already executing inside
sqlite3_step()
therefore ran to completion regardless of the request; the flag was only
observed at the next step() entry.

Check p->isInterrupted alongside db->u1.isInterrupted at both VDBE
interrupt-check sites so an interrupt requested mid-execution aborts the
running statement promptly with SQLITE_INTERRUPT, without touching the
connection-wide interrupt state (other statements keep running). Set and
clear the flag atomically, mirroring sqlite3_interrupt(), since the
request may come from another thread.

Tests:
- test/interruptstmt.test: deterministic regression via a new
  sqlite_stmt_interrupt_count test hook, covering the in-loop check and
  the connection-flag-stays-clear property.
- test/interrupttest.c: standalone multi-threaded test of the real
  cross-thread case (interrupt a step() in flight) and statement-level
  granularity. Build and run with `make interrupttest`.
The windows-latest runner image moved to windows-2025-vs2026, which
ships Visual Studio 2026. The cmake crate 0.1.54 pinned in Cargo.lock
does not recognize VS 2026 and panics in the libsql-ffi build script
with "couldn't determine visual studio generator" while configuring
the SQLite3MultipleCiphers build.

Support for the VS 2026 generator was added in cmake 0.1.55, so bump
the lockfile to 0.1.58 (pulling in the newer cc and libc it requires).
The windows-latest runner image moved to windows-2025-vs2026, which
ships Visual Studio 2026. The cmake crate 0.1.54 pinned in Cargo.lock
does not recognize VS 2026 and panics in the libsql-ffi build script
with "couldn't determine visual studio generator" while configuring the
SQLite3MultipleCiphers build.

Support for the VS 2026 generator was added in cmake 0.1.55, so bump the
lockfile to 0.1.58 (pulling in the newer cc and libc it requires).
The setup-protoc action downloads protoc via unauthenticated GitHub
API requests, which share a rate limit across all runners on the same
IP and intermittently fail with "API rate limit exceeded". Our proto
files are all plain proto3, so the protobuf-compiler package from the
Ubuntu archive is sufficient and involves no GitHub API at all.
The setup-protoc action downloads protoc via unauthenticated GitHub API
requests, which share a rate limit across all runners on the same IP and
intermittently fail with "API rate limit exceeded". Our proto files are
all plain proto3, so the protobuf-compiler package from the Ubuntu
archive is sufficient and involves no GitHub API at all.
ANALYZE is parsed by sqlite3-parser but was not classified by libsql,
causing it to fail with unsupported statement before execution. Classify
ANALYZE as Write because it updates SQLite statistics tables, and add a
regression test.
@AryanSuvarna
AryanSuvarna marked this pull request as ready for review September 29, 2026 14:51
@AryanSuvarna
AryanSuvarna requested a review from a team September 29, 2026 14:51
@AryanSuvarna
AryanSuvarna marked this pull request as draft September 29, 2026 14:53
@AryanSuvarna AryanSuvarna reopened this Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants