Skip to content

CS-2286 Fix SQLite write ahead logging checkpoint corruption on M1#2

Open
ValeriyLapin wants to merge 1 commit intorelease/1.4.2-amcofrom
fix/cbl-sql-write-ahead-logging-corruption
Open

CS-2286 Fix SQLite write ahead logging checkpoint corruption on M1#2
ValeriyLapin wants to merge 1 commit intorelease/1.4.2-amcofrom
fix/cbl-sql-write-ahead-logging-corruption

Conversation

@ValeriyLapin
Copy link

Addresses issue: CS-2286

Expectations

This PR fixes SQLite database corruption during compaction on M1 Macs. Two changes in CBL_SQLiteStorage.m:

  • sqlite3_busy_timeout(dbHandle, 5000) - gives SQLite 5 seconds to resolve internal lock contention between the app's main connection and the background replicator thread, instead of immediately failing with SQLITE_BUSY
  • PRAGMA wal_checkpoint(PASSIVE) - replaces RESTART mode which required exclusive database access. PASSIVE checkpoints only what it can without blocking other threads, eliminating the race condition that caused corruption when the replicator was writing concurrently

Review

  1. Check Source/CBL_SQLiteStorage.m line 235 - verify sqlite3_busy_timeout is called right after obtaining dbHandle
  2. Check Source/CBL_SQLiteStorage.m line 2212 - verify wal_checkpoint uses PASSIVE instead of RESTART
  3. Build and run in Xcode - confirm no compilation errors

Tests

No new unit tests added.

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.

1 participant