mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Make the sqlite3BtreeMoveto function static, since it is only used from within btree.c. Remove unused function lockBtreeWithRetry from btree.c. (CVS 6850)
FossilOrigin-Name: 30d5ec62ab6a85ee60ee4128e20959842f8c7ad1
This commit is contained in:
112
src/btree.c
112
src/btree.c
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.652 2009/07/04 17:16:01 danielk1977 Exp $
|
||||
** $Id: btree.c,v 1.653 2009/07/06 18:56:13 danielk1977 Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** See the header comment on "btreeInt.h" for additional information.
|
||||
@@ -608,6 +608,37 @@ void sqlite3BtreeClearCursor(BtCursor *pCur){
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
** In this version of BtreeMoveto, pKey is a packed index record
|
||||
** such as is generated by the OP_MakeRecord opcode. Unpack the
|
||||
** record and then call BtreeMovetoUnpacked() to do the work.
|
||||
*/
|
||||
static int btreeMoveto(
|
||||
BtCursor *pCur, /* Cursor open on the btree to be searched */
|
||||
const void *pKey, /* Packed key if the btree is an index */
|
||||
i64 nKey, /* Integer key for tables. Size of pKey for indices */
|
||||
int bias, /* Bias search to the high end */
|
||||
int *pRes /* Write search results here */
|
||||
){
|
||||
int rc; /* Status code */
|
||||
UnpackedRecord *pIdxKey; /* Unpacked index key */
|
||||
char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
|
||||
|
||||
if( pKey ){
|
||||
assert( nKey==(i64)(int)nKey );
|
||||
pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey,
|
||||
aSpace, sizeof(aSpace));
|
||||
if( pIdxKey==0 ) return SQLITE_NOMEM;
|
||||
}else{
|
||||
pIdxKey = 0;
|
||||
}
|
||||
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
|
||||
if( pKey ){
|
||||
sqlite3VdbeDeleteUnpackedRecord(pIdxKey);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Restore the cursor to the position it was in (or as close to as possible)
|
||||
** when saveCursorPosition() was called. Note that this call deletes the
|
||||
@@ -623,7 +654,7 @@ int sqlite3BtreeRestoreCursorPosition(BtCursor *pCur){
|
||||
return pCur->skip;
|
||||
}
|
||||
pCur->eState = CURSOR_INVALID;
|
||||
rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skip);
|
||||
rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &pCur->skip);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3_free(pCur->pKey);
|
||||
pCur->pKey = 0;
|
||||
@@ -2207,29 +2238,6 @@ page1_init_failed:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine works like lockBtree() except that it also invokes the
|
||||
** busy callback if there is lock contention.
|
||||
*/
|
||||
static int lockBtreeWithRetry(Btree *pRef){
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
assert( sqlite3BtreeHoldsMutex(pRef) );
|
||||
if( pRef->inTrans==TRANS_NONE ){
|
||||
u8 inTransaction = pRef->pBt->inTransaction;
|
||||
btreeIntegrity(pRef);
|
||||
rc = sqlite3BtreeBeginTrans(pRef, 0);
|
||||
pRef->pBt->inTransaction = inTransaction;
|
||||
pRef->inTrans = TRANS_NONE;
|
||||
if( rc==SQLITE_OK ){
|
||||
pRef->pBt->nTransaction--;
|
||||
}
|
||||
btreeIntegrity(pRef);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** If there are no outstanding cursors and we are not in the middle
|
||||
** of a transaction but there is a read lock on the database, then
|
||||
@@ -4321,38 +4329,6 @@ moveto_finish:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** In this version of BtreeMoveto, pKey is a packed index record
|
||||
** such as is generated by the OP_MakeRecord opcode. Unpack the
|
||||
** record and then call BtreeMovetoUnpacked() to do the work.
|
||||
*/
|
||||
int sqlite3BtreeMoveto(
|
||||
BtCursor *pCur, /* Cursor open on the btree to be searched */
|
||||
const void *pKey, /* Packed key if the btree is an index */
|
||||
i64 nKey, /* Integer key for tables. Size of pKey for indices */
|
||||
int bias, /* Bias search to the high end */
|
||||
int *pRes /* Write search results here */
|
||||
){
|
||||
int rc; /* Status code */
|
||||
UnpackedRecord *pIdxKey; /* Unpacked index key */
|
||||
char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
|
||||
|
||||
|
||||
if( pKey ){
|
||||
assert( nKey==(i64)(int)nKey );
|
||||
pIdxKey = sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey,
|
||||
aSpace, sizeof(aSpace));
|
||||
if( pIdxKey==0 ) return SQLITE_NOMEM;
|
||||
}else{
|
||||
pIdxKey = 0;
|
||||
}
|
||||
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
|
||||
if( pKey ){
|
||||
sqlite3VdbeDeleteUnpackedRecord(pIdxKey);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Return TRUE if the cursor is not pointing at an entry of the table.
|
||||
@@ -6361,7 +6337,7 @@ static int balance(BtCursor *pCur){
|
||||
** ignored. For a ZERODATA table, the pData and nData are both ignored.
|
||||
**
|
||||
** If the seekResult parameter is non-zero, then a successful call to
|
||||
** sqlite3BtreeMoveto() to seek cursor pCur to (pKey, nKey) has already
|
||||
** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
|
||||
** been performed. seekResult is the search result returned (a negative
|
||||
** number if pCur points at an entry that is smaller than (pKey, nKey), or
|
||||
** a positive value if pCur points at an etry that is larger than
|
||||
@@ -6377,7 +6353,7 @@ int sqlite3BtreeInsert(
|
||||
const void *pData, int nData, /* The data of the new record */
|
||||
int nZero, /* Number of extra 0 bytes to append to data */
|
||||
int appendBias, /* True if this is likely an append */
|
||||
int seekResult /* Result of prior sqlite3BtreeMoveto() call */
|
||||
int seekResult /* Result of prior MovetoUnpacked() call */
|
||||
){
|
||||
int rc;
|
||||
int loc = seekResult;
|
||||
@@ -6408,18 +6384,18 @@ int sqlite3BtreeInsert(
|
||||
|
||||
/* Save the positions of any other cursors open on this table.
|
||||
**
|
||||
** In some cases, the call to sqlite3BtreeMoveto() below is a no-op. For
|
||||
** In some cases, the call to btreeMoveto() below is a no-op. For
|
||||
** example, when inserting data into a table with auto-generated integer
|
||||
** keys, the VDBE layer invokes sqlite3BtreeLast() to figure out the
|
||||
** integer key to use. It then calls this function to actually insert the
|
||||
** data into the intkey B-Tree. In this case sqlite3BtreeMoveto() recognizes
|
||||
** data into the intkey B-Tree. In this case btreeMoveto() recognizes
|
||||
** that the cursor is already where it needs to be and returns without
|
||||
** doing any work. To avoid thwarting these optimizations, it is important
|
||||
** not to clear the cursor here.
|
||||
*/
|
||||
if(
|
||||
SQLITE_OK!=(rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur)) || (!loc &&
|
||||
SQLITE_OK!=(rc = sqlite3BtreeMoveto(pCur, pKey, nKey, appendBias, &loc))
|
||||
SQLITE_OK!=(rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc))
|
||||
)){
|
||||
return rc;
|
||||
}
|
||||
@@ -7472,6 +7448,9 @@ check_page_abort:
|
||||
** an array of pages numbers were each page number is the root page of
|
||||
** a table. nRoot is the number of entries in aRoot.
|
||||
**
|
||||
** A read-only or read-write transaction must be opened before calling
|
||||
** this function.
|
||||
**
|
||||
** Write the number of error seen in *pnErr. Except for some memory
|
||||
** allocation errors, an error message held in memory obtained from
|
||||
** malloc is returned if *pnErr is non-zero. If *pnErr==0 then NULL is
|
||||
@@ -7491,12 +7470,8 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
char zErr[100];
|
||||
|
||||
sqlite3BtreeEnter(p);
|
||||
assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
|
||||
nRef = sqlite3PagerRefcount(pBt->pPager);
|
||||
if( lockBtreeWithRetry(p)!=SQLITE_OK ){
|
||||
*pnErr = 1;
|
||||
sqlite3BtreeLeave(p);
|
||||
return sqlite3DbStrDup(0, "cannot acquire a read lock on the database");
|
||||
}
|
||||
sCheck.pBt = pBt;
|
||||
sCheck.pPager = pBt->pPager;
|
||||
sCheck.nPage = pagerPagecount(sCheck.pBt);
|
||||
@@ -7505,13 +7480,11 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
sCheck.mallocFailed = 0;
|
||||
*pnErr = 0;
|
||||
if( sCheck.nPage==0 ){
|
||||
unlockBtreeIfUnused(pBt);
|
||||
sqlite3BtreeLeave(p);
|
||||
return 0;
|
||||
}
|
||||
sCheck.anRef = sqlite3Malloc( (sCheck.nPage+1)*sizeof(sCheck.anRef[0]) );
|
||||
if( !sCheck.anRef ){
|
||||
unlockBtreeIfUnused(pBt);
|
||||
*pnErr = 1;
|
||||
sqlite3BtreeLeave(p);
|
||||
return 0;
|
||||
@@ -7566,7 +7539,6 @@ char *sqlite3BtreeIntegrityCheck(
|
||||
** This is an internal consistency check; an integrity check
|
||||
** of the integrity check.
|
||||
*/
|
||||
unlockBtreeIfUnused(pBt);
|
||||
if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
|
||||
checkAppendMsg(&sCheck, 0,
|
||||
"Outstanding page count goes from %d to %d during this analysis",
|
||||
|
Reference in New Issue
Block a user