mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Fix a problem that could cause a spurious SQLITE_NOMEM error when attempting
to resume an RBU operation if the previous client failed right after completing the incremental checkpoint. Also a "cannot vacuum wal db" error that could occur when resuming an RBU vacuum if an error (OOM or IO error) occurs during the incremental checkpoint. FossilOrigin-Name: 681d96eb822e606da53700867191d4738bda20c8
This commit is contained in:
66
ext/rbu/rbufault4.test
Normal file
66
ext/rbu/rbufault4.test
Normal file
@ -0,0 +1,66 @@
|
||||
# 2014 October 22
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
|
||||
if {![info exists testdir]} {
|
||||
set testdir [file join [file dirname [info script]] .. .. test]
|
||||
}
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
set ::testprefix rbufault4
|
||||
|
||||
for {set tn 1} {1} {incr tn} {
|
||||
reset_db
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
CREATE INDEX i1b ON t1(b);
|
||||
CREATE INDEX i1c ON t1(c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
}
|
||||
|
||||
forcedelete test.db2
|
||||
sqlite3rbu_vacuum rbu test.db test.db2
|
||||
for {set i 0} {$i < $tn} {incr i} { rbu step }
|
||||
set rc [rbu close]
|
||||
if {$rc!="SQLITE_OK"} {
|
||||
if {$rc!="SQLITE_DONE"} {error $rc}
|
||||
break
|
||||
}
|
||||
faultsim_save
|
||||
|
||||
do_faultsim_test $tn -faults oom-t* -prep {
|
||||
faultsim_restore
|
||||
} -body {
|
||||
sqlite3rbu_vacuum rbu test.db test.db2
|
||||
while 1 {
|
||||
set rc [rbu step]
|
||||
if {$rc=="SQLITE_DONE"} break
|
||||
if {$rc!="SQLITE_OK"} { error $rc }
|
||||
}
|
||||
} -test {
|
||||
catch {rbu close}
|
||||
faultsim_test_result {0 {}} {1 SQLITE_NOMEM} {1 SQLITE_IOERR_NOMEM}
|
||||
|
||||
sqlite3rbu_vacuum rbu test.db test.db2
|
||||
while {[rbu step]=="SQLITE_OK"} {}
|
||||
set trc [rbu close]
|
||||
if {$trc!="SQLITE_DONE"} { error "Got $trc instead of SQLITE_DONE!" }
|
||||
|
||||
set rc [db one {PRAGMA integrity_check}]
|
||||
if {$rc!="ok"} { error "Got $rc instead of ok!" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
@ -199,6 +199,37 @@ if {$::tcl_platform(platform)=="unix"} {
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test the outcome of some other connection running a checkpoint while
|
||||
# the incremental checkpoint is suspended.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 6.0 {
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
CREATE INDEX i1b ON t1(b);
|
||||
CREATE INDEX i1c ON t1(c);
|
||||
INSERT INTO t1 VALUES(1, 2, 3);
|
||||
INSERT INTO t1 VALUES(4, 5, 6);
|
||||
}
|
||||
forcedelete test.db2
|
||||
|
||||
do_test 6.1 {
|
||||
sqlite3rbu_vacuum rbu test.db test.db2
|
||||
while {[rbu state]!="checkpoint"} { rbu step }
|
||||
rbu close
|
||||
} {SQLITE_OK}
|
||||
|
||||
do_execsql_test 6.2 {
|
||||
SELECT 1 FROM sqlite_master LIMIT 1;
|
||||
PRAGMA wal_checkpoint;
|
||||
} {1 0 4 4}
|
||||
|
||||
do_test 6.3 {
|
||||
sqlite3rbu_vacuum rbu test.db test.db2
|
||||
while {[rbu step]!="SQLITE_DONE"} { rbu step }
|
||||
rbu close
|
||||
execsql { PRAGMA integrity_check }
|
||||
} {ok}
|
||||
|
||||
finish_test
|
||||
|
||||
|
@ -2333,7 +2333,7 @@ static RbuState *rbuLoadState(sqlite3rbu *p){
|
||||
** Open the database handle and attach the RBU database as "rbu". If an
|
||||
** error occurs, leave an error code and message in the RBU handle.
|
||||
*/
|
||||
static void rbuOpenDatabase(sqlite3rbu *p){
|
||||
static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){
|
||||
assert( p->rc || (p->dbMain==0 && p->dbRbu==0) );
|
||||
assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 );
|
||||
|
||||
@ -2420,6 +2420,15 @@ static void rbuOpenDatabase(sqlite3rbu *p){
|
||||
if( !rbuIsVacuum(p) ){
|
||||
p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
|
||||
}else if( p->pRbuFd->pWalFd ){
|
||||
if( pbRetry ){
|
||||
p->pRbuFd->bNolock = 0;
|
||||
sqlite3_close(p->dbRbu);
|
||||
sqlite3_close(p->dbMain);
|
||||
p->dbMain = 0;
|
||||
p->dbRbu = 0;
|
||||
*pbRetry = 1;
|
||||
return;
|
||||
}
|
||||
p->rc = SQLITE_ERROR;
|
||||
p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
|
||||
}else{
|
||||
@ -2600,16 +2609,18 @@ static void rbuSetupCheckpoint(sqlite3rbu *p, RbuState *pState){
|
||||
if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
|
||||
}
|
||||
|
||||
if( p->rc==SQLITE_OK ){
|
||||
if( p->rc==SQLITE_OK && p->nFrame>0 ){
|
||||
p->eStage = RBU_STAGE_CKPT;
|
||||
p->nStep = (pState ? pState->nRow : 0);
|
||||
p->aBuf = rbuMalloc(p, p->pgsz);
|
||||
p->iWalCksum = rbuShmChecksum(p);
|
||||
}
|
||||
|
||||
if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){
|
||||
p->rc = SQLITE_DONE;
|
||||
p->eStage = RBU_STAGE_DONE;
|
||||
if( p->rc==SQLITE_OK ){
|
||||
if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){
|
||||
p->rc = SQLITE_DONE;
|
||||
p->eStage = RBU_STAGE_DONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2782,7 +2793,7 @@ static void rbuMoveOalFile(sqlite3rbu *p){
|
||||
#endif
|
||||
|
||||
if( p->rc==SQLITE_OK ){
|
||||
rbuOpenDatabase(p);
|
||||
rbuOpenDatabase(p, 0);
|
||||
rbuSetupCheckpoint(p, 0);
|
||||
}
|
||||
}
|
||||
@ -3493,6 +3504,7 @@ static sqlite3rbu *openRbuHandle(
|
||||
/* Open the target, RBU and state databases */
|
||||
if( p->rc==SQLITE_OK ){
|
||||
char *pCsr = (char*)&p[1];
|
||||
int bRetry = 0;
|
||||
if( zTarget ){
|
||||
p->zTarget = pCsr;
|
||||
memcpy(p->zTarget, zTarget, nTarget+1);
|
||||
@ -3504,7 +3516,18 @@ static sqlite3rbu *openRbuHandle(
|
||||
if( zState ){
|
||||
p->zState = rbuMPrintf(p, "%s", zState);
|
||||
}
|
||||
rbuOpenDatabase(p);
|
||||
|
||||
/* If the first attempt to open the database file fails and the bRetry
|
||||
** flag it set, this means that the db was not opened because it seemed
|
||||
** to be a wal-mode db. But, this may have happened due to an earlier
|
||||
** RBU vacuum operation leaving an old wal file in the directory.
|
||||
** If this is the case, it will have been checkpointed and deleted
|
||||
** when the handle was closed and a second attempt to open the
|
||||
** database may succeed. */
|
||||
rbuOpenDatabase(p, &bRetry);
|
||||
if( bRetry ){
|
||||
rbuOpenDatabase(p, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if( p->rc==SQLITE_OK ){
|
||||
|
Reference in New Issue
Block a user