/ Check-in [53aaeea6]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix many minor issues in the unlocked transaction code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent
Files: files | file ages | folders
SHA1: 53aaeea6c98f82f3b55d4b3ab139ee41b727243c
User & Date: dan 2015-08-21 20:11:23
Wiki:begin-concurrent
Context
2015-08-22
07:55
Merge trunk changes into this branch. check-in: 9021f736 user: dan tags: begin-concurrent
2015-08-21
20:11
Fix many minor issues in the unlocked transaction code. check-in: 53aaeea6 user: dan tags: begin-concurrent
18:55
When committing an UNLOCKED transaction, try to move pages allocated at the end of the file to free slots within the file (like an incremental-vacuum operation does). check-in: 06967916 user: dan tags: begin-concurrent
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  3902   3902           ** nPage (inclusive) at the end of the database file. Meanwhile,
  3903   3903           ** other transactions have allocated (iFirst..nHPage). So move
  3904   3904           ** pages (iFirst..MIN(nPage,nHPage)) to (MAX(nPage,nHPage)+1).
  3905   3905           */
  3906   3906           Pgno iLast = MIN(nPage, nHPage);    /* Last page to move */
  3907   3907           Pgno iPg;
  3908   3908           Pgno nCurrent;                      /* Current size of db */
  3909         -
  3910   3909           nCurrent = MAX(nPage, nHPage);
         3910  +
  3911   3911           for(iPg=pMap->iFirst; iPg<=iLast && rc==SQLITE_OK; iPg++){
  3912   3912             MemPage *pPg = 0;
  3913   3913             Pgno iNew;              /* New page number for pPg */
  3914   3914             PtrmapEntry *pEntry;    /* Pointer map entry for page iPg */
  3915   3915   
  3916   3916             pEntry = &pMap->aPtr[iPg - pMap->iFirst];
  3917   3917             if( pEntry->eType==PTRMAP_FREEPAGE ){

Changes to src/main.c.

  2740   2740     db->magic = SQLITE_MAGIC_BUSY;
  2741   2741     db->aDb = db->aDbStatic;
  2742   2742   
  2743   2743     assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
  2744   2744     memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
  2745   2745     db->aLimit[SQLITE_LIMIT_WORKER_THREADS] = SQLITE_DEFAULT_WORKER_THREADS;
  2746   2746     db->autoCommit = 1;
  2747         -  db->bUnlocked = 0;
  2748   2747     db->nextAutovac = -1;
  2749   2748     db->szMmap = sqlite3GlobalConfig.szMmap;
  2750   2749     db->nextPagesize = 0;
  2751   2750     db->nMaxSorterMmap = 0x7FFFFFFF;
  2752   2751     db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill
  2753   2752   #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX
  2754   2753                    | SQLITE_AutoIndex

Changes to src/pager.c.

  5627   5627         */
  5628   5628         if( exFlag>=0 ){
  5629   5629           rc = sqlite3WalBeginWriteTransaction(pPager->pWal);
  5630   5630         }else{
  5631   5631           pPager->pAllRead = sqlite3BitvecCreate(pPager->dbSize);
  5632   5632           if( pPager->pAllRead==0 ){
  5633   5633             rc = SQLITE_NOMEM;
  5634         -        }else{
  5635         -          rc = sqlite3BitvecSet(pPager->pAllRead, 1);
  5636   5634           }
  5637   5635         }
  5638   5636       }else{
  5639   5637         /* Obtain a RESERVED lock on the database file. If the exFlag parameter
  5640   5638         ** is true, then immediately upgrade this to an EXCLUSIVE lock. The
  5641   5639         ** busy-handler callback can be used when upgrading to the EXCLUSIVE
  5642   5640         ** lock, but not when obtaining the RESERVED lock.
................................................................................
  6151   6149   void sqlite3PagerDropExclusiveLock(Pager *pPager){
  6152   6150     if( pagerUseWal(pPager) ){
  6153   6151       sqlite3WalEndWriteTransaction(pPager->pWal);
  6154   6152     }
  6155   6153   }
  6156   6154   
  6157   6155   /*
  6158         -** Return true if this is a WAL database and snapshot upgrade is required
  6159         -** before the current transaction can be committed.
         6156  +** Return true if this pager is currently within an UNLOCKED transaction.
  6160   6157   */
  6161   6158   int sqlite3PagerIsUnlocked(Pager *pPager){
  6162   6159     return pPager->pAllRead!=0;
  6163   6160   }
  6164   6161   
  6165   6162   
  6166   6163   /*

Changes to src/pager.h.

   141    141   /* Operations on page references. */
   142    142   int sqlite3PagerWrite(DbPage*);
   143    143   void sqlite3PagerDontWrite(DbPage*);
   144    144   int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
   145    145   int sqlite3PagerPageRefcount(DbPage*);
   146    146   void *sqlite3PagerGetData(DbPage *); 
   147    147   void *sqlite3PagerGetExtra(DbPage *); 
   148         -int sqlite3PagerIsDirty(DbPage*);
   149    148   
   150    149   /* Functions used to manage pager transactions and savepoints. */
   151    150   void sqlite3PagerPagecount(Pager*, int*);
   152    151   int sqlite3PagerBegin(Pager*, int exFlag, int);
   153    152   int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
   154    153   int sqlite3PagerExclusiveLock(Pager*, DbPage *pPage1);
   155    154   int sqlite3PagerSync(Pager *pPager, const char *zMaster);
   156    155   int sqlite3PagerCommitPhaseTwo(Pager*);
   157    156   int sqlite3PagerRollback(Pager*);
   158    157   int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
   159    158   int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
   160    159   int sqlite3PagerSharedLock(Pager *pPager);
   161    160   
   162         -void sqlite3PagerDropExclusiveLock(Pager*);
   163         -int sqlite3PagerIsUnlocked(Pager*);
   164    161   
   165    162   #ifndef SQLITE_OMIT_WAL
   166    163     int sqlite3PagerCheckpoint(Pager *pPager, int, int*, int*);
   167    164     int sqlite3PagerWalSupported(Pager *pPager);
   168    165     int sqlite3PagerWalCallback(Pager *pPager);
   169    166     int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen);
   170    167     int sqlite3PagerCloseWal(Pager *pPager);
................................................................................
   193    190   int sqlite3SectorSize(sqlite3_file *);
   194    191   
   195    192   /* Functions used to truncate the database file. */
   196    193   void sqlite3PagerTruncateImage(Pager*,Pgno);
   197    194   
   198    195   void sqlite3PagerRekey(DbPage*, Pgno, u16);
   199    196   
          197  +void sqlite3PagerDropExclusiveLock(Pager*);
          198  +int sqlite3PagerIsUnlocked(Pager*);
   200    199   int sqlite3PagerIswriteable(DbPage*);
   201    200   int sqlite3PagerUpgradeSnapshot(Pager *pPager, DbPage*);
   202    201   void sqlite3PagerSetDbsize(Pager *pPager, Pgno);
   203    202   
   204    203   #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_WAL)
   205    204   void *sqlite3PagerCodec(DbPage *);
   206    205   #endif

Changes to src/vacuum.c.

   352    352     ** database. No locks are held on any other files (since the main file
   353    353     ** was committed at the btree level). So it safe to end the transaction
   354    354     ** by manually setting the autoCommit flag to true and detaching the
   355    355     ** vacuum database. The vacuum_db journal file is deleted when the pager
   356    356     ** is closed by the DETACH.
   357    357     */
   358    358     db->autoCommit = 1;
   359         -  db->bUnlocked = 0;
          359  +  assert( db->bUnlocked==0 );
   360    360   
   361    361     if( pDb ){
   362    362       sqlite3BtreeClose(pDb->pBt);
   363    363       pDb->pBt = 0;
   364    364       pDb->pSchema = 0;
   365    365     }
   366    366   

Changes to src/vdbeaux.c.

  2567   2567     ** to invoke any required unlock-notify callbacks.
  2568   2568     */
  2569   2569     if( db->autoCommit ){
  2570   2570       sqlite3ConnectionUnlocked(db);
  2571   2571     }
  2572   2572   
  2573   2573     assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
  2574         -  return ((p->rc & 0xFF)==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
         2574  +  return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
  2575   2575   }
  2576   2576   
  2577   2577   
  2578   2578   /*
  2579   2579   ** Each VDBE holds the result of the most recent sqlite3_step() call
  2580   2580   ** in p->rc.  This routine sets that result back to SQLITE_OK.
  2581   2581   */

Changes to src/wal.c.

  2667   2667   }
  2668   2668   
  2669   2669   void sqlite3WalUpgradeSnapshot(Wal *pWal){
  2670   2670     assert( pWal->writeLock );
  2671   2671     memcpy(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr));
  2672   2672   }
  2673   2673   
  2674         -/*
  2675         -** This function is only ever called while committing an UNLOCKED 
  2676         -** transaction, after the caller has already obtained the WRITER lock
  2677         -** (by calling the sqlite3WalLockForCommit() routine). This function 
  2678         -** returns true if the transaction was prepared against a database 
  2679         -** snapshot older than the current head of the wal file.
  2680         -**
  2681         -** Note that this will only work as described if the database is 
  2682         -** currently executing an UNLOCKED transaction, as it assumes that 
  2683         -** pWal->hdr has not been modified since the beginning of the 
  2684         -** transaction. This may not be true for a non-UNLOCKED transaction,
  2685         -** as pWal->hdr is updated if any pages are spilled to the wal file
  2686         -** while the transaction is executing.
  2687         -*/
  2688         -int sqlite3WalCommitRequiresUpgrade(Wal *pWal){
  2689         -  assert( pWal->writeLock );
  2690         -  return memcmp(&pWal->hdr, (void*)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0;
  2691         -}
  2692         -
  2693   2674   /*
  2694   2675   ** End a write transaction.  The commit has already been done.  This
  2695   2676   ** routine merely releases the lock.
  2696   2677   */
  2697   2678   int sqlite3WalEndWriteTransaction(Wal *pWal){
  2698   2679     if( pWal->writeLock ){
  2699   2680       walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);

Changes to src/wal.h.

   122    122   
   123    123   /* Return true if the argument is non-NULL and the WAL module is using
   124    124   ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
   125    125   ** WAL module is using shared-memory, return false. 
   126    126   */
   127    127   int sqlite3WalHeapMemory(Wal *pWal);
   128    128   
   129         -/* Return true if the WRITER lock is held. False otherwise. */
   130    129   int sqlite3WalLockForCommit(Wal *pWal, PgHdr *pPg, Bitvec *pRead);
   131         -int sqlite3WalCommitRequiresUpgrade(Wal *pWal);
   132    130   void sqlite3WalUpgradeSnapshot(Wal *pWal);
   133    131   
   134    132   #ifdef SQLITE_ENABLE_ZIPVFS
   135    133   /* If the WAL file is not empty, return the number of bytes of content
   136    134   ** stored in each frame (i.e. the db page-size when the WAL was created).
   137    135   */
   138    136   int sqlite3WalFramesize(Wal *pWal);
   139    137   #endif
   140    138   
   141    139   #endif /* ifndef SQLITE_OMIT_WAL */
   142    140   #endif /* _WAL_H_ */