1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Add the SQLITE_FCNTL_RESET_CACHE verb. Use it to ensure that the page cache is purged before and after a the recovery extension is run.

FossilOrigin-Name: 6db0bc4bc0d272b610bef2aeeae43f539ed6e7cc0a9cc767d5af85ecb0019d5f
This commit is contained in:
dan
2022-11-28 18:41:41 +00:00
parent e862b5fe1d
commit 1b3d13e65e
8 changed files with 82 additions and 14 deletions

View File

@@ -273,5 +273,46 @@ do_execsql_test 15.1 {
} {}
do_recover_test 15
#-------------------------------------------------------------------------
reset_db
do_execsql_test 16.1 {
PRAGMA journal_mode = wal;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(1), (2), (3);
} {wal}
do_test 16.2 {
set R [sqlite3_recover_init db main test.db2]
$R run
$R finish
} {}
do_execsql_test 16.3 {
SELECT * FROM t1;
} {1 2 3}
do_execsql_test 16.4 {
BEGIN;
SELECT * FROM t1;
} {1 2 3}
do_test 16.5 {
set R [sqlite3_recover_init db main test.db2]
$R run
list [catch { $R finish } msg] $msg
} {1 {cannot start a transaction within a transaction}}
do_execsql_test 16.6 {
SELECT * FROM t1;
} {1 2 3}
do_execsql_test 16.7 {
INSERT INTO t1 VALUES(4);
}
do_test 16.8 {
set R [sqlite3_recover_init db main test.db2]
$R run
list [catch { $R finish } msg] $msg
} {1 {cannot start a transaction within a transaction}}
do_execsql_test 16.9 {
SELECT * FROM t1;
COMMIT;
} {1 2 3 4}
finish_test

View File

@@ -2017,6 +2017,7 @@ static void recoverFinalCleanup(sqlite3_recover *p){
p->pTblList = 0;
sqlite3_finalize(p->pGetPage);
p->pGetPage = 0;
sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0);
{
#ifndef NDEBUG
@@ -2315,6 +2316,7 @@ static int recoverVfsRead(sqlite3_file *pFd, void *aBuf, int nByte, i64 iOff){
**
** + first freelist page (32-bits at offset 32)
** + size of freelist (32-bits at offset 36)
** + the wal-mode flags (16-bits at offset 18)
**
** We also try to preserve the auto-vacuum, incr-value, user-version
** and application-id fields - all 32 bit quantities at offsets
@@ -2378,7 +2380,8 @@ static int recoverVfsRead(sqlite3_file *pFd, void *aBuf, int nByte, i64 iOff){
if( p->pPage1Cache ){
p->pPage1Disk = &p->pPage1Cache[nByte];
memcpy(p->pPage1Disk, aBuf, nByte);
aHdr[18] = a[18];
aHdr[19] = a[19];
recoverPutU32(&aHdr[28], dbsz);
recoverPutU32(&aHdr[56], enc);
recoverPutU16(&aHdr[105], pgsz-nReserve);
@@ -2574,6 +2577,7 @@ static void recoverStep(sqlite3_recover *p){
recoverOpenOutput(p);
/* Open transactions on both the input and output databases. */
sqlite3_file_control(p->dbIn, p->zDb, SQLITE_FCNTL_RESET_CACHE, 0);
recoverExec(p, p->dbIn, "PRAGMA writable_schema = on");
recoverExec(p, p->dbIn, "BEGIN");
if( p->errCode==SQLITE_OK ) p->bCloseTransaction = 1;