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

Bug fix in BTree shared cache locking code. (CVS 4246)

FossilOrigin-Name: 399d3e755253a7b4604a62b9f171e0f1154134e2
This commit is contained in:
drh
2007-08-20 13:14:28 +00:00
parent 482ea18fde
commit abddb0c8c4
4 changed files with 25 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
C Get\smain.c\sto\scompile\swhen\sHAVE_USLEEP\sis\s0.\s(CVS\s4245) C Bug\sfix\sin\sBTree\sshared\scache\slocking\scode.\s(CVS\s4246)
D 2007-08-20T11:12:41 D 2007-08-20T13:14:29
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -68,9 +68,9 @@ F src/alter.c f0aac0060ae8102e58f210b44d35b53438d53173
F src/analyze.c a14237d869c6bea0846493b59317e4097e81a0b6 F src/analyze.c a14237d869c6bea0846493b59317e4097e81a0b6
F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8 F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8
F src/auth.c 5ea90bc93dfea46e9fe4bf531e14c7cd98219ecb F src/auth.c 5ea90bc93dfea46e9fe4bf531e14c7cd98219ecb
F src/btree.c f00ed30c442b4934d042af84e065498c542d21aa F src/btree.c f8a04f35eb81360773899983f7c2008145e13935
F src/btree.h 91ee529d581c1473d8e6e15299acc3b8de1d0674 F src/btree.h 91ee529d581c1473d8e6e15299acc3b8de1d0674
F src/btreeInt.h 6329e955a7dadd8628d5866e2465721b5fd25ef2 F src/btreeInt.h 9b4ca8999e52f713420e5f297dd86887a7a9820f
F src/build.c add67be992307b4b11849a6611bfd3352aacde92 F src/build.c add67be992307b4b11849a6611bfd3352aacde92
F src/callback.c 143436453bb93e831c9574fea0b9b9eb90e40ff3 F src/callback.c 143436453bb93e831c9574fea0b9b9eb90e40ff3
F src/complete.c ea63834e798a0ab14159bdc6e6cabc3df21aa346 F src/complete.c ea63834e798a0ab14159bdc6e6cabc3df21aa346
@@ -529,7 +529,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 41f2175b1ed7eccf271b687ee5c3ea262a0cd096 P b27f022fb924709f1c5e4642d5d59cab942e826d
R 3e86c1deeec6de8a6818d829abf2506d R ee810a3824b25c07a2182b7d0dedc3f5
U drh U drh
Z e107c976a8aac7848166a53955d0d290 Z 6c13724b198dff1360ddd718c375cb8a

View File

@@ -1 +1 @@
b27f022fb924709f1c5e4642d5d59cab942e826d 399d3e755253a7b4604a62b9f171e0f1154134e2

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btree.c,v 1.401 2007/08/17 16:50:38 danielk1977 Exp $ ** $Id: btree.c,v 1.402 2007/08/20 13:14:29 drh Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -1207,7 +1207,7 @@ int sqlite3BtreeOpen(
#if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO) #if !defined(SQLITE_OMIT_SHARED_CACHE) && !defined(SQLITE_OMIT_DISKIO)
/* If the new Btree uses a sharable pBtShared, then link the new /* If the new Btree uses a sharable pBtShared, then link the new
** Btree into the list of all sharable Btrees for the same connection. ** Btree into the list of all sharable Btrees for the same connection.
** The list is kept in ascending order by pBtShared address. ** The list is kept in ascending order by pBt address.
*/ */
if( p->sharable ){ if( p->sharable ){
int i; int i;
@@ -1220,7 +1220,7 @@ int sqlite3BtreeOpen(
p->pPrev = 0; p->pPrev = 0;
pSib->pPrev = p; pSib->pPrev = p;
}else{ }else{
while( pSib->pNext && pSib->pNext->pBt>p->pBt ){ while( pSib->pNext && pSib->pNext->pBt<p->pBt ){
pSib = pSib->pNext; pSib = pSib->pNext;
} }
p->pNext = pSib->pNext; p->pNext = pSib->pNext;
@@ -1323,7 +1323,6 @@ int sqlite3BtreeClose(Btree *p){
** Clean out and delete the BtShared object. ** Clean out and delete the BtShared object.
*/ */
assert( !pBt->pCursor ); assert( !pBt->pCursor );
assert( pBt->nRef==0 );
sqlite3PagerClose(pBt->pPager); sqlite3PagerClose(pBt->pPager);
if( pBt->xFreeSchema && pBt->pSchema ){ if( pBt->xFreeSchema && pBt->pSchema ){
pBt->xFreeSchema(pBt->pSchema); pBt->xFreeSchema(pBt->pSchema);

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** May you share freely, never taking more than you give.
** **
************************************************************************* *************************************************************************
** $Id: btreeInt.h,v 1.6 2007/08/17 01:14:38 drh Exp $ ** $Id: btreeInt.h,v 1.7 2007/08/20 13:14:29 drh Exp $
** **
** This file implements a external (disk-based) database using BTrees. ** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to ** For a detailed discussion of BTrees, refer to
@@ -314,6 +314,9 @@ struct MemPage {
** points to the same BtShared object. The database cache and the ** points to the same BtShared object. The database cache and the
** schema associated with the database file are all contained within ** schema associated with the database file are all contained within
** the BtShared object. ** the BtShared object.
**
** All fields in this structure are accessed under the sqlite3.pMutex
** mutex.
*/ */
struct Btree { struct Btree {
sqlite3 *pSqlite; /* The database connection holding this btree */ sqlite3 *pSqlite; /* The database connection holding this btree */
@@ -346,6 +349,10 @@ struct Btree {
** private Btree object for the file and each of those Btrees points ** private Btree object for the file and each of those Btrees points
** to this one BtShared object. BtShared.nRef is the number of ** to this one BtShared object. BtShared.nRef is the number of
** connections currently sharing this database file. ** connections currently sharing this database file.
**
** Fields in this structure are accessed under the BtShared.mutex
** mutex, except for nRef and pNext which are accessed under the
** global SQLITE_MUTEX_STATIC_MASTER mutex.
*/ */
struct BtShared { struct BtShared {
Pager *pPager; /* The page cache */ Pager *pPager; /* The page cache */
@@ -370,14 +377,14 @@ struct BtShared {
int minLeaf; /* Minimum local payload in a LEAFDATA table */ int minLeaf; /* Minimum local payload in a LEAFDATA table */
BusyHandler *pBusyHandler; /* Callback for when there is lock contention */ BusyHandler *pBusyHandler; /* Callback for when there is lock contention */
u8 inTransaction; /* Transaction state */ u8 inTransaction; /* Transaction state */
int nRef; /* Number of references to this structure */
int nTransaction; /* Number of open transactions (read + write) */ int nTransaction; /* Number of open transactions (read + write) */
void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */ void *pSchema; /* Pointer to space allocated by sqlite3BtreeSchema() */
void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */ void (*xFreeSchema)(void*); /* Destructor for BtShared.pSchema */
#ifndef SQLITE_OMIT_SHARED_CACHE #ifndef SQLITE_OMIT_SHARED_CACHE
int nRef; /* Number of references to this structure */
BtShared *pNext; /* Next on a list of sharable BtShared structs */
sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */ sqlite3_mutex *mutex; /* Non-recursive mutex required to access this struct */
BtLock *pLock; /* List of locks held on this shared-btree struct */ BtLock *pLock; /* List of locks held on this shared-btree struct */
BtShared *pNext; /* Next in ThreadData.pBtree linked list */
#endif #endif
}; };
@@ -408,6 +415,10 @@ struct CellInfo {
** When a single database file can shared by two more database connections, ** When a single database file can shared by two more database connections,
** but cursors cannot be shared. Each cursor is associated with a ** but cursors cannot be shared. Each cursor is associated with a
** particular database connection identified BtCursor.pBtree.pSqlite. ** particular database connection identified BtCursor.pBtree.pSqlite.
**
** The fields in this structure are accessed under the sqlite3.pMutex
** mutex, specifically the BtCurser.pBtree->pSqlite->pMutex mutex.
** The pNext and pPrev fields also require the BtShared.mutex mutex.
*/ */
struct BtCursor { struct BtCursor {
Btree *pBtree; /* The Btree to which this cursor belongs */ Btree *pBtree; /* The Btree to which this cursor belongs */