If an error occurs in PagerSetPagesize(), set the output variable to the unmodified page-size before returning.

FossilOrigin-Name: 02def8f92588b8a45dff3976d1e7f9e3f0359b3b
This commit is contained in:
dan 2010-08-12 16:36:34 +00:00
parent 5653e4da36
commit 1879b088bd
5 changed files with 78 additions and 25 deletions

View File

@ -1,5 +1,5 @@
C Add\scoverage\stests\sfor\spager.c.
D 2010-08-12T11:25:48
C If\san\serror\soccurs\sin\sPagerSetPagesize(),\sset\sthe\soutput\svariable\sto\sthe\sunmodified\spage-size\sbefore\sreturning.
D 2010-08-12T16:36:35
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in ec08dc838fd8110fe24c92e5130bcd91cbb1ff2e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -156,7 +156,7 @@ F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f
F src/os_os2.c 72d0b2e562952a2464308c4ce5f7913ac10bef3e
F src/os_unix.c 11194cbcf6a57456e58022dc537ab8c3497d9bb9
F src/os_win.c 51cb62f76262d961ea4249489383d714501315a7
F src/pager.c ff51a76c802c51dc5b36645a2d9202d2a9462897
F src/pager.c 4e144b452545838fdb226755a16d109e0198f513
F src/pager.h 985a83d35b0cfa8e1c23ef91ed5cdb9bde73695a
F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58
F src/pcache.c 1e9aa2dbc0845b52e1b51cc39753b6d1e041cb07
@ -539,10 +539,10 @@ F test/notify3.test d60923e186e0900f4812a845fcdfd8eea096e33a
F test/notnull.test cc7c78340328e6112a13c3e311a9ab3127114347
F test/null.test a8b09b8ed87852742343b33441a9240022108993
F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec
F test/pager1.test 8b6e57d8cdf4c9f5c31ddcd048e81b026b225f0c
F test/pager1.test 6922029d71a8090169c71a67a141b6b94ad17d50
F test/pager2.test 0fbb6b6dc40ce1fecfe758c555a748ad2e9beaa3
F test/pager3.test 3856d9c80839be0668efee1b74811b1b7f7fc95f
F test/pagerfault.test c08abb54b591ba704c913af9278428fa3cce42d5
F test/pagerfault.test f025fbe0cbab8f3aec6cc5676af60d7b488f868c
F test/pagerfault2.test 1f79ea40d1133b2683a2f811b00f2399f7ec2401
F test/pageropt.test 8146bf448cf09e87bb1867c2217b921fb5857806
F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb
@ -843,7 +843,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 45362437d491fbe0f033a67b398f8ba68cbf1b3b
R 38d53c0088d37a8bc9ce3834465ac451
P 228c5b16af80c22e97d9d4deb351e0d3f4523f89
R 639f1bec1c909cc7434c6e41850105f7
U dan
Z ebb8f906eccfa5df91e15cf73afafb56
Z 132d1fc4e540d643bf195378105a77c8

View File

@ -1 +1 @@
228c5b16af80c22e97d9d4deb351e0d3f4523f89
02def8f92588b8a45dff3976d1e7f9e3f0359b3b

View File

@ -3354,6 +3354,8 @@ void sqlite3PagerSetBusyhandler(
** then *pPageSize is set to the old, retained page size before returning.
*/
int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){
int rc = SQLITE_OK;
/* It is not possible to do a full assert_pager_state() here, as this
** function may be called from within PagerOpen(), before the state
** of the Pager object is internally consistent.
@ -3372,14 +3374,16 @@ int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){
){
char *pNew; /* New temp space */
i64 nByte = 0;
if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
int rc = sqlite3OsFileSize(pPager->fd, &nByte);
if( rc!=SQLITE_OK ) return rc;
rc = sqlite3OsFileSize(pPager->fd, &nByte);
}
pNew = (char *)sqlite3PageMalloc(pageSize);
if( !pNew ){
return SQLITE_NOMEM;
}else{
if( rc==SQLITE_OK ){
pNew = (char *)sqlite3PageMalloc(pageSize);
if( !pNew ) rc = SQLITE_NOMEM;
}
if( rc==SQLITE_OK ){
pager_reset(pPager);
pPager->dbSize = nByte/pageSize;
pPager->pageSize = pageSize;
@ -3390,11 +3394,13 @@ int sqlite3PagerSetPagesize(Pager *pPager, u32 *pPageSize, int nReserve){
}
*pPageSize = pPager->pageSize;
if( nReserve<0 ) nReserve = pPager->nReserve;
assert( nReserve>=0 && nReserve<1000 );
pPager->nReserve = (i16)nReserve;
pagerReportSize(pPager);
return SQLITE_OK;
if( rc==SQLITE_OK ){
if( nReserve<0 ) nReserve = pPager->nReserve;
assert( nReserve>=0 && nReserve<1000 );
pPager->nReserve = (i16)nReserve;
pagerReportSize(pPager);
}
return rc;
}
/*

View File

@ -2328,5 +2328,24 @@ do_multiclient_test tn {
do_test pager1-28.$tn.20 { sql2 { COMMIT } } {}
}
do_test pager1-29.1 {
faultsim_delete_and_reopen
execsql {
PRAGMA page_size = 1024;
PRAGMA auto_vacuum = full;
PRAGMA locking_mode=exclusive;
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
}
file size test.db
} [expr 1024*3]
do_test pager1-29.2 {
execsql {
PRAGMA page_size = 4096;
VACUUM;
}
file size test.db
} [expr 4096*3]
finish_test

View File

@ -28,8 +28,6 @@ proc a_string {n} {
}
db func a_string a_string
if 1 {
#-------------------------------------------------------------------------
# Test fault-injection while rolling back a hot-journal file.
#
@ -1125,8 +1123,6 @@ do_faultsim_test pagerfault-24 -prep {
if {$ic != "ok"} { error "Integrity check: $ic" }
}
}
proc lockrows {n} {
if {$n==0} { return "" }
db eval { SELECT * FROM t1 WHERE oid = $n } {
@ -1134,6 +1130,7 @@ proc lockrows {n} {
}
}
do_test pagerfault-25-pre1 {
faultsim_delete_and_reopen
db func a_string a_string
@ -1150,7 +1147,7 @@ do_test pagerfault-25-pre1 {
}
faultsim_save_and_close
} {}
do_faultsim_test pagerfault-25 -faults full -prep {
do_faultsim_test pagerfault-25 -prep {
faultsim_restore_and_reopen
db func a_string a_string
set ::channel [db incrblob -readonly t1 a 1]
@ -1164,9 +1161,40 @@ do_faultsim_test pagerfault-25 -faults full -prep {
lockrows 30
} -test {
catch { lockrows 30 }
catch { db eval COMMIT }
close $::channel
faultsim_test_result {0 {}}
}
do_faultsim_test pagerfault-26 -prep {
faultsim_delete_and_reopen
execsql {
PRAGMA page_size = 1024;
PRAGMA journal_mode = truncate;
PRAGMA auto_vacuum = full;
PRAGMA locking_mode=exclusive;
CREATE TABLE t1(a, b);
INSERT INTO t1 VALUES(1, 2);
PRAGMA page_size = 4096;
}
} -body {
execsql {
VACUUM;
}
} -test {
faultsim_test_result {0 {}}
set contents [db eval {SELECT * FROM t1}]
if {$contents != "1 2"} { error "Bad database contents ($contents)" }
set sz [file size test.db]
if {$testrc!=0 && $sz!=1024*3 && $sz!=4096*3} {
error "Expected file size to be 3072 or 12288 bytes - actual size $sz bytes"
}
if {$testrc==0 && $sz!=4096*3} {
error "Expected file size to be 12288 bytes - actual size $sz bytes"
}
}
finish_test