/ 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 Unified Diffs Show Whitespace Changes Patch

Changes to src/btree.c.

624
625
626
627
628
629
630




































631
632
633
634
635

636
637
638
639
640
641
642
....
4151
4152
4153
4154
4155
4156
4157


4158
4159
4160
4161
4162
4163
4164
    sqlite3_free(pMap->aRollback);
    sqlite3_free(pMap->aPtr);
    sqlite3_free(pMap->aSvpt);
    sqlite3_free(pMap);
    pBt->pMap = 0;
  }
}




































#else  /* SQLITE_OMIT_CONCURRENT */
# define btreePtrmapAllocate(x) SQLITE_OK
# define btreePtrmapDelete(x) 
# define btreePtrmapBegin(x,y)  SQLITE_OK
# define btreePtrmapEnd(x,y,z) 

#endif /* SQLITE_OMIT_CONCURRENT */

static void releasePage(MemPage *pPage);  /* Forward reference */
static void releasePageOne(MemPage *pPage);      /* Forward reference */
static void releasePageNotNull(MemPage *pPage);  /* Forward reference */

/*
................................................................................
  if( rc==SQLITE_OK ){
    Pgno nHPage = get4byte(&p1[28]);
    Pgno nFin = nHPage;         /* Size of db after transaction merge */

    if( sqlite3PagerIswriteable(pPage1->pDbPage) ){
      Pgno iHTrunk = get4byte(&p1[32]);
      u32 nHFree = get4byte(&p1[36]);



      /* Attach the head database free list to the end of the current
      ** transactions free-list (if any).  */
      if( iTrunk!=0 ){
        put4byte(&p1[36], nHFree + nFree);
        put4byte(&p1[32], iTrunk);
        while( iTrunk ){







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>







 







>
>







624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
....
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
    sqlite3_free(pMap->aRollback);
    sqlite3_free(pMap->aPtr);
    sqlite3_free(pMap->aSvpt);
    sqlite3_free(pMap);
    pBt->pMap = 0;
  }
}

/*
** Check that the pointer-map does not contain any entries with a parent
** page of 0. Call sqlite3_log() multiple times to output the entire
** data structure if it does.
*/
static void btreePtrmapCheck(BtShared *pBt, Pgno nPage){
  Pgno i;
  int bProblem = 0;
  BtreePtrmap *p = pBt->pMap;

  for(i=p->iFirst; i<=nPage; i++){
    PtrmapEntry *pEntry = &p->aPtr[i-p->iFirst];
    if( pEntry->eType==PTRMAP_OVERFLOW1
     || pEntry->eType==PTRMAP_OVERFLOW2
     || pEntry->eType==PTRMAP_BTREE
    ){
      if( pEntry->parent==0 ){
        bProblem = 1;
        break;
      }
    }
  }

  if( bProblem ){
    for(i=p->iFirst; i<=nPage; i++){
      PtrmapEntry *pEntry = &p->aPtr[i-p->iFirst];
      sqlite3_log(SQLITE_CORRUPT, 
          "btreePtrmapCheck: pgno=%d eType=%d parent=%d", 
          (int)i, (int)pEntry->eType, (int)pEntry->parent
      );
    }
    abort();
  }
}

#else  /* SQLITE_OMIT_CONCURRENT */
# define btreePtrmapAllocate(x) SQLITE_OK
# define btreePtrmapDelete(x) 
# define btreePtrmapBegin(x,y)  SQLITE_OK
# define btreePtrmapEnd(x,y,z) 
# define btreePtrmapCheck(y,z) 
#endif /* SQLITE_OMIT_CONCURRENT */

static void releasePage(MemPage *pPage);  /* Forward reference */
static void releasePageOne(MemPage *pPage);      /* Forward reference */
static void releasePageNotNull(MemPage *pPage);  /* Forward reference */

/*
................................................................................
  if( rc==SQLITE_OK ){
    Pgno nHPage = get4byte(&p1[28]);
    Pgno nFin = nHPage;         /* Size of db after transaction merge */

    if( sqlite3PagerIswriteable(pPage1->pDbPage) ){
      Pgno iHTrunk = get4byte(&p1[32]);
      u32 nHFree = get4byte(&p1[36]);

      btreePtrmapCheck(pBt, nPage);

      /* Attach the head database free list to the end of the current
      ** transactions free-list (if any).  */
      if( iTrunk!=0 ){
        put4byte(&p1[36], nHFree + nFree);
        put4byte(&p1[32], iTrunk);
        while( iTrunk ){