/ Check-in [57023371]
Login

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

Overview
Comment:Add extra code to log details when corruption is detected in the pointer-map structure maintained by the b-tree layer in begin-concurrent transactions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | begin-concurrent-pnu
Files: files | file ages | folders
SHA3-256: 570233716032f258b878d52c4d5a47e07292d66fa84e3a85c0388ec15efee625
User & Date: dan 2018-02-20 21:00:45
Context
2018-12-03
19:29
Cherrypick a couple of fixes from begin-concurrent-pnu into this branch. The differences between the two branches are now that this one does not have "PRAGMA noop_update" or the mutex-free PRNG. check-in: a56506b9 user: dan tags: begin-concurrent
2018-03-02
18:26
Merge latest changes from begin-concurrent into this branch. check-in: 8ade94ba user: dan tags: begin-concurrent-pnu
2018-02-20
21:00
Add extra code to log details when corruption is detected in the pointer-map structure maintained by the b-tree layer in begin-concurrent transactions. check-in: 57023371 user: dan tags: begin-concurrent-pnu
2018-01-04
18:36
Fix problem causing free-list corruption when merging free-lists for two concurrent transactions that have both used page X as an in-memory free-list trunk page, where X lies past the end of the initial database images. check-in: dc0fc2aa user: dan tags: begin-concurrent-pnu
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

   624    624       sqlite3_free(pMap->aRollback);
   625    625       sqlite3_free(pMap->aPtr);
   626    626       sqlite3_free(pMap->aSvpt);
   627    627       sqlite3_free(pMap);
   628    628       pBt->pMap = 0;
   629    629     }
   630    630   }
          631  +
          632  +/*
          633  +** Check that the pointer-map does not contain any entries with a parent
          634  +** page of 0. Call sqlite3_log() multiple times to output the entire
          635  +** data structure if it does.
          636  +*/
          637  +static void btreePtrmapCheck(BtShared *pBt, Pgno nPage){
          638  +  Pgno i;
          639  +  int bProblem = 0;
          640  +  BtreePtrmap *p = pBt->pMap;
          641  +
          642  +  for(i=p->iFirst; i<=nPage; i++){
          643  +    PtrmapEntry *pEntry = &p->aPtr[i-p->iFirst];
          644  +    if( pEntry->eType==PTRMAP_OVERFLOW1
          645  +     || pEntry->eType==PTRMAP_OVERFLOW2
          646  +     || pEntry->eType==PTRMAP_BTREE
          647  +    ){
          648  +      if( pEntry->parent==0 ){
          649  +        bProblem = 1;
          650  +        break;
          651  +      }
          652  +    }
          653  +  }
          654  +
          655  +  if( bProblem ){
          656  +    for(i=p->iFirst; i<=nPage; i++){
          657  +      PtrmapEntry *pEntry = &p->aPtr[i-p->iFirst];
          658  +      sqlite3_log(SQLITE_CORRUPT, 
          659  +          "btreePtrmapCheck: pgno=%d eType=%d parent=%d", 
          660  +          (int)i, (int)pEntry->eType, (int)pEntry->parent
          661  +      );
          662  +    }
          663  +    abort();
          664  +  }
          665  +}
          666  +
   631    667   #else  /* SQLITE_OMIT_CONCURRENT */
   632    668   # define btreePtrmapAllocate(x) SQLITE_OK
   633    669   # define btreePtrmapDelete(x) 
   634    670   # define btreePtrmapBegin(x,y)  SQLITE_OK
   635    671   # define btreePtrmapEnd(x,y,z) 
          672  +# define btreePtrmapCheck(y,z) 
   636    673   #endif /* SQLITE_OMIT_CONCURRENT */
   637    674   
   638    675   static void releasePage(MemPage *pPage);  /* Forward reference */
   639    676   static void releasePageOne(MemPage *pPage);      /* Forward reference */
   640    677   static void releasePageNotNull(MemPage *pPage);  /* Forward reference */
   641    678   
   642    679   /*
................................................................................
  4151   4188     if( rc==SQLITE_OK ){
  4152   4189       Pgno nHPage = get4byte(&p1[28]);
  4153   4190       Pgno nFin = nHPage;         /* Size of db after transaction merge */
  4154   4191   
  4155   4192       if( sqlite3PagerIswriteable(pPage1->pDbPage) ){
  4156   4193         Pgno iHTrunk = get4byte(&p1[32]);
  4157   4194         u32 nHFree = get4byte(&p1[36]);
         4195  +
         4196  +      btreePtrmapCheck(pBt, nPage);
  4158   4197   
  4159   4198         /* Attach the head database free list to the end of the current
  4160   4199         ** transactions free-list (if any).  */
  4161   4200         if( iTrunk!=0 ){
  4162   4201           put4byte(&p1[36], nHFree + nFree);
  4163   4202           put4byte(&p1[32], iTrunk);
  4164   4203           while( iTrunk ){