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

Only pass -1 as the size parameter to xShmGet when the caller does not care what size mapping is returned. Only call xShmSize when the underlying allocation (not the mapping) should be resized.

FossilOrigin-Name: 637f51ddf9e4a57e1f171b6d2c6c93152074267e
This commit is contained in:
dan
2010-05-06 18:04:50 +00:00
parent b7d53f54ae
commit 576bc3294d
5 changed files with 72 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sa\sbug\swhereby\san\sold\ssnapshot\scould\sbe\scheckpointed\s(and\ssubsequent\stransactions\sdiscarded)\sif\sthe\slast\sconnection\sto\sdisconnect\sfrom\sa\sWAL\sdatabase\shappended\sto\sbe\sholding\san\sout-of-date\swal-index\sheader.
D 2010-05-06T17:28:09
C Only\spass\s-1\sas\sthe\ssize\sparameter\sto\sxShmGet\swhen\sthe\scaller\sdoes\snot\scare\swhat\ssize\smapping\sis\sreturned.\sOnly\scall\sxShmSize\swhen\sthe\sunderlying\sallocation\s(not\sthe\smapping)\sshould\sbe\sresized.
D 2010-05-06T18:04:51
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -207,7 +207,7 @@ F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
F src/test_server.c bbba05c144b5fc4b52ff650a4328027b3fa5fcc6
F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa
F src/test_thread.c aa9919c885a1fe53eafc73492f0898ee6c0a0726
F src/test_vfs.c a6a8b594b4b9ce884fcf7d822887b8e16e61f797
F src/test_vfs.c 72b8ad1a6bc6c27d9e5b4362d6320d3834c87db6
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
F src/tokenize.c 25ceb0f0a746ea1d0f9553787f3f0a56853cfaeb
F src/trigger.c 8927588cb9e6d47f933b53bfe74200fbb504100d
@@ -224,7 +224,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
F src/wal.c d7250e0da0d389d9fc3839363570f3f74da0b60d
F src/wal.c 1730243c6491a5b4e325c8977b15fcb9aa4486c6
F src/wal.h b4c42014b5fa3b4e6244ac8c65de7ff67adeb27c
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
@@ -762,7 +762,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
F test/wal.test f0b78497bbe2e7f3c35a1c28e9772fe0dead1fc8
F test/wal2.test 4a8e20416020f83b792464edee18107321dea99a
F test/wal2.test 1d5b761f55070e242a983bf08634c79fb46724f2
F test/walbak.test a0e45187c7d8928df035dfea29b99b016b21ca3c
F test/walcrash.test f6d5fb2bb108876f04848720a488065d9deef69f
F test/walfault.test ae37204f4375e0e5eba75094d0d0db7148de70a8
@@ -813,7 +813,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 56a17dae91600a3863903f8d654ed52a0f720caf
R aee4f4f487984caf56f9844933d88af1
P d0c0034b0baa83046c1d6b94c886f7039e4e06f5
R 4a69eca7dd8c02399282e41c5a135767
U dan
Z 2489bba830e3043eba5db422e0f13170
Z 6b8130cf037212b2a014832ceb2e7bfd

View File

@@ -1 +1 @@
d0c0034b0baa83046c1d6b94c886f7039e4e06f5
637f51ddf9e4a57e1f171b6d2c6c93152074267e

View File

@@ -648,7 +648,7 @@ static void testvfs_obj_del(ClientData cd){
#define TESTVFS_MAX_ARGS 12
/*
** Usage: testvfs VFSNAME SCRIPT
** Usage: testvfs ?-noshm? VFSNAME SCRIPT
**
** This command creates two things when it is invoked: an SQLite VFS, and
** a Tcl command. Both are named VFSNAME. The VFS is installed. It is not
@@ -732,13 +732,15 @@ static int testvfs_cmd(
Tcl_Obj **apScript; /* Array of pScript elements */
int nByte; /* Bytes of space to allocate at p */
int i; /* Counter variable */
int isNoshm = 0; /* True if -noshm is passed */
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 1, objv, "VFSNAME SCRIPT");
return TCL_ERROR;
if( objc<3 ) goto bad_args;
if( strcmp(Tcl_GetString(objv[1]), "-noshm")==0 ){
isNoshm = 1;
}
zVfs = Tcl_GetString(objv[1]);
pScript = objv[2];
if( objc!=3+isNoshm ) goto bad_args;
zVfs = Tcl_GetString(objv[isNoshm+1]);
pScript = objv[isNoshm+2];
if( TCL_OK!=Tcl_ListObjGetElements(interp, pScript, &nScript, &apScript) ){
return TCL_ERROR;
@@ -768,11 +770,23 @@ static int testvfs_cmd(
pVfs->mxPathname = p->pParent->mxPathname;
pVfs->szOsFile += p->pParent->szOsFile;
p->pVfs = pVfs;
if( isNoshm ){
pVfs->xShmOpen = 0;
pVfs->xShmGet = 0;
pVfs->xShmSize = 0;
pVfs->xShmRelease = 0;
pVfs->xShmClose = 0;
pVfs->xShmLock = 0;
}
Tcl_CreateObjCommand(interp, zVfs, testvfs_obj_cmd, p, testvfs_obj_del);
sqlite3_vfs_register(pVfs, 0);
return TCL_OK;
bad_args:
Tcl_WrongNumArgs(interp, 1, objv, "?-noshm? VFSNAME SCRIPT");
return TCL_ERROR;
}
int Sqlitetestvfs_Init(Tcl_Interp *interp){

View File

@@ -577,8 +577,13 @@ static int walIndexRecover(Wal *pWal){
}
finished:
if( rc==SQLITE_OK && hdr.iLastPg==0 ){
rc = walIndexRemap(pWal, WALINDEX_MMAP_INCREMENT);
}
if( rc==SQLITE_OK ){
walIndexWriteHdr(pWal, &hdr);
memcpy(&pWal->hdr, &hdr, sizeof(hdr));
}
return rc;
}
@@ -698,7 +703,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){
u8 *aTmp; /* Temp space used by merge-sort */
int rc; /* Return code of walIndexMap() */
rc = walIndexMap(pWal, -1);
rc = walIndexMap(pWal, walMappingSize(pWal->hdr.iLastPg));
if( rc!=SQLITE_OK ){
return rc;
}
@@ -878,10 +883,9 @@ int walIndexTryHdr(Wal *pWal, int *pisValid, int *pChanged){
u32 aCksum[2] = {1, 1};
u32 aHdr[WALINDEX_HDR_NFIELD+2];
assert( *pisValid==0 );
if( pWal->szWIndex==0 ){
int rc;
rc = walIndexRemap(pWal, WALINDEX_MMAP_INCREMENT);
if( rc ) return rc;
return SQLITE_OK;
}
/* Read the header. The caller may or may not have locked the wal-index
@@ -939,7 +943,7 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){
/* This call to walIndexTryHdr() may not return an error code, as the
** wal-index is already mapped. It may find that the header is invalid,
** but there is no chance of hitting an actual error. */
assert( pWal->szWIndex );
assert( pWal->pWiData );
rc = walIndexTryHdr(pWal, &isValid, pChanged);
assert( rc==SQLITE_OK );
if( isValid==0 ){
@@ -972,13 +976,6 @@ int sqlite3WalOpenSnapshot(Wal *pWal, int *pChanged){
if( rc!=SQLITE_OK ){
/* An error occured while attempting log recovery. */
sqlite3WalCloseSnapshot(pWal);
}else{
/* Check if the mapping needs to grow. */
if( pWal->hdr.iLastPg
&& walIndexEntry(pWal->hdr.iLastPg)*sizeof(u32)>=pWal->szWIndex
){
walIndexRemap(pWal, -1);
}
}
}
@@ -1012,7 +1009,7 @@ int sqlite3WalRead(
int iFrame = (pWal->hdr.iLastPg & 0xFFFFFF00);
assert( pWal->lockState==SQLITE_SHM_READ||pWal->lockState==SQLITE_SHM_WRITE );
rc = walIndexMap(pWal, -1);
rc = walIndexMap(pWal, walMappingSize(pWal->hdr.iLastPg));
if( rc!=SQLITE_OK ){
return rc;
}
@@ -1100,7 +1097,7 @@ int sqlite3WalWriteLock(Wal *pWal, int op){
** the write locks and return SQLITE_BUSY.
*/
if( rc==SQLITE_OK ){
rc = walIndexMap(pWal, -1);
rc = walIndexMap(pWal, sizeof(WalIndexHdr));
if( rc==SQLITE_OK
&& memcmp(&pWal->hdr, pWal->pWiData, sizeof(WalIndexHdr))
){

View File

@@ -306,4 +306,34 @@ db close
tvfs delete
file delete -force test.db test.db-wal test.db-journal
#-------------------------------------------------------------------------
# Test that a database connection using a VFS that does not support the
# xShmXXX interfaces cannot open a WAL database.
#
do_test wal2-4.1 {
sqlite3 db test.db
execsql {
PRAGMA journal_mode = WAL;
CREATE TABLE data(x);
INSERT INTO data VALUES('need xShmOpen to see this');
PRAGMA wal_checkpoint;
}
} {wal}
do_test wal2-4.2 {
db close
proc ok {args} {return SQLITE_OK}
testvfs -noshm tvfs ok
sqlite3 db test.db -vfs tvfs
catchsql { SELECT * FROM data }
} {1 {unable to open database file}}
do_test wal2-4.3 {
db close
proc ok {args} {return SQLITE_OK}
testvfs tvfs ok
sqlite3 db test.db -vfs tvfs
catchsql { SELECT * FROM data }
} {0 {{need xShmOpen to see this}}}
db close
tvfs delete
finish_test