Skip to content

Read the bundled tile index without writing beside it - #42

Closed
eliotmcintire wants to merge 5 commits into
modsForFireSensefrom
fix/sqlite-readonly-immutable
Closed

eliotmcintire wants to merge 5 commits into
modsForFireSensefrom
fix/sqlite-readonly-immutable

Conversation

@eliotmcintire

Copy link
Copy Markdown
Collaborator

Reading the package's built-in tile database wrote temporary SQLite files into the installed package folder. It now reads the database without writing anything there.

Affects: Every call to latestHistoricalYear() and the tile lookup. They work in read-only or shared installs and no longer create files in the package folder. Lookup results are unchanged.

Technical details

Defect: the shipped inst/extdata/ClimateNA_tiles.sqlite was in WAL mode. Even a SQLITE_RO connection (sqlite_connect_db(), R/ClimateNA_createTiles.R:81-115, called from R/ClimateNA_useTiles.R:59 and R/latestHistoricalYear.R:21) creates and writes -shm (and -wal) beside a WAL database, here in the install folder. That fails on read-only installs, is shared between hard-linked libraries, and writes into the install directory.

Fix:

  • Read-only connections open file:<path>?immutable=1. RSQLite passes a file: URI to SQLite as is (RSQLite 3.53.3; flags = SQLITE_RO is enough, no extra URI flag). The path is percent-encoded, so spaces and # work. SQLite then takes no locks and writes nothing. The PRAGMAs (busy_timeout, synchronous, journal_mode) now run only for writing connections. readonly = TRUE therefore assumes nobody is changing the file; that holds for the shipped index.
  • The committed database is converted with PRAGMA journal_mode = DELETE. Contents are the same (all 6 tables compared with identical(); only header bytes 18-19, 28 and 96 change). md5 47de7e6a... becomes bc94e316...; size stays 48,427,008 bytes.
  • The maintainer step that ships the file (data-raw/06-archive_fingerprints.R) now runs PRAGMA journal_mode = DELETE after the checkpoint. New databases still start in WAL for concurrent building; a comment in sqlite_connect_db() says to switch back before shipping.
  • Data is not moved to tools::R_user_dir(); that is unnecessary once readers write nothing.

Tests (tests/testthat/test-sqliteReadOnlyNoWrites.R), failing first on development:

  • the shipped index is not in WAL mode;
  • on a copy of extdata, the readers create no -wal/-shm, and file list, size, mtime and md5 are unchanged;
  • with the folder read-only (mode 555), the readers still work and return the same rows as before.

Full devtools::test(), NOT_CRAN=true, Linux. Branch: 117 pass, 2 fail, 1 skip. Development plus the new test file: the 2 new-test groups fail (2 failures) plus the same 2 other failures and 1 skip. The 2 other failures are in test-prepClimateLayers.R (Google Drive credentials unavailable here); the 1 skip is the Windows-only makeClimateDEM test. R CMD check --no-manual shows no WARNINGs; its only NOTE is the existing unused hms import.

Reuses: sqlite_connect_db(), ClimateNA_sql(), ClimateNA_tiles_sqlite(), utils::URLencode(), the existing data-raw/06-archive_fingerprints.R checkpoint step; new: none (no new function; one URI branch inside sqlite_connect_db()).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Lx3DXeS4gUhjnvsZYVXumT

Read-only ClimateNA_sql() connections open the file with SQLite's immutable=1 URI, so no -wal/-shm
files are created. The shipped index is converted from WAL to rollback-journal mode, and the
maintainer step that ships it now switches the journal mode back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXeS4gUhjnvsZYVXumT
@eliotmcintire eliotmcintire added the bug Something isn't working label Nov 28, 2026
eliotmcintire and others added 4 commits November 27, 2026 21:13
The lock-wait test now uses two writing connections and asserts an immutable read ignores the lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXeS4gUhjnvsZYVXumT
It pushes the :latest image on push events and its Wine smoke test fails on this runner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXeS4gUhjnvsZYVXumT
…ead-only tests on Windows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx3DXeS4gUhjnvsZYVXumT
@eliotmcintire

Copy link
Copy Markdown
Collaborator Author

Superseded by #43 (against development).

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