Skip to content

Read the tile index read-only; set busy_timeout before other pragmas - #41

Merged
eliotmcintire merged 1 commit into
developmentfrom
fix-sqlite-busy-timeout
Nov 8, 2026
Merged

eliotmcintire merged 1 commit into
developmentfrom
fix-sqlite-busy-timeout

Conversation

@eliotmcintire

Copy link
Copy Markdown
Collaborator

Looking up the latest climate year could fail with "database is locked" when many jobs started at once. Lookups now wait for the lock instead of failing, and no longer try to write to the database.

Affects: parallel runs on shared (NFS) libraries, where parsing fireSense modules sometimes died inside latestHistoricalYear(); results are unchanged.

Technical details

Defect: sqlite_connect_db() (R/ClimateNA_createTiles.R:95-104) let dbConnect run PRAGMA synchronous and then ran PRAGMA journal_mode = WAL before PRAGMA busy_timeout, so both failed at once under contention. firstRun was also TRUE when the file existed, and ClimateNA_sql() could dbCreateTable on a read path.

Fix: connect with synchronous = NULL and set busy_timeout first. Only writing connections set synchronous, and WAL only when the file is new. ClimateNA_sql() gets readonly, which opens SQLITE_RO and never creates tables. latestHistoricalYear() and ClimateNA_useTiles() use it.

Tests (tests/testthat/test-sqliteConcurrency.R): 8 forked readers, a read-only check, and a lookup that must wait out a 2 s exclusive lock. The lock-wait and read-only tests fail on development ("database is locked") and pass here. The parallel test passes on local disk either way; the failure was seen on NFS (8/280 calls before, 0/280 after). devtools::test(): 110 pass, 2 fail in test-prepClimateLayers.R (Drive downloads / parallel workers under load_all). R CMD check: Rd and codoc clean; remaining errors are the Drive-dependent prepClimateLayers example.

🤖 Generated with Claude Code

https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6

@eliotmcintire eliotmcintire added the bug Something isn't working label Nov 8, 2026
@eliotmcintire
eliotmcintire merged commit 59de27d into development Nov 8, 2026
12 checks passed
@eliotmcintire
eliotmcintire deleted the fix-sqlite-busy-timeout branch November 8, 2026 18:09
eliotmcintire added a commit that referenced this pull request Nov 8, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
eliotmcintire added a commit that referenced this pull request Nov 8, 2026
…hive audit) into modsForFireSense; 2.2.3.9011

Conflicts: version (9011), NEWS (both), prepClimateLayers.R (development's formatting + mods' gdal argument).
Layer cache key unchanged (climateBuilderDigest identical before and after).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014G18Mik3fH4z5M5CyMSUS6
achubaty added a commit that referenced this pull request Nov 9, 2026
Use #41's read-only connection instead of copying the 40 MB index on every call;

the shipped index is no longer in WAL mode, so nothing is left beside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
achubaty added a commit that referenced this pull request Nov 9, 2026
development took 2.2.3.9011 for #41.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
achubaty added a commit that referenced this pull request Nov 9, 2026
The shipped index is in rollback-journal mode, so #41's read-only path needs no write access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant