Repository navigation
Sqlite3Handler: do not sync to disk after each record, add wal argument - #105
woutdenolf wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7800c9f to
06d9748
Compare
| if self._wal: | ||
| # The busy timeout does not apply to a journal mode change. | ||
| self._sql_query_with_retries( | ||
| "PRAGMA journal_mode=WAL", tuple(), conn, retry_period=0.01 | ||
| ) | ||
| conn.execute("PRAGMA synchronous=NORMAL") | ||
| else: | ||
| conn.execute("PRAGMA synchronous=OFF") |
There was a problem hiding this comment.
-
It looks like requesting to switch mode is not necessarily accepted / activate by passing by '_sql_query_with_retries'
So in this case the WAL mode might not be active and move to 'NORMAL' synchronization. How much is it an issue ? I think in this case you will still met performance issue. -
Furthermore the
walmode seems to be store in the file and if you have several accessor you might have conflict.
This is the way AI end up fixing those two points. it which seems faire IMO (but not a sqlite3 expert):
| if self._wal: | |
| # The busy timeout does not apply to a journal mode change. | |
| self._sql_query_with_retries( | |
| "PRAGMA journal_mode=WAL", tuple(), conn, retry_period=0.01 | |
| ) | |
| conn.execute("PRAGMA synchronous=NORMAL") | |
| else: | |
| conn.execute("PRAGMA synchronous=OFF") | |
| if self._wal: | |
| # The busy timeout does not apply to a journal mode change. | |
| self._sql_query_with_retries( | |
| "PRAGMA journal_mode=WAL", tuple(), conn, retry_period=0.01 | |
| ) | |
| journal_mode = conn.execute("PRAGMA journal_mode").fetchone()[0] | |
| if journal_mode == "wal": | |
| # Protected against corruption; a power loss may only lose the last commits. | |
| conn.execute("PRAGMA synchronous=NORMAL") | |
| else: | |
| # No disk waits; an OS crash or power loss can corrupt the database. | |
| conn.execute("PRAGMA synchronous=OFF") |
Note: I think switching to 'WAL' mode can still fail silently when calling _sql_query_with_retries but should be safe.
PR summary
Closes #104
Sqlite3Handlergets awalargument. Both modes stop a commit from holding the lock during a slow disk sync.wal=False(default):PRAGMA synchronous=OFF. Trade-off: an OS crash or a power loss can corrupt the database. An application crash cannot.wal=True: write-ahead logging withPRAGMA synchronous=NORMAL. Crash-safe, but does not work on network file systems.AI Disclosure
🤖 Generated with Claude Code