Index: src/wal.c ================================================================== --- src/wal.c +++ src/wal.c @@ -2900,15 +2900,17 @@ ** SQLITE_OK is returned if no error is encountered (regardless of whether ** or not pWal->hdr.mxFrame is modified). An SQLite error code is returned ** if an error occurs. */ static int walRestartLog(Wal *pWal){ + volatile WalCkptInfo *pInfo = walCkptInfo(pWal); int rc = SQLITE_OK; int cnt; - if( pWal->readLock==0 ){ - volatile WalCkptInfo *pInfo = walCkptInfo(pWal); + if( pWal->readLock==0 + || (walIsServer(pWal) && pInfo->nBackfill==pWal->hdr.mxFrame) + ){ assert( pInfo->nBackfill==pWal->hdr.mxFrame ); if( pInfo->nBackfill>0 ){ u32 salt1; sqlite3_randomness(4, &salt1); rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); @@ -2926,10 +2928,11 @@ walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); }else if( rc!=SQLITE_BUSY ){ return rc; } } + if( walIsServer(pWal) ) return rc; walUnlockShared(pWal, WAL_READ_LOCK(0)); pWal->readLock = -1; cnt = 0; do{ int notUsed; Index: test/serverwal.test ================================================================== --- test/serverwal.test +++ test/serverwal.test @@ -34,10 +34,11 @@ do_test 1.4 { db close glob test.db* } {test.db} +#------------------------------------------------------------------------- # Two concurrent transactions. # do_test 2.0 { sqlite3 db test.db sqlite3 db2 test.db @@ -57,8 +58,33 @@ } {} do_test 2.2 { execsql COMMIT db execsql COMMIT db2 } {} +db close + +#------------------------------------------------------------------------- +# That the wal file can be wrapped around. +# +reset_db +do_execsql_test 3.0 { + PRAGMA journal_mode = wal; + CREATE TABLE ttt(a, b); + INSERT INTO ttt VALUES(1, 2); + INSERT INTO ttt VALUES(3, 4); + INSERT INTO ttt VALUES(5, 6); + INSERT INTO ttt VALUES(7, 8); + INSERT INTO ttt VALUES(9, 10); +} {wal} +do_test 3.1 { + set N [file size test.db-wal] + execsql { + PRAGMA wal_checkpoint; + INSERT INTO ttt VALUES(11, 12); + INSERT INTO ttt VALUES(13, 14); + } + expr {$N == [file size test.db-wal]} +} {1} finish_test +