Skip to content

Add a test for sorter worker threads and sqlite3_backup_init - #307

Merged
utelle merged 1 commit into
utelle:mainfrom
SchwarzDigits:test/sorter-threads-backup-lock
Nov 10, 2026
Merged

utelle merged 1 commit into
utelle:mainfrom
SchwarzDigits:test/sorter-threads-backup-lock

Conversation

@mtrossbach

Copy link
Copy Markdown
Contributor

A new CI test for two things that need more than one thread to show up.

The first part sorts and indexes enough rows that the sorter hands work to worker threads (PRAGMA threads=4, temp_store=FILE, cache_size=10). With the default of 100000 rows, the worker threads open 12 of the 14 to 16 temporary files. The test checks that the ORDER BY and the CREATE INDEX finish within 60 seconds, that worker threads opened temporary files at all, and that the files of an encrypted database contain no plaintext. The same run on a plaintext database must show the rows in the temporary files, so the check itself is known to see the sorter's data. A VFS below the Multiple Ciphers VFS does the counting.

The second part calls sqlite3_backup_init with both databases encrypted, both plaintext, and the two mixed cases, which are refused. Afterwards a second thread must be able to take the mutexes of both connections with sqlite3_mutex_try, so a mutex left locked shows up as a failure instead of a hang.

The second thread and the timeout use sqlite3ThreadCreate, so the test needs no platform code beyond getting the thread id.

Testing (macOS arm64, flags from Makefile.am):

  • On 329a142 all checks pass, in about 3 seconds; the other CI tests pass as well.
  • On 5a9d89f and on v2.6.1 the ORDER BY does not finish, and the test fails after 60 seconds with exit code 1.
  • On 0a69702 the four mutex checks for the two refused backups fail; everything else passes.
  • Built with ThreadSanitizer it reports only races inside SQLite's own sorter code (the same reports come from plain SQLite); AddressSanitizer and UBSan are clean.

threadtest sorts and indexes enough rows that the sorter hands work to
worker threads, which open temporary files of their own. It checks that
the statements finish, that worker threads really opened such files,
and that the files of an encrypted database contain no plaintext. A
plaintext database serves as the control.

It also checks that another thread can use both connections after
sqlite3_backup_init, for compatible databases and for the two cases in
which the backup is refused.

The CI runs it after the rekeying tests.
@utelle
utelle merged commit 92c704f into utelle:main Nov 10, 2026
13 checks passed
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.

2 participants