Repository navigation
Commit 0fcd385
committed
sqlitedb: recover a poisoned handle inside a write operation by replaying it
Closes the last deviation recorded for DID-matlab da83fa3. MATLAB
reopens the connection before retrying a READONLY statement, because a
poisoned handle (SQLITE_READONLY_DBMOVED) is cleared by reopening and
never by waiting. mksqlite autocommits, so there the failed statement is
all there is to re-run. In SQLiteDB it is part of a transaction whose
earlier statements die with the handle.
The four write operations (_do_add_branch, _do_add_doc, _do_remove_doc,
_do_delete_branch) now run through a journaling cursor. It records each
statement's SQL, parameters, rowcount, an INSERT's lastrowid and every
row read. On a READONLY at a statement or at COMMIT, _recover_transaction
rolls back the dead transaction, waits on the same backoff schedule,
reopens and replays the journal. Each statement is checked against what
it did the first time before the failed statement runs or the
transaction commits. Only SQL is replayed: files already copied, or
deleted with delete_original, are not needed again. A replay that differs
(another writer took the next doc_idx, a different file is at the path,
a statement fails) is refused, nothing is written, and the original
error is raised.
The tests reproduce a real DBMOVED by replacing the database file under
the open connection. Doing that showed SQLite reports it at the first
write of a transaction rather than at COMMIT, so a COMMIT-only recovery
would have missed the real case. It also showed that a swap after the
first write is not detected at all, which no retry can see.
Adding documents is about 4% slower (1,500 documents: 6.1 s -> 6.4 s).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012Dn4gCNCU2jUGdmfPVCAGK1 parent 881a897 commit 0fcd385
3 files changed
Lines changed: 623 additions & 34 deletions
File tree
- src/did
- implementations
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
177 | 188 | | |
178 | 189 | | |
179 | 190 | | |
| |||
0 commit comments