For a pager backed by a temp file, store the main journal in memory until it is at least sqlite3_config.nStmtSpill bytes in size. Prevent the backup API from being used to change the page-size of a temp file.

FossilOrigin-Name: 84c557010c211595d2ec80b62c63af1c7f4714bd
This commit is contained in:
dan 2016-04-06 18:20:51 +00:00
parent 7f8def285e
commit 9131ab9386
6 changed files with 110 additions and 35 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sproblem\sin\stest\sscript\slock.test.\sFix\sminor\sissues\sin\spager.c.
D 2016-04-06T16:27:50.054
C For\sa\spager\sbacked\sby\sa\stemp\sfile,\sstore\sthe\smain\sjournal\sin\smemory\suntil\sit\sis\sat\sleast\ssqlite3_config.nStmtSpill\sbytes\sin\ssize.\sPrevent\sthe\sbackup\sAPI\sfrom\sbeing\sused\sto\schange\sthe\spage-size\sof\sa\stemp\sfile.
D 2016-04-06T18:20:51.565
F Makefile.in eba680121821b8a60940a81454316f47a341487a
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 1f123a0757f6f04f0341accb46457e116817159a
@ -362,7 +362,7 @@ F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c b1ccb273771f41dbdbe0ba7c1ad63c38ad5972ec
F src/os_win.c b3ba9573d8d893e70a6a8015bbee572ecf7ffbef
F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca
F src/pager.c 2047e837a5df26c16271e77e6b30021d0cdc98b7
F src/pager.c 91d7462aa2429e30d64c705f75ba36cace90c241
F src/pager.h e1d38a2f14849e219df0f91f8323504d134c8a56
F src/parse.y 5ea8c81c5c41b27887f41b4a7e1c58470d7d3821
F src/pcache.c e9c00846d3dcdaa75b288c6f16238c2fe2177823
@ -387,7 +387,7 @@ F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
F src/tclsqlite.c 56569acc73d36e836b64aefecbbb709a92ba0077
F src/test1.c 7187b7e924bfc97780e6fd2a40dad94a32bddca0
F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b
F src/test3.c a8887dabbbee3059af338f20d290084a63ed1b0f
F src/test3.c 0df6f8dbb4cbaa7106397c70a271fa6a43659042
F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e
F src/test5.c 5a34feec76d9b3a86aab30fd4f6cc9c48cbab4c1
F src/test6.c 41cacf3b0dd180823919bf9e1fbab287c9266723
@ -976,7 +976,7 @@ F test/pcache.test c8acbedd3b6fd0f9a7ca887a83b11d24a007972b
F test/pcache2.test af7f3deb1a819f77a6d0d81534e97d1cf62cd442
F test/percentile.test 4243af26b8f3f4555abe166f723715a1f74c77ff
F test/permutations.test cd1fa041074ed08eeaa563e4d1bacb0c69337ec1
F test/pragma.test afbf028be1c35b68f57db8eb015c4a3c59d8f28e
F test/pragma.test 36daccdbfbdd958a5f65c034141ab2bfd959808e
F test/pragma2.test e5d5c176360c321344249354c0c16aec46214c9f
F test/pragma3.test 3f1984a04657331f838df5c519b443c2088df922
F test/printf.test b3ff34e73d59124140eaf89f7672e21bc2ca5fcc
@ -1110,7 +1110,7 @@ F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930
F test/tclsqlite.test e1306001a0ca92250b691ea6d3cecaca5b6342aa
F test/tempdb.test bd92eba8f20e16a9136e434e20b280794de3cdb6
F test/temptable.test d2c9b87a54147161bcd1822e30c1d1cd891e5b30
F test/temptable2.test c16f96e996bf6f587a4df4199c62cf0ac9a1c0ea
F test/temptable2.test 707c01c00b4a8fd050e0db5dcef448e998b9ddb5
F test/temptrigger.test 8ec228b0db5d7ebc4ee9b458fc28cb9e7873f5e1
F test/tester.tcl 7b740ee852c55e1e72b6ebe5044acee7aa4e5553
F test/thread001.test 9f22fd3525a307ff42a326b6bc7b0465be1745a5
@ -1483,7 +1483,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P afe9bd9b4b5dc98dccf1bced80567515ab5c0117
R 35c99f2c80a6bf5e586b897ba6d7e956
P 84de8813c3b4007e3c7c3a286ce13020f2065c7b
R 54ab030014fa87b230c7ab4f5fdc139b
U dan
Z 67c50ed57a780aa24194c52733684bdf
Z dbab9fc4f54135fb156cdc6ccf0d8253

View File

@ -1 +1 @@
84de8813c3b4007e3c7c3a286ce13020f2065c7b
84c557010c211595d2ec80b62c63af1c7f4714bd

View File

@ -1170,6 +1170,8 @@ static int jrnlBufferSize(Pager *pPager){
return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
}
#else
# define jrnlBufferSize(x) 0
#endif
/*
@ -5562,24 +5564,24 @@ static int pager_open_journal(Pager *pPager){
if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
sqlite3MemJournalOpen(pPager->jfd);
}else{
const int flags = /* VFS flags to open journal file */
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
(pPager->tempFile ?
(SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
(SQLITE_OPEN_MAIN_JOURNAL)
);
int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
int nSpill;
if( pPager->tempFile ){
flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
nSpill = sqlite3Config.nStmtSpill;
}else{
flags |= SQLITE_OPEN_MAIN_JOURNAL;
nSpill = jrnlBufferSize(pPager);
}
/* Verify that the database still has the same name as it did when
** it was originally opened. */
rc = databaseIsUnmoved(pPager);
if( rc==SQLITE_OK ){
#ifdef SQLITE_ENABLE_ATOMIC_WRITE
rc = sqlite3JournalOpen(
pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
rc = sqlite3JournalOpen (
pVfs, pPager->zJournal, pPager->jfd, flags, nSpill
);
#else
rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
#endif
}
}
assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
@ -6532,10 +6534,10 @@ void sqlite3PagerCacheStat(Pager *pPager, int eStat, int reset, int *pnVal){
}
/*
** Return true if this is an in-memory pager.
** Return true if this is an in-memory or temp-file backed pager.
*/
int sqlite3PagerIsMemdb(Pager *pPager){
return MEMDB;
return pPager->tempFile;
}
/*

View File

@ -547,7 +547,7 @@ static int btree_from_db(
/*
** Usage: btree_ismemdb ID
**
** Return true if the B-Tree is in-memory.
** Return true if the B-Tree is currently stored entirely in memory.
*/
static int btree_ismemdb(
void *NotUsed,
@ -557,6 +557,7 @@ static int btree_ismemdb(
){
Btree *pBt;
int res;
sqlite3_file *pFile;
if( argc!=2 ){
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
@ -566,7 +567,8 @@ static int btree_ismemdb(
pBt = sqlite3TestTextToPtr(argv[1]);
sqlite3_mutex_enter(pBt->db->mutex);
sqlite3BtreeEnter(pBt);
res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt));
pFile = sqlite3PagerFile(sqlite3BtreePager(pBt));
res = (pFile->pMethods==0);
sqlite3BtreeLeave(pBt);
sqlite3_mutex_leave(pBt->db->mutex);
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res));

View File

@ -1083,7 +1083,20 @@ do_test pragma-8.2.15 {
# "memory" or "disk" as appropriate.
#
proc check_temp_store {} {
db eval {CREATE TEMP TABLE IF NOT EXISTS a(b)}
db eval {
PRAGMA temp.cache_size = 1;
CREATE TEMP TABLE IF NOT EXISTS a(b);
DELETE FROM a;
INSERT INTO a VALUES(randomblob(1000));
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
INSERT INTO a SELECT * FROM a;
}
db eval {PRAGMA database_list} {
if {$name=="temp"} {
set bt [btree_from_db db 1]

View File

@ -113,8 +113,12 @@ do_execsql_test 4.1.3 {
SELECT count(*) FROM t2;
SELECT count(*) FROM t1;
PRAGMA temp.page_count;
} {500 10 292}
} {500 10}
do_test 4.1.4 {
set n [db one { PRAGMA temp.page_count }]
expr ($n >280 && $n < 300)
} 1
do_execsql_test 4.1.4 { PRAGMA temp.integrity_check } {ok}
@ -133,11 +137,14 @@ do_execsql_test 5.1.1 {
CREATE TEMP TABLE t1(a, b);
CREATE INDEX i1 ON t1(a, b);
INSERT INTO t1 VALUES(1, 2);
}
PRAGMA temp.page_count;
} {286}
do_test 5.1.2 {
set n [db one { PRAGMA temp.page_count }]
expr ($n > 280 && $n < 290)
} {1}
do_execsql_test 5.1.2 {
do_execsql_test 5.1.3 {
BEGIN;
UPDATE t1 SET a=2;
UPDATE t2 SET a=randomblob(100);
@ -145,13 +152,13 @@ do_execsql_test 5.1.2 {
ROLLBACK;
} {1}
do_execsql_test 5.1.3 {
do_execsql_test 5.1.4 {
UPDATE t2 SET a=randomblob(100);
SELECT * FROM t1;
} {1 2}
do_execsql_test 5.1.4 { PRAGMA temp.integrity_check } {ok}
do_execsql_test 5.1.5 { PRAGMA temp.integrity_check } {ok}
#-------------------------------------------------------------------------
# Test this:
@ -192,7 +199,7 @@ do_execsql_test 6.2 {
} {two 500 two}
#-------------------------------------------------------------------------
#
reset_db
sqlite3 db ""
do_execsql_test 7.1 {
@ -211,5 +218,56 @@ do_execsql_test 7.1 {
PRAGMA integrity_check;
} {ok}
#-------------------------------------------------------------------------
# Try changing the page size using a backup operation when pages are
# stored in main-memory only.
#
reset_db
do_execsql_test 8.1 {
CREATE TABLE t2(a, b);
CREATE INDEX i2 ON t2(a, b);
WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<20 )
INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM x;
PRAGMA page_count;
} {13}
do_test 8.2 {
sqlite3 tmp ""
execsql {
PRAGMA page_size = 8192;
CREATE TABLE t1(a, b);
CREATE INDEX i1 ON t1(a, b);
WITH x(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM x WHERE i<100 )
INSERT INTO t1 SELECT randomblob(100), randomblob(100) FROM x;
PRAGMA page_count;
} tmp
} {10}
do_test 8.3 {
sqlite3_backup B tmp main db main
B step 5
B finish
} {SQLITE_READONLY}
do_test 8.4 {
execsql {
SELECT count(*) FROM t1;
PRAGMA integrity_check;
PRAGMA page_size;
} tmp
} {100 ok 8192}
do_test 8.5 {
tmp eval { UPDATE t1 SET a=randomblob(100) }
} {}
do_test 8.6 {
sqlite3_backup B tmp main db main
B step 1000
B finish
} {SQLITE_READONLY}
tmp close
finish_test