Refactor wal.c to use the VFS. This check-in compiles and links and works

ok as long as you leave WAL turned off, but WAL does not work.

FossilOrigin-Name: 62db5fa3b61be885b2d94e9b9ce3877b2c588350
This commit is contained in:
drh 2010-04-29 22:34:07 +00:00
parent 31cbbbad1c
commit 7ed91f2344
14 changed files with 534 additions and 1210 deletions

View File

@ -1,8 +1,8 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Untested\simplementation\sof\sthe\sshared-memory\sdead-man-switch.
D 2010-04-29T16:40:51
C Refactor\swal.c\sto\suse\sthe\sVFS.\s\sThis\scheck-in\scompiles\sand\slinks\sand\sworks\nok\sas\slong\sas\syou\sleave\sWAL\sturned\soff,\sbut\sWAL\sdoes\snot\swork.
D 2010-04-29T22:34:08
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in d83a0ffef3dcbfb08b410a6c6dd6c009ec9167fb
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -112,7 +112,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c e86634da8c48357a759694c9c7c471125cd8d5a8
F src/bitvec.c 06ad2c36a9c3819c0b9cbffec7b15f58d5d834e0
F src/btmutex.c 96a12f50f7a17475155971a241d85ec5171573ff
F src/btree.c dd26f3b5725ac3cbc765857a76523ac10dbfe761
F src/btree.c 2e41e62e80ad4686b3322721982ceb7aa6d8c9f1
F src/btree.h dd83041eda10c17daf023257c1fc883b5f71f85a
F src/btreeInt.h b0c87f6725b06a0aa194a6d25d54b16ce9d6e291
F src/build.c 11100b66fb97638d2d874c1d34d8db90650bb1d7
@ -134,7 +134,7 @@ F src/journal.c b0ea6b70b532961118ab70301c00a33089f9315c
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
F src/loadext.c 1c7a61ce1281041f437333f366a96aa0d29bb581
F src/main.c 569561a238a0bb6d55affbaa224ddc885c91df2b
F src/main.c 28171059466a5dac18160c466b978eaafdbb3594
F src/malloc.c a08f16d134f0bfab6b20c3cd142ebf3e58235a6a
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 89d4ea8d5cdd55635cbaa48ad53132af6294cbb2
@ -153,10 +153,10 @@ F src/os.c 8bc63cf91e9802e2b807198e54e50227fa889306
F src/os.h 534b082c3cb349ad05fa6fa0b06087e022af282c
F src/os_common.h 0d6ee583b6ee3185eb9d951f890c6dd03021a08d
F src/os_os2.c 8ad77a418630d7dee91d1bb04f79c2096301d3a0
F src/os_unix.c f0e002e74108c8a3f70c63dd91419ab6bcafd095
F src/os_unix.c bf4cc543fcb32dbcb25a88cf817c761ceef14fdd
F src/os_win.c a8fc01d8483be472e495793c01064fd87e56a5c1
F src/pager.c b4a41030860229e80295fa1f37addab24d21799c
F src/pager.h cee4487ab4f0911dd9f22a40e3cd55afdb7ef444
F src/pager.c 07c3522319a449db9dc732da828a09c4c55c41a4
F src/pager.h 934b598583a9d936bb13c37d62a2fe68ac48781c
F src/parse.y ace5c7a125d9f2a410e431ee3209034105045f7e
F src/pcache.c ace8f6a5ecd4711cc66a1b23053be7109bd437cf
F src/pcache.h c683390d50f856d4cd8e24342ae62027d1bb6050
@ -169,14 +169,14 @@ F src/resolve.c ac5f1a713cd1ae77f08b83cc69581e11bf5ae6f9
F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
F src/select.c c03d8a0565febcde8c6a12c5d77d065fddae889b
F src/shell.c c40427c7245535a04a9cb4a417b6cc05c022e6a4
F src/sqlite.h.in 0cc43a0fa5d26cd26d2609b84ecf094a159e9cb9
F src/sqlite.h.in a710846e91159742ee3ddcbabb56eb7c7478e3a5
F src/sqlite3ext.h 69dfb8116af51b84a029cddb3b35062354270c89
F src/sqliteInt.h 700a2df7b8dfe57c3b8d83c52ff40928e026220c
F src/sqliteInt.h 32dfe6294b46914fb567db493994bf902fb0f8c9
F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6
F src/status.c 4df6fe7dce2d256130b905847c6c60055882bdbe
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c 4de81521174fedacd8393ea7b70b730ce17f8eae
F src/test1.c 64b5b8135080b94370e8100e5066bb394f5c3122
F src/test1.c a449144907face6414f68f6a5663a5b8cadabbd4
F src/test2.c b6b43413d495addd039a88b87d65c839f86b18cb
F src/test3.c 4c21700c73a890a47fc685c1097bfb661346ac94
F src/test4.c ad03bb987ddedce928f4258c1e7fa4109a73497d
@ -215,17 +215,17 @@ F src/update.c c0dc6b75ad28b76b619042d934f337b02acee208
F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685
F src/util.c 32aebf04c10e51ad3977a928b7416bed671b620b
F src/vacuum.c 8e7d9a6fd076774bb6e211cad335c7337948a164
F src/vdbe.c da7ee09fdb5ee6ecfac11b74086834ff6583cd23
F src/vdbe.c 21a96eeeb43dedd40072028db0b42e137296a81a
F src/vdbe.h 471f6a3dcec4817ca33596fe7f6654d56c0e75f3
F src/vdbeInt.h 19ebc8c2a2e938340051ee65af3f377fb99102d1
F src/vdbeapi.c 466044df5bc916f778833e927165fd02cdef6086
F src/vdbeapi.c 85e448c7d1d6dde7226c721cd8da8f9b5286699d
F src/vdbeaux.c be6ca4bb330c7730b358dd627d6d632ca93482c9
F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
F src/wal.c b1c6868b975a67f6f4dd2cd612eeace4117eb98f
F src/wal.h c60781e78e394af07ece3b64a11192eb442241c1
F src/wal.c 1c984ba3bba07a9efb4974837d12daef8f0d80c4
F src/wal.h d0a7048e68a86d3fe4639858d7f592606545d224
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c faadd9c2bf08868e5135192b44e0d753e363a885
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@ -811,14 +811,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 1bde41cf081570ad257f927b641e752dff4ed014
R a7ee89d9d5eb7d4f4fd9d69824beab31
P 706611283ea2575c2942543391026b36061cfc1c
R d5f4a8af6d2162b2c802208b97207bbd
U drh
Z 15bd57757c5a0ce16c3065e9d45dae67
Z eca35982e551d3fde58c618a2bb3d812
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD4DBQFL2baVoxKgR168RlERArO2AJ9g8Vnb6XlVDltcg68idEyJzFPcYwCYh7Xs
0Mdctk0jP1xbHiTJhHLX+A==
=minX
iD8DBQFL2glkoxKgR168RlERAm4BAJ9/6BoUJM0bQ0jccd1czYE2rrEefgCfYnyN
XCr+jA+ZIb6AheCdZkTnnE4=
=Dx/c
-----END PGP SIGNATURE-----

View File

@ -1 +1 @@
706611283ea2575c2942543391026b36061cfc1c
62db5fa3b61be885b2d94e9b9ce3877b2c588350

View File

@ -2278,7 +2278,7 @@ static int lockBtree(BtShared *pBt){
*/
if( page1[19]==2 && pBt->doNotUseWAL==0 ){
int isOpen = 0;
rc = sqlite3PagerOpenLog(pBt->pPager, &isOpen);
rc = sqlite3PagerOpenWal(pBt->pPager, &isOpen);
if( rc!=SQLITE_OK ){
goto page1_init_failed;
}else if( isOpen==0 ){

View File

@ -1197,9 +1197,9 @@ void *sqlite3_wal_hook(
){
void *pRet;
sqlite3_mutex_enter(db->mutex);
pRet = db->pLogArg;
db->xLogCallback = xCallback;
db->pLogArg = pArg;
pRet = db->pWalArg;
db->xWalCallback = xCallback;
db->pWalArg = pArg;
sqlite3_mutex_leave(db->mutex);
return pRet;
}

View File

@ -5049,6 +5049,7 @@ static int unixShmClose(sqlite3_shm *pSharedMem){
unixShm **pp; /* For looping over sibling connections */
int nRef; /* Number of connections to pFile */
if( pSharedMem==0 ) return SQLITE_OK;
p = (struct unixShm*)pSharedMem;
pFile = p->pFile;
@ -5092,7 +5093,7 @@ static int unixShmSize(
sqlite3_shm *pSharedMem, /* Pointer returned by unixShmOpen() */
int reqSize, /* Requested size. -1 for query only */
int *pNewSize, /* Write new size here */
char **ppBuf /* Write new buffer origin here */
void **ppBuf /* Write new buffer origin here */
){
unixShm *p = (unixShm*)pSharedMem;
unixShmFile *pFile = p->pFile;
@ -5165,7 +5166,7 @@ static int unixShmLock(
|| desiredLock==p->lockState
|| (desiredLock==SQLITE_SHM_READ && p->lockState==SQLITE_SHM_READ_FULL)
){
*pGotLock = p->lockState;
if( pGotLock ) *pGotLock = p->lockState;
return SQLITE_OK;
}
@ -5257,7 +5258,7 @@ static int unixShmLock(
}
}
sqlite3_mutex_leave(pFile->mutex);
*pGotLock = p->lockState;
if( pGotLock ) *pGotLock = p->lockState;
return rc;
}

View File

@ -399,7 +399,7 @@ struct Pager {
char *pTmpSpace; /* Pager.pageSize bytes of space for tmp use */
PCache *pPCache; /* Pointer to page cache object */
sqlite3_backup *pBackup; /* Pointer to list of ongoing backup processes */
Log *pLog; /* Log used by "journal_mode=wal" */
Wal *pWal; /* Write-ahead log used by "journal_mode=wal" */
};
/*
@ -1192,8 +1192,8 @@ static int addToSavepointBitvecs(Pager *pPager, Pgno pgno){
** Return true if this pager uses a write-ahead log instead of the usual
** rollback journal. Otherwise false.
*/
static int pagerUseLog(Pager *pPager){
return (pPager->pLog!=0);
static int pagerUseWal(Pager *pPager){
return (pPager->pWal!=0);
}
/*
@ -1227,8 +1227,8 @@ static void pager_unlock(Pager *pPager){
*/
pPager->dbSizeValid = 0;
if( pagerUseLog(pPager) ){
sqlite3WalCloseSnapshot(pPager->pLog);
if( pagerUseWal(pPager) ){
sqlite3WalCloseSnapshot(pPager->pWal);
}else{
rc = osUnlock(pPager->fd, NO_LOCK);
}
@ -1380,7 +1380,7 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
assert( isOpen(pPager->jfd) || pPager->pInJournal==0 );
if( isOpen(pPager->jfd) ){
assert( !pagerUseLog(pPager) );
assert( !pagerUseWal(pPager) );
/* Finalize the journal file. */
if( sqlite3IsMemJournal(pPager->jfd) ){
@ -1426,8 +1426,8 @@ static int pager_end_transaction(Pager *pPager, int hasMaster){
pPager->nRec = 0;
sqlite3PcacheCleanAll(pPager->pPCache);
if( pagerUseLog(pPager) ){
rc2 = sqlite3WalWriteLock(pPager->pLog, 0);
if( pagerUseWal(pPager) ){
rc2 = sqlite3WalWriteLock(pPager->pWal, 0);
pPager->state = PAGER_SHARED;
}else if( !pPager->exclusiveMode ){
rc2 = osUnlock(pPager->fd, SHARED_LOCK);
@ -1540,7 +1540,7 @@ static int pager_playback_one_page(
aData = pPager->pTmpSpace;
assert( aData ); /* Temp storage must have already been allocated */
assert( pagerUseLog(pPager)==0 || (!isMainJrnl && isSavepnt) );
assert( pagerUseWal(pPager)==0 || (!isMainJrnl && isSavepnt) );
/* Read the page number and page data from the journal or sub-journal
** file. Return an error code to the caller if an IO error occurs.
@ -1610,7 +1610,7 @@ static int pager_playback_one_page(
** is possible to fail a statement on a database that does not yet exist.
** Do not attempt to write if database file has never been opened.
*/
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
pPg = 0;
}else{
pPg = pager_lookup(pPager, pgno);
@ -1631,7 +1631,7 @@ static int pager_playback_one_page(
){
i64 ofst = (pgno-1)*(i64)pPager->pageSize;
testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
assert( !pagerUseLog(pPager) );
assert( !pagerUseWal(pPager) );
rc = sqlite3OsWrite(pPager->fd, (u8*)aData, pPager->pageSize, ofst);
if( pgno>pPager->dbFileSize ){
pPager->dbFileSize = pgno;
@ -1696,7 +1696,7 @@ static int pager_playback_one_page(
** segment is synced. If a crash occurs during or following this,
** database corruption may ensue.
*/
assert( !pagerUseLog(pPager) );
assert( !pagerUseWal(pPager) );
sqlite3PcacheMakeClean(pPg);
}
#ifdef SQLITE_CHECK_PAGES
@ -2188,7 +2188,7 @@ static int readDbPage(PgHdr *pPg){
Pgno pgno = pPg->pgno; /* Page number to read */
int rc = SQLITE_OK; /* Return code */
i64 iOffset; /* Byte offset of file to read from */
int isInLog = 0; /* True if page is in log file */
int isInWal = 0; /* True if page is in log file */
assert( pPager->state>=PAGER_SHARED && !MEMDB );
assert( isOpen(pPager->fd) );
@ -2199,11 +2199,11 @@ static int readDbPage(PgHdr *pPg){
return SQLITE_OK;
}
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
/* Try to pull the page from the write-ahead log. */
rc = sqlite3WalRead(pPager->pLog, pgno, &isInLog, pPg->pData);
rc = sqlite3WalRead(pPager->pWal, pgno, &isInWal, pPg->pData);
}
if( rc==SQLITE_OK && !isInLog ){
if( rc==SQLITE_OK && !isInWal ){
iOffset = (pgno-1)*(i64)pPager->pageSize;
rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
if( rc==SQLITE_IOERR_SHORT_READ ){
@ -2278,7 +2278,7 @@ static int pagerUndoCallback(void *pCtx, Pgno iPg){
/*
** This function is called to rollback a transaction on a WAL database.
*/
static int pagerRollbackLog(Pager *pPager){
static int pagerRollbackWal(Pager *pPager){
int rc; /* Return Code */
PgHdr *pList; /* List of dirty pages to revert */
@ -2290,7 +2290,7 @@ static int pagerRollbackLog(Pager *pPager){
** also copied into the backup databases) as part of this transaction,
** the backups must be restarted.
*/
if( sqlite3WalDirty(pPager->pLog) ){
if( sqlite3WalDirty(pPager->pWal) ){
sqlite3BackupRestart(pPager->pBackup);
}
@ -2302,7 +2302,7 @@ static int pagerRollbackLog(Pager *pPager){
** + Reload page content from the database (if refcount>0).
*/
pPager->dbSize = pPager->dbOrigSize;
rc = sqlite3WalUndo(pPager->pLog, pagerUndoCallback, (void *)pPager);
rc = sqlite3WalUndo(pPager->pWal, pagerUndoCallback, (void *)pPager);
pList = sqlite3PcacheDirtyList(pPager->pPCache);
while( pList && rc==SQLITE_OK ){
PgHdr *pNext = pList->pDirty;
@ -2370,8 +2370,8 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
*/
pPager->dbSize = pSavepoint ? pSavepoint->nOrig : pPager->dbOrigSize;
if( !pSavepoint && pagerUseLog(pPager) ){
return pagerRollbackLog(pPager);
if( !pSavepoint && pagerUseWal(pPager) ){
return pagerRollbackWal(pPager);
}
/* Use pPager->journalOff as the effective size of the main rollback
@ -2380,7 +2380,7 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
** past pPager->journalOff is off-limits to us.
*/
szJ = pPager->journalOff;
assert( pagerUseLog(pPager)==0 || szJ==0 );
assert( pagerUseWal(pPager)==0 || szJ==0 );
/* Begin by rolling back records from the main journal starting at
** PagerSavepoint.iOffset and continuing to the next journal header.
@ -2389,7 +2389,7 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
** will be skipped automatically. Pages are added to pDone as they
** are played back.
*/
if( pSavepoint && !pagerUseLog(pPager) ){
if( pSavepoint && !pagerUseWal(pPager) ){
iHdrOff = pSavepoint->iHdrOffset ? pSavepoint->iHdrOffset : szJ;
pPager->journalOff = pSavepoint->iOffset;
while( rc==SQLITE_OK && pPager->journalOff<iHdrOff ){
@ -2437,8 +2437,8 @@ static int pagerPlaybackSavepoint(Pager *pPager, PagerSavepoint *pSavepoint){
u32 ii; /* Loop counter */
i64 offset = pSavepoint->iSubRec*(4+pPager->pageSize);
if( pagerUseLog(pPager) ){
rc = sqlite3WalSavepointUndo(pPager->pLog, pSavepoint->iFrame);
if( pagerUseWal(pPager) ){
rc = sqlite3WalSavepointUndo(pPager->pWal, pSavepoint->iFrame);
}
for(ii=pSavepoint->iSubRec; rc==SQLITE_OK && ii<pPager->nSubRec; ii++){
assert( offset==ii*(4+pPager->pageSize) );
@ -2750,8 +2750,8 @@ int sqlite3PagerPagecount(Pager *pPager, int *pnPage){
int rc; /* Error returned by OsFileSize() */
i64 n = 0; /* File size in bytes returned by OsFileSize() */
if( pagerUseLog(pPager) ){
sqlite3WalDbsize(pPager->pLog, &nPage);
if( pagerUseWal(pPager) ){
sqlite3WalDbsize(pPager->pWal, &nPage);
}
if( nPage==0 ){
@ -2936,10 +2936,10 @@ int sqlite3PagerClose(Pager *pPager){
sqlite3BeginBenignMalloc();
pPager->errCode = 0;
pPager->exclusiveMode = 0;
sqlite3WalClose(pPager->pLog, pPager->fd,
sqlite3WalClose(pPager->pWal, pPager->fd,
(pPager->noSync ? 0 : pPager->sync_flags), pTmp
);
pPager->pLog = 0;
pPager->pWal = 0;
pager_reset(pPager);
if( MEMDB ){
pager_unlock(pPager);
@ -3176,7 +3176,7 @@ static int pager_write_pagelist(PgHdr *pList){
** EXCLUSIVE, it means the database file has been changed and any rollback
** will require a journal playback.
*/
assert( !pagerUseLog(pList->pPager) );
assert( !pagerUseWal(pList->pPager) );
assert( pPager->state>=PAGER_RESERVED );
rc = pager_wait_on_lock(pPager, EXCLUSIVE_LOCK);
@ -3265,7 +3265,7 @@ static int subjournalPage(PgHdr *pPg){
CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2);
PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
assert( pagerUseLog(pPager)
assert( pagerUseWal(pPager)
|| pageInJournal(pPg)
|| pPg->pgno>pPager->dbOrigSize
);
@ -3288,7 +3288,7 @@ static int subjournalPage(PgHdr *pPg){
** this function notifies any active backup processes that the pages have
** changed.
*/
static int pagerLogFrames(
static int pagerWalFrames(
Pager *pPager, /* Pager object */
PgHdr *pList, /* List of frames to log */
Pgno nTruncate, /* Database size after this commit */
@ -3297,8 +3297,8 @@ static int pagerLogFrames(
){
int rc; /* Return code */
assert( pPager->pLog );
rc = sqlite3WalFrames(pPager->pLog,
assert( pPager->pWal );
rc = sqlite3WalFrames(pPager->pWal,
pPager->pageSize, pList, nTruncate, isCommit, sync_flags
);
if( rc==SQLITE_OK && pPager->pBackup ){
@ -3337,13 +3337,13 @@ static int pagerStress(void *p, PgHdr *pPg){
assert( pPg->flags&PGHDR_DIRTY );
pPg->pDirty = 0;
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
/* Write a single frame for this page to the log. */
if( subjRequiresPage(pPg) ){
rc = subjournalPage(pPg);
}
if( rc==SQLITE_OK ){
rc = pagerLogFrames(pPager, pPg, 0, 0, 0);
rc = pagerWalFrames(pPager, pPg, 0, 0, 0);
}
}else{
/* The doNotSync flag is set by the sqlite3PagerWrite() function while it
@ -3836,12 +3836,12 @@ static int pagerHasWAL(Pager *pPager, int *pExists){
int rc; /* Return code */
if( !pPager->tempFile ){
char *zLog = sqlite3_mprintf("%s-wal", pPager->zFilename);
if( !zLog ){
char *zWal = sqlite3_mprintf("%s-wal", pPager->zFilename);
if( !zWal ){
rc = SQLITE_NOMEM;
}else{
rc = sqlite3OsAccess(pPager->pVfs, zLog, SQLITE_ACCESS_EXISTS, pExists);
sqlite3_free(zLog);
rc = sqlite3OsAccess(pPager->pVfs, zWal, SQLITE_ACCESS_EXISTS, pExists);
sqlite3_free(zWal);
}
}else{
rc = SQLITE_OK;
@ -3854,9 +3854,9 @@ static int pagerOpenSnapshot(Pager *pPager){
int rc; /* Return code */
int changed = 0; /* True if cache must be reset */
assert( pagerUseLog(pPager) );
assert( pagerUseWal(pPager) );
rc = sqlite3WalOpenSnapshot(pPager->pLog, &changed);
rc = sqlite3WalOpenSnapshot(pPager->pWal, &changed);
if( rc==SQLITE_OK ){
int dummy;
if( changed ){
@ -3923,7 +3923,7 @@ int sqlite3PagerSharedLock(Pager *pPager){
pager_reset(pPager);
}
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
rc = pagerOpenSnapshot(pPager);
}else if( pPager->state==PAGER_UNLOCK || isErrorReset ){
sqlite3_vfs * const pVfs = pPager->pVfs;
@ -4089,7 +4089,7 @@ int sqlite3PagerSharedLock(Pager *pPager){
}
if( isWal ){
pager_reset(pPager);
rc = sqlite3PagerOpenLog(pPager, 0);
rc = sqlite3PagerOpenWal(pPager, 0);
if( rc==SQLITE_OK ){
rc = pagerOpenSnapshot(pPager);
}
@ -4332,7 +4332,7 @@ void sqlite3PagerUnref(DbPage *pPg){
*/
static int openSubJournal(Pager *pPager){
int rc = SQLITE_OK;
if( (pagerUseLog(pPager) || isOpen(pPager->jfd)) && !isOpen(pPager->sjfd) ){
if( (pagerUseWal(pPager) || isOpen(pPager->jfd)) && !isOpen(pPager->sjfd) ){
if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY || pPager->subjInMemory ){
sqlite3MemJournalOpen(pPager->sjfd);
}else{
@ -4468,13 +4468,13 @@ int sqlite3PagerBegin(Pager *pPager, int exFlag, int subjInMemory){
assert( pPager->pInJournal==0 );
assert( !MEMDB && !pPager->tempFile );
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
/* Grab the write lock on the log file. If successful, upgrade to
** PAGER_EXCLUSIVE state. Otherwise, return an error code to the caller.
** The busy-handler is not invoked if another connection already
** holds the write-lock. If possible, the upper layer will call it.
*/
rc = sqlite3WalWriteLock(pPager->pLog, 1);
rc = sqlite3WalWriteLock(pPager->pWal, 1);
if( rc==SQLITE_OK ){
pPager->dbOrigSize = pPager->dbSize;
pPager->state = PAGER_RESERVED;
@ -4507,7 +4507,7 @@ int sqlite3PagerBegin(Pager *pPager, int exFlag, int subjInMemory){
** kept open and either was truncated to 0 bytes or its header was
** overwritten with zeros.
*/
assert( pagerUseLog(pPager)==0 );
assert( pagerUseWal(pPager)==0 );
assert( pPager->nRec==0 );
assert( pPager->dbOrigSize==0 );
assert( pPager->pInJournal==0 );
@ -4562,7 +4562,7 @@ static int pager_write(PgHdr *pPg){
*/
sqlite3PcacheMakeDirty(pPg);
if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){
assert( !pagerUseLog(pPager) );
assert( !pagerUseWal(pPager) );
pPager->dbModified = 1;
}else{
@ -4580,7 +4580,7 @@ static int pager_write(PgHdr *pPg){
}
if( !isOpen(pPager->jfd)
&& pPager->journalMode!=PAGER_JOURNALMODE_OFF
&& !pagerUseLog(pPager)
&& !pagerUseWal(pPager)
){
assert( pPager->useJournal );
rc = pager_open_journal(pPager);
@ -4593,7 +4593,7 @@ static int pager_write(PgHdr *pPg){
** the transaction journal if it is not there already.
*/
if( !pageInJournal(pPg) && isOpen(pPager->jfd) ){
assert( !pagerUseLog(pPager) );
assert( !pagerUseWal(pPager) );
if( pPg->pgno<=pPager->dbOrigSize ){
u32 cksum;
char *pData2;
@ -4974,10 +4974,10 @@ int sqlite3PagerCommitPhaseOne(
*/
sqlite3BackupRestart(pPager->pBackup);
}else if( pPager->state!=PAGER_SYNCED && pPager->dbModified ){
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
if( pList ){
rc = pagerLogFrames(pPager, pList, pPager->dbSize, 1,
rc = pagerWalFrames(pPager, pList, pPager->dbSize, 1,
(pPager->fullSync ? pPager->sync_flags : 0)
);
}
@ -5213,7 +5213,7 @@ int sqlite3PagerCommitPhaseTwo(Pager *pPager){
int sqlite3PagerRollback(Pager *pPager){
int rc = SQLITE_OK; /* Return code */
PAGERTRACE(("ROLLBACK %d\n", PAGERID(pPager)));
if( pagerUseLog(pPager) ){
if( pagerUseWal(pPager) ){
int rc2;
rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
@ -5360,8 +5360,8 @@ int sqlite3PagerOpenSavepoint(Pager *pPager, int nSavepoint){
if( !aNew[ii].pInSavepoint ){
return SQLITE_NOMEM;
}
if( pagerUseLog(pPager) ){
aNew[ii].iFrame = sqlite3WalSavepoint(pPager->pLog);
if( pagerUseWal(pPager) ){
aNew[ii].iFrame = sqlite3WalSavepoint(pPager->pWal);
}
}
@ -5440,7 +5440,7 @@ int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
** not yet been opened. In this case there have been no changes to
** the database file, so the playback operation can be skipped.
*/
else if( pagerUseLog(pPager) || isOpen(pPager->jfd) ){
else if( pagerUseWal(pPager) || isOpen(pPager->jfd) ){
PagerSavepoint *pSavepoint = (nNew==0)?0:&pPager->aSavepoint[nNew-1];
rc = pagerPlaybackSavepoint(pPager, pSavepoint);
assert(rc!=SQLITE_DONE);
@ -5796,9 +5796,9 @@ sqlite3_backup **sqlite3PagerBackupPtr(Pager *pPager){
*/
int sqlite3PagerCheckpoint(Pager *pPager){
int rc = SQLITE_OK;
if( pPager->pLog ){
if( pPager->pWal ){
u8 *zBuf = (u8 *)pPager->pTmpSpace;
rc = sqlite3WalCheckpoint(pPager->pLog, pPager->fd,
rc = sqlite3WalCheckpoint(pPager->pWal, pPager->fd,
(pPager->noSync ? 0 : pPager->sync_flags),
zBuf, pPager->xBusyHandler, pPager->pBusyHandlerArg
);
@ -5806,8 +5806,8 @@ int sqlite3PagerCheckpoint(Pager *pPager){
return rc;
}
int sqlite3PagerLogCallback(Pager *pPager){
return sqlite3WalCallback(pPager->pLog);
int sqlite3PagerWalCallback(Pager *pPager){
return sqlite3WalCallback(pPager->pWal);
}
/*
@ -5817,17 +5817,17 @@ int sqlite3PagerLogCallback(Pager *pPager){
** The caller must be holding a SHARED lock on the database file to call
** this function.
*/
int sqlite3PagerOpenLog(Pager *pPager, int *pisOpen){
int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen){
int rc = SQLITE_OK; /* Return code */
assert( pPager->state>=PAGER_SHARED );
if( !pPager->pLog ){
if( !pPager->pWal ){
/* Open the connection to the log file. If this operation fails,
** (e.g. due to malloc() failure), unlock the database file and
** return an error code.
*/
rc = sqlite3WalOpen(pPager->pVfs, pPager->zFilename, &pPager->pLog);
rc = sqlite3WalOpen(pPager->pVfs, pPager->zFilename, &pPager->pWal);
if( rc==SQLITE_OK ){
pPager->journalMode = PAGER_JOURNALMODE_WAL;
}
@ -5848,7 +5848,7 @@ int sqlite3PagerOpenLog(Pager *pPager, int *pisOpen){
** error (SQLITE_BUSY) is returned and the log connection is not closed.
** If successful, the EXCLUSIVE lock is not released before returning.
*/
int sqlite3PagerCloseLog(Pager *pPager){
int sqlite3PagerCloseWal(Pager *pPager){
int rc = SQLITE_OK;
assert( pPager->journalMode==PAGER_JOURNALMODE_WAL );
@ -5857,28 +5857,28 @@ int sqlite3PagerCloseLog(Pager *pPager){
** it may need to be checkpointed before the connection can switch to
** rollback mode. Open it now so this can happen.
*/
if( !pPager->pLog ){
if( !pPager->pWal ){
int logexists = 0;
rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_SHARED);
if( rc==SQLITE_OK ){
rc = pagerHasWAL(pPager, &logexists);
}
if( rc==SQLITE_OK && logexists ){
rc = sqlite3WalOpen(pPager->pVfs, pPager->zFilename, &pPager->pLog);
rc = sqlite3WalOpen(pPager->pVfs, pPager->zFilename, &pPager->pWal);
}
}
/* Checkpoint and close the log. Because an EXCLUSIVE lock is held on
** the database file, the log and log-summary files will be deleted.
*/
if( rc==SQLITE_OK && pPager->pLog ){
if( rc==SQLITE_OK && pPager->pWal ){
rc = sqlite3OsLock(pPager->fd, SQLITE_LOCK_EXCLUSIVE);
if( rc==SQLITE_OK ){
rc = sqlite3WalClose(pPager->pLog, pPager->fd,
rc = sqlite3WalClose(pPager->pWal, pPager->fd,
(pPager->noSync ? 0 : pPager->sync_flags),
(u8*)pPager->pTmpSpace
);
pPager->pLog = 0;
pPager->pWal = 0;
}
}
return rc;

View File

@ -135,9 +135,9 @@ int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
int sqlite3PagerSharedLock(Pager *pPager);
int sqlite3PagerCheckpoint(Pager *pPager);
int sqlite3PagerLogCallback(Pager *pPager);
int sqlite3PagerOpenLog(Pager *pPager, int *pisOpen);
int sqlite3PagerCloseLog(Pager *pPager);
int sqlite3PagerWalCallback(Pager *pPager);
int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
int sqlite3PagerCloseWal(Pager *pPager);
/* Functions used to query pager state and configuration. */
u8 sqlite3PagerIsreadonly(Pager*);

View File

@ -844,7 +844,7 @@ struct sqlite3_vfs {
** definition. Those that follow are added in version 2 or later
*/
int (*xShmOpen)(sqlite3_vfs*, const char *zName, sqlite3_shm**);
int (*xShmSize)(sqlite3_shm*, int reqSize, int *pNewSize, char**);
int (*xShmSize)(sqlite3_shm*, int reqSize, int *pNewSize, void**);
int (*xShmRelease)(sqlite3_shm*);
int (*xShmPush)(sqlite3_shm*);
int (*xShmPull)(sqlite3_shm*);

View File

@ -823,8 +823,8 @@ struct sqlite3 {
void (*xRollbackCallback)(void*); /* Invoked at every commit. */
void *pUpdateArg;
void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
int (*xLogCallback)(void *, sqlite3 *, const char *, int);
void *pLogArg;
int (*xWalCallback)(void *, sqlite3 *, const char *, int);
void *pWalArg;
void(*xCollNeeded)(void*,sqlite3*,int eTextRep,const char*);
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
void *pCollNeededArg;

View File

@ -5113,7 +5113,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
#ifdef SQLITE_TEST
extern char sqlite3_query_plan[];
static char *query_plan = sqlite3_query_plan;
extern int sqlite3_walsummary_mmap_incr; /* In wal.c */
/* extern int sqlite3_walsummary_mmap_incr; // In wal.c */
#ifdef SQLITE_ENABLE_FTS3
extern int sqlite3_fts3_enable_parentheses;
#endif
@ -5173,8 +5173,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
#ifdef SQLITE_TEST
Tcl_LinkVar(interp, "sqlite_query_plan",
(char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
Tcl_LinkVar(interp, "sqlite_walsummary_mmap_incr",
(char*)&sqlite3_walsummary_mmap_incr, TCL_LINK_INT);
/* Tcl_LinkVar(interp, "sqlite_walsummary_mmap_incr",
(char*)&sqlite3_walsummary_mmap_incr, TCL_LINK_INT); */
#endif
#ifdef SQLITE_DEBUG
Tcl_LinkVar(interp, "sqlite_addop_trace",

View File

@ -5252,11 +5252,11 @@ case OP_JournalMode: {
if( eOld==PAGER_JOURNALMODE_WAL ){
/* If leaving WAL mode, close the log file. If successful, the call
** to PagerCloseLog() checkpoints and deletes the write-ahead-log
** to PagerCloseWal() checkpoints and deletes the write-ahead-log
** file. An EXCLUSIVE lock may still be held on the database file
** after a successful return.
*/
rc = sqlite3PagerCloseLog(pPager);
rc = sqlite3PagerCloseWal(pPager);
if( rc!=SQLITE_OK ) goto abort_due_to_error;
sqlite3PagerJournalMode(pPager, eNew);
}else{

View File

@ -306,15 +306,15 @@ void sqlite3_result_error_nomem(sqlite3_context *pCtx){
pCtx->s.db->mallocFailed = 1;
}
static int doLogCallbacks(sqlite3 *db){
static int doWalCallbacks(sqlite3 *db){
int i;
int rc = SQLITE_OK;
for(i=0; i<db->nDb; i++){
Btree *pBt = db->aDb[i].pBt;
if( pBt ){
int nEntry = sqlite3PagerLogCallback(sqlite3BtreePager(pBt));
if( db->xLogCallback && nEntry>0 && rc==SQLITE_OK
&& db->xLogCallback(db->pLogArg, db, db->aDb[i].zName, nEntry)
int nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK
&& db->xWalCallback(db->pWalArg, db, db->aDb[i].zName, nEntry)
){
rc = sqlite3PagerCheckpoint(sqlite3BtreePager(pBt));
}
@ -406,7 +406,7 @@ static int sqlite3Step(Vdbe *p){
if( rc==SQLITE_DONE ){
assert( p->rc==SQLITE_OK );
p->rc = doLogCallbacks(db);
p->rc = doWalCallbacks(db);
if( p->rc!=SQLITE_OK ){
rc = SQLITE_ERROR;
}

1485
src/wal.c

File diff suppressed because it is too large Load Diff

View File

@ -22,11 +22,11 @@
/* Connection to a write-ahead log (WAL) file.
** There is one object of this type for each pager.
*/
typedef struct Log Log;
typedef struct Wal Wal;
/* Open and close a connection to a write-ahead log. */
int sqlite3WalOpen(sqlite3_vfs*, const char *zDb, Log **ppLog);
int sqlite3WalClose(Log *pLog, sqlite3_file *pFd, int sync_flags, u8 *zBuf);
int sqlite3WalOpen(sqlite3_vfs*, const char *zDb, Wal **ppWal);
int sqlite3WalClose(Wal *pWal, sqlite3_file *pFd, int sync_flags, u8 *zBuf);
/* Used by readers to open (lock) and close (unlock) a snapshot. A
** snapshot is like a read-transaction. It is the state of the database
@ -35,39 +35,39 @@ int sqlite3WalClose(Log *pLog, sqlite3_file *pFd, int sync_flags, u8 *zBuf);
** write to or checkpoint the WAL. sqlite3WalCloseSnapshot() closes the
** transaction and releases the lock.
*/
int sqlite3WalOpenSnapshot(Log *pLog, int *);
void sqlite3WalCloseSnapshot(Log *pLog);
int sqlite3WalOpenSnapshot(Wal *pWal, int *);
void sqlite3WalCloseSnapshot(Wal *pWal);
/* Read a page from the write-ahead log, if it is present. */
int sqlite3WalRead(Log *pLog, Pgno pgno, int *pInLog, u8 *pOut);
int sqlite3WalRead(Wal *pWal, Pgno pgno, int *pInWal, u8 *pOut);
/* Return the size of the database as it existed at the beginning
** of the snapshot */
void sqlite3WalDbsize(Log *pLog, Pgno *pPgno);
void sqlite3WalDbsize(Wal *pWal, Pgno *pPgno);
/* Obtain or release the WRITER lock. */
int sqlite3WalWriteLock(Log *pLog, int op);
int sqlite3WalWriteLock(Wal *pWal, int op);
/* Undo any frames written (but not committed) to the log */
int sqlite3WalUndo(Log *pLog, int (*xUndo)(void *, Pgno), void *pUndoCtx);
int sqlite3WalUndo(Wal *pWal, int (*xUndo)(void *, Pgno), void *pUndoCtx);
/* Return an integer that records the current (uncommitted) write
** position in the WAL */
u32 sqlite3WalSavepoint(Log *pLog);
u32 sqlite3WalSavepoint(Wal *pWal);
/* Move the write position of the WAL back to iFrame. Called in
** response to a ROLLBACK TO command. */
int sqlite3WalSavepointUndo(Log *pLog, u32 iFrame);
int sqlite3WalSavepointUndo(Wal *pWal, u32 iFrame);
/* Return true if data has been written but not committed to the log file. */
int sqlite3WalDirty(Log *pLog);
int sqlite3WalDirty(Wal *pWal);
/* Write a frame or frames to the log. */
int sqlite3WalFrames(Log *pLog, int, PgHdr *, Pgno, int, int);
int sqlite3WalFrames(Wal *pWal, int, PgHdr *, Pgno, int, int);
/* Copy pages from the log to the database file */
int sqlite3WalCheckpoint(
Log *pLog, /* Log connection */
Wal *pWal, /* Write-ahead log connection */
sqlite3_file *pFd, /* File descriptor open on db file */
int sync_flags, /* Flags to sync db file with (or 0) */
u8 *zBuf, /* Temporary buffer to use */
@ -80,6 +80,6 @@ int sqlite3WalCheckpoint(
** sqlite3WalCallback() was called. If no commits have occurred since
** the last call, then return 0.
*/
int sqlite3WalCallback(Log *pLog);
int sqlite3WalCallback(Wal *pWal);
#endif /* _WAL_H_ */