Skip to content

Commit

Permalink
wal: add bUsesShm flag to declare relying on shared memory
Browse files Browse the repository at this point in the history
Before enabling WAL journaling, libSQL detects whether WAL
is fully supported. Historically it meant either operating
in exclusive mode or supporting shared memory locks in the
underlying VFS, but it may not be the case with custom WAL
implementations. Thus, custom WAL methods can declare whether
they rely on shared memory - if not, it will also not get
verified when checking for WAL support.
  • Loading branch information
psarna committed Oct 30, 2022
1 parent eff934f commit 621dcae
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -7484,7 +7484,7 @@ int sqlite3PagerWalCallback(Pager *pPager){
int sqlite3PagerWalSupported(Pager *pPager){
const sqlite3_io_methods *pMethods = pPager->fd->pMethods;
if( pPager->noLock ) return 0;
return pPager->exclusiveMode || (pMethods->iVersion>=2 && pMethods->xShmMap);
return pPager->exclusiveMode || (pPager->pWalMethods->bUsesShm == 0) || (pMethods->iVersion>=2 && pMethods->xShmMap);
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/wal.c
Original file line number Diff line number Diff line change
Expand Up @@ -4130,6 +4130,7 @@ libsql_wal_methods *libsql_wal_methods_find(const char *zName) {
#endif
methods.xDb = sqlite3WalDb;

methods.bUsesShm = 1;
methods.zName = "default";
methods.pNext = NULL;
methods_head = &methods;
Expand Down
3 changes: 3 additions & 0 deletions src/wal.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ typedef struct libsql_wal_methods {

void (*xDb)(Wal *pWal, sqlite3 *db);

/* True if the implementation relies on shared memory routines (e.g. locks) */
int bUsesShm;

const char *zName;
struct libsql_wal_methods *pNext;
} libsql_wal_methods;
Expand Down

0 comments on commit 621dcae

Please sign in to comment.