Skip to content

Avoid sqlite3 lock contention by serializing access through the cache thread.#927

Merged
danyeaw merged 17 commits into
26.4.xfrom
cache-insert-queue
May 13, 2026
Merged

Avoid sqlite3 lock contention by serializing access through the cache thread.#927
danyeaw merged 17 commits into
26.4.xfrom
cache-insert-queue

Conversation

@dholth
Copy link
Copy Markdown
Contributor

@dholth dholth commented Apr 30, 2026

Description

Instead of giving the network thread a sqlite3 connection, add "store record" requests to the cache thread's input queue. The cache thread processes either "fetch record" or "store record" requests as they come in, and there is no database contention within a single conda process.

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

jezdez and others added 2 commits April 30, 2026 13:54
Enable WAL journal mode and a 30s busy timeout on repodata_shards.db so the
cache reader thread no longer races with the network writer thread. Falls back
gracefully on filesystems where WAL is unsupported.
Co-authored-by: Daniel Holth <dholth@anaconda.com>
@github-project-automation github-project-automation Bot moved this to 🆕 New in 🔎 Review Apr 30, 2026
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Apr 30, 2026
@jezdez
Copy link
Copy Markdown
Member

jezdez commented Apr 30, 2026

I'd like to land #926 first as a quick fix since WAL is independently useful for any concurrent access to the cache. This can then build on top as a follow-up to remove the contention at the source. Alternatively, happy to fold this into #926 if you'd prefer shipping both together.

Copy link
Copy Markdown
Member

@jezdez jezdez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea to serialize all SQLite access through the cache thread. One suggestion to avoid the isinstance dance: use a separate insert queue instead of mixing types on the lookup queue.

Comment thread conda_libmamba_solver/shards_subset.py
Comment thread conda_libmamba_solver/shards_subset.py Outdated
@dholth dholth force-pushed the cache-insert-queue branch from fbc8fee to 207d7d6 Compare April 30, 2026 13:35
@dholth dholth marked this pull request as ready for review April 30, 2026 14:48
@dholth dholth requested a review from a team as a code owner April 30, 2026 14:48
@dholth dholth changed the title sketch queue cache idea Avoid sqlite3 lock contention by serializing access through the cache thread. Apr 30, 2026
@dholth
Copy link
Copy Markdown
Contributor Author

dholth commented May 4, 2026

Will continue this in the conda repository.

@dholth
Copy link
Copy Markdown
Contributor Author

dholth commented May 11, 2026

@jezdez if we really get frustrated, we could fall back to no-cache. Or the memory:// sqlite database! Are we closing the transaction correctly in our current write-to-cache?

@dholth dholth requested review from danyeaw and jezdez May 12, 2026 18:28
@dholth dholth changed the base branch from main to 26.4.x May 12, 2026 20:11
Copy link
Copy Markdown
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dholth, this looks great, thanks for serializing access back down. I was thinking an additional unit test that creates a QueueCache, calls insert, and checks that the shard is in the output would have improve test coverage.

Comment thread conda_libmamba_solver/shards_subset.py
Comment thread conda_libmamba_solver/shards_subset.py Outdated
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Approved in 🔎 Review May 12, 2026
@danyeaw danyeaw enabled auto-merge (squash) May 13, 2026 01:04
@danyeaw danyeaw merged commit b5847b4 into 26.4.x May 13, 2026
143 of 147 checks passed
@danyeaw danyeaw deleted the cache-insert-queue branch May 13, 2026 02:27
@github-project-automation github-project-automation Bot moved this from ✅ Approved to 🏁 Done in 🔎 Review May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed [bot] added once the contributor has signed the CLA

Projects

Status: 🏁 Done

Development

Successfully merging this pull request may close these issues.

4 participants