Repository navigation
Read the bundled tile index without writing beside it - #43
Merged
Merged
Conversation
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
This was referenced Nov 28, 2026
achubaty
added a commit
that referenced
this pull request
Dec 4, 2026
# Conflicts: # NEWS.md # inst/extdata/ClimateNA_tiles.sqlite # tests/testthat/test-sqliteConcurrency.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.sqlitewas in WAL mode. Even aSQLITE_ROconnection (sqlite_connect_db(), R/ClimateNA_createTiles.R, 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:
file:<path>?immutable=1withflags = SQLITE_RO. RSQLite passes afile:URI to SQLite as is (RSQLite 3.53.3; no extra URI flag). Newsqlite_immutable_uri()builds it: POSIXfile:///home/..., Windowsfile:///C:/...(backslashes to/, drive colon kept), the rest percent-encoded. SQLite then takes no locks and writes nothing. The PRAGMAs (busy_timeout,synchronous,journal_mode) now run only for writing connections.readonly = TRUEassumes nobody is changing the file; that holds for the shipped index.PRAGMA journal_mode = DELETE. Contents are the same (all 6 tables compared withidentical(); only header bytes 19, 20, 28 and 96 change). md547de7e6a...becomesbc94e316...; size stays 48,427,008 bytes.PRAGMA journal_mode = DELETEafter the checkpoint. New databases still start in WAL for concurrent building.tools::R_user_dir(); that is unnecessary once readers write nothing.Tests (tests/testthat/test-sqliteReadOnlyNoWrites.R, shared
dbCopy()in tests/testthat/helper-sqlite.R), failing first on development:-wal/-shm, and file list, size, mtime and md5 are unchanged;The old lock-wait test in test-sqliteConcurrency.R passed trivially, because immutable reads ignore locks. It now holds a write lock in another process, asserts that an immutable read neither waits nor fails, and that a second writing connection waits and then succeeds.
Full
devtools::test(),NOT_CRAN=true, Linux: 123 pass, 2 fail, 1 skip. The 2 failures are in test-prepClimateLayers.R (Google Drive credentials unavailable in this environment; they fail the same on development). The skip is the Windows-only makeClimateDEM test.R CMD check --no-manualshows no WARNINGs; its only NOTE is the existing unusedhmsimport.Reuses:
sqlite_connect_db(),ClimateNA_sql(),ClimateNA_tiles_sqlite(),utils::URLencode(), the existingdbCopy()test helper (moved to helper-sqlite.R), the checkpoint step indata-raw/06-archive_fingerprints.R; new:sqlite_immutable_uri()(nothing existing builds a SQLite file URI).🤖 Generated with Claude Code
https://claude.ai/code/session_01Lx3DXeS4gUhjnvsZYVXumT