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

Remove the mutex counter and the logic that attempts to verify that btree

mutexes are held continuously.  We are not making that assumption at this
time.

FossilOrigin-Name: 242ce7cff416a87d57d4eb624cb79fa4e2215559
This commit is contained in:
drh
2011-04-05 17:31:56 +00:00
parent ce8e5ffe1c
commit e54e051800
8 changed files with 25 additions and 139 deletions

View File

@@ -1,5 +1,5 @@
C When\scommitting\sa\sWAL\stransaction,\sdo\snot\swrite\sany\spages\sto\sthe\sWAL\sfile\swith\spage\snumbers\sgreater\sthan\sthe\ssize\sof\sthe\sdatabase\simage\sin\spages. C Remove\sthe\smutex\scounter\sand\sthe\slogic\sthat\sattempts\sto\sverify\sthat\sbtree\nmutexes\sare\sheld\scontinuously.\s\sWe\sare\snot\smaking\sthat\sassumption\sat\sthis\ntime.
D 2011-04-05T16:09:08.127 D 2011-04-05T17:31:56.106
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -120,10 +120,10 @@ F src/attach.c 7cae2cf0c14762ce14c074a860ec52890a973a56
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c b7529a6691f0fd534ae8ff622203c46a7f1b626b F src/backup.c b7529a6691f0fd534ae8ff622203c46a7f1b626b
F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef
F src/btmutex.c b81062220a4f91b0bd785d13d57205d68449be88 F src/btmutex.c 1f951523accdfa1d204b06150e016b5b69529b8a
F src/btree.c 107723ed4f9bdb55213ba6164c30c49af75f4bf9 F src/btree.c 107723ed4f9bdb55213ba6164c30c49af75f4bf9
F src/btree.h c0e0ff5c85effe9fc757e3085bbdded6d1cca000 F src/btree.h 221e186cd64127088890a878aaab154344380fe8
F src/btreeInt.h 6714ce2f5e879eb9a904a6a4575dc4faa4f29991 F src/btreeInt.h b5e339df994d12bcd9067d04f9125c8792de51ac
F src/build.c d809f57250b10e83586bc23921de02055890b239 F src/build.c d809f57250b10e83586bc23921de02055890b239
F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
@@ -235,11 +235,11 @@ F src/update.c 81911be16ece3c3e7716aa18565b4814ec41f8b9
F src/utf.c d83650c3ea08f7407bd9d0839d9885241c209c60 F src/utf.c d83650c3ea08f7407bd9d0839d9885241c209c60
F src/util.c cd997077bad039efc0597eb027c929658f93c018 F src/util.c cd997077bad039efc0597eb027c929658f93c018
F src/vacuum.c 05513dca036a1e7848fe18d5ed1265ac0b32365e F src/vacuum.c 05513dca036a1e7848fe18d5ed1265ac0b32365e
F src/vdbe.c 0140a57f9cbd50351219bfc4e44ef3de64bd65b8 F src/vdbe.c b239d70f6862f1d0d3896c96efe7d6fabae1c56c
F src/vdbe.h 8a675fefdf7119441fe817c800a9a52440c2e797 F src/vdbe.h 8a675fefdf7119441fe817c800a9a52440c2e797
F src/vdbeInt.h 7e2f028ecc1a9faa6f253e7aa8d89cae03662bae F src/vdbeInt.h 53dfcaf5b83297c24f537c4a54c1f35fd655b0a2
F src/vdbeapi.c a09ad9164cafc505250d5dd6b69660c960f1308c F src/vdbeapi.c a09ad9164cafc505250d5dd6b69660c960f1308c
F src/vdbeaux.c e1ea6edc07b4f33a339cc45a2fbe0a36067d2d8b F src/vdbeaux.c 64304e50c6d4ccca586410184927baa9faca6ecc
F src/vdbeblob.c c3ccb7c8732858c680f442932e66ad06bb036562 F src/vdbeblob.c c3ccb7c8732858c680f442932e66ad06bb036562
F src/vdbemem.c 0498796b6ffbe45e32960d6a1f5adfb6e419883b F src/vdbemem.c 0498796b6ffbe45e32960d6a1f5adfb6e419883b
F src/vdbetrace.c 3ba13bc32bdf16d2bdea523245fd16736bed67b5 F src/vdbetrace.c 3ba13bc32bdf16d2bdea523245fd16736bed67b5
@@ -926,7 +926,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P d25c17ef6e2b916923489dccaaa018a2d6525401 P 311d0b613d9cfa2dbcbb9ef2450041b1fd48770a
R c888a09e2325a742237e83457c23e497 R f2efb954b9e1d86872be6fb2ad3e5711
U dan U drh
Z 881050430264f599344995b52c518cce Z c70542c8d51f5c49bbcf63ab42aa4a3a

View File

@@ -1 +1 @@
311d0b613d9cfa2dbcbb9ef2450041b1fd48770a 242ce7cff416a87d57d4eb624cb79fa4e2215559

View File

@@ -45,28 +45,10 @@ static void unlockBtreeMutex(Btree *p){
assert( sqlite3_mutex_held(p->db->mutex) ); assert( sqlite3_mutex_held(p->db->mutex) );
assert( p->db==pBt->db ); assert( p->db==pBt->db );
pBt->iMutexCounter++;
sqlite3_mutex_leave(pBt->mutex); sqlite3_mutex_leave(pBt->mutex);
p->locked = 0; p->locked = 0;
} }
#ifdef SQLITE_DEBUG
/*
** Return the number of times that the mutex has been exited for
** the given btree.
**
** This is a small circular counter that wraps around to zero on
** overflow. It is used only for sanity checking - to verify that
** mutexes are held continously by asserting that the value of
** this counter at the beginning of a region is the same as at
** the end.
*/
u32 sqlite3BtreeMutexCounter(Btree *p){
assert( p->locked==1 || p->sharable==0 );
return p->pBt->iMutexCounter;
}
#endif
/* /*
** Enter a mutex on the given BTree object. ** Enter a mutex on the given BTree object.
** **
@@ -111,24 +93,6 @@ void sqlite3BtreeEnter(Btree *p){
p->wantToLock++; p->wantToLock++;
if( p->locked ) return; if( p->locked ) return;
/* Increment the mutex counter on all locked btrees in the same
** database connection. This simulates the unlocking that would
** occur on a worst-case mutex dead-lock avoidance scenario.
*/
#ifdef SQLITE_DEBUG
{
int ii;
sqlite3 *db = p->db;
Btree *pOther;
for(ii=0; ii<db->nDb; ii++){
if( ii==1 ) continue;
pOther = db->aDb[ii].pBt;
if( pOther==0 || pOther->sharable==0 || pOther->locked==0 ) continue;
pOther->pBt->iMutexCounter++;
}
}
#endif
/* In most cases, we should be able to acquire the lock we /* In most cases, we should be able to acquire the lock we
** want without having to go throught the ascending lock ** want without having to go throught the ascending lock
** procedure that follows. Just be sure not to block. ** procedure that follows. Just be sure not to block.

View File

@@ -221,19 +221,17 @@ void sqlite3BtreeCursorList(Btree*);
int sqlite3BtreeHoldsMutex(Btree*); int sqlite3BtreeHoldsMutex(Btree*);
int sqlite3BtreeHoldsAllMutexes(sqlite3*); int sqlite3BtreeHoldsAllMutexes(sqlite3*);
int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*); int sqlite3SchemaMutexHeld(sqlite3*,int,Schema*);
u32 sqlite3BtreeMutexCounter(Btree*);
#endif #endif
#else #else
# define sqlite3BtreeLeave(X) # define sqlite3BtreeLeave(X)
# define sqlite3BtreeMutexCounter(X) 0
# define sqlite3BtreeEnterCursor(X) # define sqlite3BtreeEnterCursor(X)
# define sqlite3BtreeLeaveCursor(X) # define sqlite3BtreeLeaveCursor(X)
# define sqlite3BtreeLeaveAll(X) # define sqlite3BtreeLeaveAll(X)
# define sqlite3BtreeHoldsMutex(X) 1 # define sqlite3BtreeHoldsMutex(X) 1
# define sqlite3BtreeHoldsAllMutexes(X) 1 # define sqlite3BtreeHoldsAllMutexes(X) 1
# define sqlite3BtreeSchemaMutexHeld(X,Y) 1 # define sqlite3SchemaMutexHeld(X,Y,Z) 1
#endif #endif

View File

@@ -435,7 +435,6 @@ struct BtShared {
Btree *pWriter; /* Btree with currently open write transaction */ Btree *pWriter; /* Btree with currently open write transaction */
u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */ u8 isExclusive; /* True if pWriter has an EXCLUSIVE lock on the db */
u8 isPending; /* If waiting for read-locks to clear */ u8 isPending; /* If waiting for read-locks to clear */
u16 iMutexCounter; /* The number of mutex_leave(mutex) calls */
#endif #endif
u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */ u8 *pTmpSpace; /* BtShared.pageSize bytes of space for tmp use */
}; };

View File

@@ -1394,7 +1394,6 @@ case OP_Function: {
ctx.pColl = pOp[-1].p4.pColl; ctx.pColl = pOp[-1].p4.pColl;
} }
(*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */
sqlite3VdbeMutexResync(p);
if( db->mallocFailed ){ if( db->mallocFailed ){
/* Even though a malloc() has failed, the implementation of the /* Even though a malloc() has failed, the implementation of the
** user function may have called an sqlite3_result_XXX() function ** user function may have called an sqlite3_result_XXX() function
@@ -2660,7 +2659,6 @@ case OP_Savepoint: {
if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){
sqlite3ExpirePreparedStatements(db); sqlite3ExpirePreparedStatements(db);
sqlite3ResetInternalSchema(db, -1); sqlite3ResetInternalSchema(db, -1);
sqlite3VdbeMutexResync(p);
db->flags = (db->flags | SQLITE_InternChanges); db->flags = (db->flags | SQLITE_InternChanges);
} }
} }
@@ -5198,23 +5196,11 @@ case OP_AggStep: {
ctx.pColl = pOp[-1].p4.pColl; ctx.pColl = pOp[-1].p4.pColl;
} }
(ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */
sqlite3VdbeMutexResync(p);
if( ctx.isError ){ if( ctx.isError ){
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s));
rc = ctx.isError; rc = ctx.isError;
} }
/* The app-defined function has done something that as caused this
** statement to expire. (Perhaps the function called sqlite3_exec()
** with a CREATE TABLE statement.)
*/
#if 0
if( p->expired ){
rc = SQLITE_ABORT;
break;
}
#endif
sqlite3VdbeMemRelease(&ctx.s); sqlite3VdbeMemRelease(&ctx.s);
break; break;
@@ -5238,11 +5224,8 @@ case OP_AggFinal: {
pMem = &aMem[pOp->p1]; pMem = &aMem[pOp->p1];
assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
sqlite3VdbeMutexResync(p);
if( rc ){ if( rc ){
sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem)); sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem));
}else if( p->expired ){
rc = SQLITE_ABORT;
} }
sqlite3VdbeChangeEncoding(pMem, encoding); sqlite3VdbeChangeEncoding(pMem, encoding);
UPDATE_MAX_BLOBSIZE(pMem); UPDATE_MAX_BLOBSIZE(pMem);

View File

@@ -303,7 +303,6 @@ struct Vdbe {
u8 isPrepareV2; /* True if prepared with prepare_v2() */ u8 isPrepareV2; /* True if prepared with prepare_v2() */
int nChange; /* Number of db changes made since last reset */ int nChange; /* Number of db changes made since last reset */
yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */
u32 iMutexCounter; /* Mutex counter upon sqlite3VdbeEnter() */
int iStatement; /* Statement number (or 0 if has not opened stmt) */ int iStatement; /* Statement number (or 0 if has not opened stmt) */
int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ int aCounter[3]; /* Counters used by sqlite3_stmt_status() */
#ifndef SQLITE_OMIT_TRACE #ifndef SQLITE_OMIT_TRACE
@@ -387,9 +386,14 @@ int sqlite3VdbeCloseStatement(Vdbe *, int);
void sqlite3VdbeFrameDelete(VdbeFrame*); void sqlite3VdbeFrameDelete(VdbeFrame*);
int sqlite3VdbeFrameRestore(VdbeFrame *); int sqlite3VdbeFrameRestore(VdbeFrame *);
void sqlite3VdbeMemStoreType(Mem *pMem); void sqlite3VdbeMemStoreType(Mem *pMem);
void sqlite3VdbeEnter(Vdbe*);
void sqlite3VdbeLeave(Vdbe*); #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
void sqlite3VdbeMutexResync(Vdbe*); void sqlite3VdbeEnter(Vdbe*);
void sqlite3VdbeLeave(Vdbe*);
#else
# define sqlite3VdbeEnter(X)
# define sqlite3VdbeLeave(X)
#endif
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*); void sqlite3VdbeMemPrepareToChange(Vdbe*,Mem*);

View File

@@ -960,31 +960,7 @@ void sqlite3VdbeUsesBtree(Vdbe *p, int i){
p->btreeMask |= ((yDbMask)1)<<i; p->btreeMask |= ((yDbMask)1)<<i;
} }
/* #if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
** Compute the sum of all mutex counters for all btrees in the
** given prepared statement.
*/
#ifndef SQLITE_OMIT_SHARED_CACHE
static u32 mutexCounterSum(Vdbe *p){
u32 cntSum = 0;
#ifdef SQLITE_DEBUG
int i;
yDbMask mask;
sqlite3 *db = p->db;
Db *aDb = db->aDb;
int nDb = db->nDb;
for(i=0, mask=1; i<nDb; i++, mask += mask){
if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
cntSum += sqlite3BtreeMutexCounter(aDb[i].pBt);
}
}
#else
UNUSED_PARAMETER(p);
#endif
return cntSum;
}
#endif
/* /*
** If SQLite is compiled to support shared-cache mode and to be threadsafe, ** If SQLite is compiled to support shared-cache mode and to be threadsafe,
** this routine obtains the mutex associated with each BtShared structure ** this routine obtains the mutex associated with each BtShared structure
@@ -1007,7 +983,6 @@ static u32 mutexCounterSum(Vdbe *p){
** be a problem. ** be a problem.
*/ */
void sqlite3VdbeEnter(Vdbe *p){ void sqlite3VdbeEnter(Vdbe *p){
#ifndef SQLITE_OMIT_SHARED_CACHE
int i; int i;
yDbMask mask; yDbMask mask;
sqlite3 *db = p->db; sqlite3 *db = p->db;
@@ -1018,63 +993,27 @@ void sqlite3VdbeEnter(Vdbe *p){
sqlite3BtreeEnter(aDb[i].pBt); sqlite3BtreeEnter(aDb[i].pBt);
} }
} }
p->iMutexCounter = mutexCounterSum(p);
#else
UNUSED_PARAMETER(p);
#endif
} }
#endif
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE>0
/* /*
** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter(). ** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
*/ */
void sqlite3VdbeLeave(Vdbe *p){ void sqlite3VdbeLeave(Vdbe *p){
#ifndef SQLITE_OMIT_SHARED_CACHE
int i; int i;
yDbMask mask; yDbMask mask;
sqlite3 *db = p->db; sqlite3 *db = p->db;
Db *aDb = db->aDb; Db *aDb = db->aDb;
int nDb = db->nDb; int nDb = db->nDb;
/* Assert that the all mutexes have been held continously since
** the most recent sqlite3VdbeEnter() or sqlite3VdbeMutexResync().
*/
assert( mutexCounterSum(p) == p->iMutexCounter );
for(i=0, mask=1; i<nDb; i++, mask += mask){ for(i=0, mask=1; i<nDb; i++, mask += mask){
if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){ if( i!=1 && (mask & p->btreeMask)!=0 && ALWAYS(aDb[i].pBt!=0) ){
sqlite3BtreeLeave(aDb[i].pBt); sqlite3BtreeLeave(aDb[i].pBt);
} }
} }
#else
UNUSED_PARAMETER(p);
#endif
} }
/*
** Recompute the sum of the mutex counters on all btrees used by the
** prepared statement p.
**
** Call this routine while holding a sqlite3VdbeEnter() after doing something
** that might cause one or more of the individual mutexes held by the
** prepared statement to be released. Calling sqlite3BtreeEnter() on
** any BtShared mutex which is not used by the prepared statement is one
** way to cause one or more of the mutexes in the prepared statement
** to be temporarily released. The anti-deadlocking logic in
** sqlite3BtreeEnter() can cause mutexes to be released temporarily then
** reacquired.
**
** Calling this routine is an acknowledgement that some of the individual
** mutexes in the prepared statement might have been released and reacquired.
** So checks to verify that mutex-protected content did not change
** unexpectedly should accompany any call to this routine.
*/
void sqlite3VdbeMutexResync(Vdbe *p){
#if !defined(SQLITE_OMIT_SHARED_CACHE) && defined(SQLITE_DEBUG)
p->iMutexCounter = mutexCounterSum(p);
#else
UNUSED_PARAMETER(p);
#endif #endif
}
#if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) #if defined(VDBE_PROFILE) || defined(SQLITE_DEBUG)
/* /*
@@ -2283,7 +2222,6 @@ int sqlite3VdbeHalt(Vdbe *p){
} }
/* Release the locks */ /* Release the locks */
sqlite3VdbeMutexResync(p);
sqlite3VdbeLeave(p); sqlite3VdbeLeave(p);
} }