If a call to sqlite3rbu_close() on an rbu handle opened by sqlite3rbu_vacuum() returns other than SQLITE_OK, delete the contents of the rbu_state table. This ensures that if an RBU vacuum operation either completes successfully or encounters an error, the next call to sqlite3rbu_vacuum() with the same parameters starts a new RBU vacuum operation.

FossilOrigin-Name: 6e4ac704f51bdd1e0b16814f6a45ab29f26400ee
This commit is contained in:
dan
2016-04-21 16:44:38 +00:00
parent 2e8bfb67d4
commit b7a208686a
5 changed files with 24 additions and 13 deletions
-3
View File
@@ -19,7 +19,6 @@ set ::testprefix rbuvacuum
proc do_rbu_vacuum_test {tn step} {
uplevel [list do_test $tn.1 {
forcedelete state.db
if {$step==0} { sqlite3rbu_vacuum rbu test.db state.db }
while 1 {
if {$step==1} { sqlite3rbu_vacuum rbu test.db state.db }
@@ -275,7 +274,6 @@ do_execsql_test 2.1.0 {
INSERT INTO t1 VALUES(9, 10);
} wal
do_test 2.1.1 {
forcedelete state.db
sqlite3rbu_vacuum rbu test.db state.db
rbu step
} {SQLITE_ERROR}
@@ -294,7 +292,6 @@ do_execsql_test 2.2.0 {
}
db_save_and_close
for {set i 1} 1 {incr i} {
forcedelete state.db
db_restore_and_reopen
sqlite3rbu_vacuum rbu test.db state.db
+10
View File
@@ -3685,6 +3685,16 @@ int sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){
/* Close any open statement handles. */
rbuObjIterFinalize(&p->objiter);
/* If this is an RBU vacuum handle and the vacuum has either finished
** successfully or encountered an error, delete the contents of the
** state table. This causes the next call to sqlite3rbu_vacuum()
** specifying the current target and state databases to start a new
** vacuum from scratch. */
if( rbuIsVacuum(p) && p->rc!=SQLITE_OK && p->dbRbu ){
int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
if( p->rc==SQLITE_DONE && rc2!=SQLITE_OK ) p->rc = rc2;
}
/* Close the open database handle and VFS object. */
sqlite3_close(p->dbRbu);
sqlite3_close(p->dbMain);
+5 -1
View File
@@ -330,7 +330,11 @@ sqlite3rbu *sqlite3rbu_open(
** handle specifying the same target and state databases.
**
** This function does not delete the state database after an RBU vacuum
** is completed, even if it created it.
** is completed, even if it created it. However, if the call to
** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
** of the state tables within the state database are zeroed. This way,
** the next call to sqlite3rbu_vacuum() opens a handle that starts a
** new RBU vacuum operation.
**
** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
** describing the sqlite3rbu_create_vfs() API function below for