/ Check-in [91d9d51e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Additional commands and another procedure name changes for clarity of presentation. No logic changes. (CVS 6323)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:91d9d51e03657e7492dd7b93e66c82b152abec3b
User & Date: drh 2009-02-24 19:21:41
Context
2009-02-25
08:56
Minor changes and coverge tests for "SELECT count(*)" optimization. (CVS 6324) check-in: a3695b98 user: danielk1977 tags: trunk
2009-02-24
19:21
Additional commands and another procedure name changes for clarity of presentation. No logic changes. (CVS 6323) check-in: 91d9d51e user: drh tags: trunk
18:57
Changes to comments and functions/procedure names for clarification. No changes to logic. (CVS 6322) check-in: b99c1815 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/btree.c.

     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12         -** $Id: btree.c,v 1.569 2009/02/24 18:57:32 drh Exp $
           12  +** $Id: btree.c,v 1.570 2009/02/24 19:21:41 drh Exp $
    13     13   **
    14     14   ** This file implements a external (disk-based) database using BTrees.
    15     15   ** See the header comment on "btreeInt.h" for additional information.
    16     16   ** Including a description of file format and an overview of operation.
    17     17   */
    18     18   #include "btreeInt.h"
    19     19   
................................................................................
    64     64   }
    65     65   #endif
    66     66   
    67     67   
    68     68   /*
    69     69   ** Forward declaration
    70     70   */
    71         -static int checkReadLocks(Btree*, Pgno, BtCursor*, i64);
           71  +static int checkForReadConflicts(Btree*, Pgno, BtCursor*, i64);
    72     72   
    73     73   
    74     74   #ifdef SQLITE_OMIT_SHARED_CACHE
    75     75     /*
    76     76     ** The functions querySharedCacheTableLock(), setSharedCacheTableLock(),
    77     77     ** and clearAllSharedCacheTableLocks()
    78     78     ** manipulate entries in the BtShared.pLock linked list used to store
................................................................................
  2938   2938     assert( sqlite3BtreeHoldsMutex(p) );
  2939   2939     assert( wrFlag==0 || wrFlag==1 );
  2940   2940     if( wrFlag ){
  2941   2941       assert( !pBt->readOnly );
  2942   2942       if( NEVER(pBt->readOnly) ){
  2943   2943         return SQLITE_READONLY;
  2944   2944       }
  2945         -    if( checkReadLocks(p, iTable, 0, 0) ){
         2945  +    if( checkForReadConflicts(p, iTable, 0, 0) ){
  2946   2946         return SQLITE_LOCKED;
  2947   2947       }
  2948   2948     }
  2949   2949   
  2950   2950     if( pBt->pPage1==0 ){
  2951   2951       rc = lockBtreeWithRetry(p);
  2952   2952       if( rc!=SQLITE_OK ){
................................................................................
  5914   5914   ** This routine checks all cursors that point to table pgnoRoot.
  5915   5915   ** If any of those cursors were opened with wrFlag==0 in a different
  5916   5916   ** database connection (a database connection that shares the pager
  5917   5917   ** cache with the current connection) and that other connection 
  5918   5918   ** is not in the ReadUncommmitted state, then this routine returns 
  5919   5919   ** SQLITE_LOCKED.
  5920   5920   **
  5921         -** As well as cursors with wrFlag==0, cursors with wrFlag==1 and 
  5922         -** isIncrblobHandle==1 are also considered 'read' cursors. Incremental 
  5923         -** blob cursors are used for both reading and writing.
         5921  +** As well as cursors with wrFlag==0, cursors with 
         5922  +** isIncrblobHandle==1 are also considered 'read' cursors because
         5923  +** incremental blob cursors are used for both reading and writing.
  5924   5924   **
  5925   5925   ** When pgnoRoot is the root page of an intkey table, this function is also
  5926   5926   ** responsible for invalidating incremental blob cursors when the table row
  5927   5927   ** on which they are opened is deleted or modified. Cursors are invalidated
  5928   5928   ** according to the following rules:
  5929   5929   **
  5930   5930   **   1) When BtreeClearTable() is called to completely delete the contents
................................................................................
  5938   5938   **      to the integer row id of the B-Tree entry being modified. Unless
  5939   5939   **      pExclude is itself an incremental blob cursor, then all incremental
  5940   5940   **      blob cursors open on row iRow of the B-Tree are invalidated.
  5941   5941   **
  5942   5942   **   3) If both pExclude and iRow are set to zero, no incremental blob 
  5943   5943   **      cursors are invalidated.
  5944   5944   */
  5945         -static int checkReadLocks(
  5946         -  Btree *pBtree, 
  5947         -  Pgno pgnoRoot, 
  5948         -  BtCursor *pExclude,
  5949         -  i64 iRow
         5945  +static int checkForReadConflicts(
         5946  +  Btree *pBtree,          /* The database file to check */
         5947  +  Pgno pgnoRoot,          /* Look for read cursors on this btree */
         5948  +  BtCursor *pExclude,     /* Ignore this cursor */
         5949  +  i64 iRow                /* The rowid that might be changing */
  5950   5950   ){
  5951   5951     BtCursor *p;
  5952   5952     BtShared *pBt = pBtree->pBt;
  5953   5953     sqlite3 *db = pBtree->db;
  5954   5954     assert( sqlite3BtreeHoldsMutex(pBtree) );
  5955   5955     for(p=pBt->pCursor; p; p=p->pNext){
  5956   5956       if( p==pExclude ) continue;
................................................................................
  6005   6005     unsigned char *oldCell;
  6006   6006     unsigned char *newCell = 0;
  6007   6007   
  6008   6008     assert( cursorHoldsMutex(pCur) );
  6009   6009     assert( pBt->inTransaction==TRANS_WRITE );
  6010   6010     assert( !pBt->readOnly );
  6011   6011     assert( pCur->wrFlag );
  6012         -  if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, nKey) ){
         6012  +  if( checkForReadConflicts(pCur->pBtree, pCur->pgnoRoot, pCur, nKey) ){
  6013   6013       return SQLITE_LOCKED; /* The table pCur points to has a read lock */
  6014   6014     }
  6015   6015     if( pCur->eState==CURSOR_FAULT ){
  6016   6016       return pCur->skip;
  6017   6017     }
  6018   6018   
  6019   6019     /* Save the positions of any other cursors open on this table */
................................................................................
  6102   6102     if( pCur->eState==CURSOR_FAULT ){
  6103   6103       return pCur->skip;
  6104   6104     }
  6105   6105     if( NEVER(pCur->aiIdx[pCur->iPage]>=pPage->nCell) ){
  6106   6106       return SQLITE_ERROR;  /* The cursor is not pointing to anything */
  6107   6107     }
  6108   6108     assert( pCur->wrFlag );
  6109         -  if( checkReadLocks(pCur->pBtree, pCur->pgnoRoot, pCur, pCur->info.nKey) ){
         6109  +  if( checkForReadConflicts(pCur->pBtree, pCur->pgnoRoot,
         6110  +                            pCur, pCur->info.nKey)
         6111  +  ){
  6110   6112       return SQLITE_LOCKED; /* The table pCur points to has a read lock */
  6111   6113     }
  6112   6114   
  6113   6115     /* Restore the current cursor position (a no-op if the cursor is not in 
  6114   6116     ** CURSOR_REQUIRESEEK state) and save the positions of any other cursors 
  6115   6117     ** open on the same table. Then call sqlite3PagerWrite() on the page
  6116   6118     ** that the entry will be deleted from.
................................................................................
  6488   6490   */
  6489   6491   int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
  6490   6492     int rc;
  6491   6493     BtShared *pBt = p->pBt;
  6492   6494     sqlite3BtreeEnter(p);
  6493   6495     pBt->db = p->db;
  6494   6496     assert( p->inTrans==TRANS_WRITE );
  6495         -  if( (rc = checkReadLocks(p, iTable, 0, 1))!=SQLITE_OK ){
         6497  +  if( (rc = checkForReadConflicts(p, iTable, 0, 1))!=SQLITE_OK ){
  6496   6498       /* nothing to do */
  6497   6499     }else if( SQLITE_OK!=(rc = saveAllCursors(pBt, iTable, 0)) ){
  6498   6500       /* nothing to do */
  6499   6501     }else{
  6500   6502       rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
  6501   6503     }
  6502   6504     sqlite3BtreeLeave(p);
................................................................................
  7439   7441     **   (c) the cursor points at a valid row of an intKey table.
  7440   7442     */
  7441   7443     if( !pCsr->wrFlag ){
  7442   7444       return SQLITE_READONLY;
  7443   7445     }
  7444   7446     assert( !pCsr->pBt->readOnly 
  7445   7447             && pCsr->pBt->inTransaction==TRANS_WRITE );
  7446         -  if( checkReadLocks(pCsr->pBtree, pCsr->pgnoRoot, pCsr, 0) ){
         7448  +  if( checkForReadConflicts(pCsr->pBtree, pCsr->pgnoRoot, pCsr, 0) ){
  7447   7449       return SQLITE_LOCKED; /* The table pCur points to has a read lock */
  7448   7450     }
  7449   7451     if( pCsr->eState==CURSOR_INVALID || !pCsr->apPage[pCsr->iPage]->intKey ){
  7450   7452       return SQLITE_ERROR;
  7451   7453     }
  7452   7454   
  7453   7455     return accessPayload(pCsr, offset, amt, (unsigned char *)z, 0, 1);