aboutsummaryrefslogtreecommitdiff
path: root/ext/rbu/sqlite3rbu.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2017-03-02 14:51:47 +0000
committerdan <dan@noemail.net>2017-03-02 14:51:47 +0000
commitcb1b0a693ac7aef2f05c65dba4d4bf5d78d4cf3b (patch)
tree65b4b1409dea7d5209e56c7dfba5a3bb0caac643 /ext/rbu/sqlite3rbu.c
parent76adb239805a543742232090cd4399db3f8f46f6 (diff)
downloadsqlite-cb1b0a693ac7aef2f05c65dba4d4bf5d78d4cf3b.tar.gz
sqlite-cb1b0a693ac7aef2f05c65dba4d4bf5d78d4cf3b.zip
When saving the state of an RBU update in the incremental-checkpoint phase,
sync the database file. Otherwise, if a power failure occurs and the RBU update resumed following system recovery, the database may become corrupt. FossilOrigin-Name: edee6a80e1cc7e6a2b8c3c7f76dd794fc8ab9a72
Diffstat (limited to 'ext/rbu/sqlite3rbu.c')
-rw-r--r--ext/rbu/sqlite3rbu.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/rbu/sqlite3rbu.c b/ext/rbu/sqlite3rbu.c
index 48c69115e..262f96ea3 100644
--- a/ext/rbu/sqlite3rbu.c
+++ b/ext/rbu/sqlite3rbu.c
@@ -3718,6 +3718,12 @@ int sqlite3rbu_close(sqlite3rbu *p, char **pzErrmsg){
p->rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, &p->zErrmsg);
}
+ /* Sync the db file if currently doing an incremental checkpoint */
+ if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){
+ sqlite3_file *pDb = p->pTargetFd->pReal;
+ p->rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
+ }
+
rbuSaveState(p, p->eStage);
if( p->rc==SQLITE_OK && p->eStage==RBU_STAGE_OAL ){
@@ -3842,6 +3848,12 @@ int sqlite3rbu_savestate(sqlite3rbu *p){
if( rc==SQLITE_OK ) rc = sqlite3_exec(p->dbMain, "COMMIT", 0, 0, 0);
}
+ /* Sync the db file */
+ if( rc==SQLITE_OK && p->eStage==RBU_STAGE_CKPT ){
+ sqlite3_file *pDb = p->pTargetFd->pReal;
+ rc = pDb->pMethods->xSync(pDb, SQLITE_SYNC_NORMAL);
+ }
+
p->rc = rc;
rbuSaveState(p, p->eStage);
rc = p->rc;