Skip to content

Commit e6a4b1a

Browse files
committed
libsql-sqlite3: End read transaction in sqlite3PagerWalEndCommit()
We have a problem with WAL API where in some scenarios, we seem to lose WAL frames that were already applied. However, inspecting the external WAL frame, the sync mechanics work fine and the problem is in SQLite's in-memory state. As it turnws out, the sqlite3PagerWalBeginCommit() function first begins a read transaction and then upgrades it to a write transaction. However, sqlite3PagerWalEndCommit() only ends the write transaction and therefore leaves the pager in READER state. Let's call pager_unlock() to switch to OPEN stte, fixing the issue of disappearing frames.
1 parent f453e44 commit e6a4b1a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libsql-sqlite3/src/pager.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7813,10 +7813,16 @@ int sqlite3PagerWalBeginCommit(Pager *pPager) {
78137813
}
78147814

78157815
int sqlite3PagerWalEndCommit(Pager *pPager) {
7816+
int rc = SQLITE_ERROR;
78167817
if (!pagerUseWal(pPager)) {
7817-
return SQLITE_ERROR;
7818+
return rc;
7819+
}
7820+
rc = pPager->wal->methods.xEndWriteTransaction(pPager->wal->pData);
7821+
if (rc != SQLITE_OK) {
7822+
return rc;
78187823
}
7819-
return pPager->wal->methods.xEndWriteTransaction(pPager->wal->pData);
7824+
pager_unlock(pPager);
7825+
return rc;
78207826
}
78217827

78227828
int sqlite3PagerWalInsert(Pager *pPager, unsigned int iFrame, void *pBuf, unsigned int nBuf) {

0 commit comments

Comments
 (0)