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

Overview
Comment:Speed up the assert() used to check that no page references are being leaked.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d276ad3f9e3873e89d0fca27799f5240ee3f9300
User & Date: dan 2013-10-12 20:03:25.771
Context
2013-10-14
14:03
Use key-prefixes instead of full keys on interior nodes. check-in: 449433ea21 user: dan tags: trunk
2013-10-12
20:03
Speed up the assert() used to check that no page references are being leaked. check-in: d276ad3f9e user: dan tags: trunk
19:50
Fix page reference leaks in btree code. check-in: f69b88077c user: dan tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/bt_main.c.
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
int btErrorBkpt(int rc){
  static int error_cnt = 0;
  error_cnt++;
  return rc;
}
#endif

#if !defined(NDEBUG) && BT_EXPENSIVE_ASSERT
static void btCheckPageRefs(bt_db *pDb){
  int nActual = 0;
  int nExpect;
  bt_cursor *pCsr;

  nExpect = sqlite4BtPagerRefcount(pDb->pPager);
  for(pCsr=pDb->pAllCsr; pCsr; pCsr=pCsr->pNextCsr){
    if( pCsr->nPg>0 ) nActual += pCsr->nPg;
  }

  assert( nActual==nExpect );
}
#else
# define btCheckPageRefs(x) 
#endif

/*







|

|
|
|

<

|

>







61
62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
int btErrorBkpt(int rc){
  static int error_cnt = 0;
  error_cnt++;
  return rc;
}
#endif

#if !defined(NDEBUG) 
static void btCheckPageRefs(bt_db *pDb){
  int nActual = 0;                /* Outstanding refs according to pager */
  int nExpect = 0;                /* According to the set of open cursors */
  bt_cursor *pCsr;                /* Iterator variable */


  for(pCsr=pDb->pAllCsr; pCsr; pCsr=pCsr->pNextCsr){
    if( pCsr->nPg>0 ) nExpect += pCsr->nPg;
  }
  nActual = sqlite4BtPagerRefcount(pDb->pPager);
  assert( nActual==nExpect );
}
#else
# define btCheckPageRefs(x) 
#endif

/*
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201

  btCheckPageRefs(db);
  return rc;
}

int sqlite4BtDelete(bt_cursor *pCsr){
  int rc;
  btCheckPageRefs(db);
  rc =  btDeleteFromPage(pCsr, 1);
  if( rc==SQLITE4_OK ){
    rc = btBalanceIfUnderfull(pCsr);
  }
  btCheckPageRefs(db);
  return rc;
}

int sqlite4BtSetCookie(bt_db *db, unsigned int iVal){
  return sqlite4BtPagerSetCookie(db->pPager, iVal);
}

int sqlite4BtGetCookie(bt_db *db, unsigned int *piVal){
  return sqlite4BtPagerGetCookie(db->pPager, piVal);
}








|




|











2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201

  btCheckPageRefs(db);
  return rc;
}

int sqlite4BtDelete(bt_cursor *pCsr){
  int rc;
  btCheckPageRefs(pCsr->pDb);
  rc =  btDeleteFromPage(pCsr, 1);
  if( rc==SQLITE4_OK ){
    rc = btBalanceIfUnderfull(pCsr);
  }
  btCheckPageRefs(pCsr->pDb);
  return rc;
}

int sqlite4BtSetCookie(bt_db *db, unsigned int iVal){
  return sqlite4BtPagerSetCookie(db->pPager, iVal);
}

int sqlite4BtGetCookie(bt_db *db, unsigned int *piVal){
  return sqlite4BtPagerGetCookie(db->pPager, piVal);
}

Changes to src/bt_pager.c.
72
73
74
75
76
77
78

79
80
81
82
83
84
85
  int iTransactionLevel;          /* Current transaction level (see bt.h) */
  char *zFile;                    /* Database file name */
  int nFile;                      /* Length of string zFile in bytes */
  bt_file *pFd;                   /* Database file */
  BtPageHash hash;                /* Hash table */
  BtPage *pDirty;                 /* List of all dirty pages */
  BtDbhdr dbhdr;

};


/**************************************************************************
** Interface to BtPageHash object.
*/








>







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
  int iTransactionLevel;          /* Current transaction level (see bt.h) */
  char *zFile;                    /* Database file name */
  int nFile;                      /* Length of string zFile in bytes */
  bt_file *pFd;                   /* Database file */
  BtPageHash hash;                /* Hash table */
  BtPage *pDirty;                 /* List of all dirty pages */
  BtDbhdr dbhdr;
  int nTotalRef;
};


/**************************************************************************
** Interface to BtPageHash object.
*/

497
498
499
500
501
502
503

504
505
506
507
508
509
510
        btFreePage(p, pRet);
        pRet = 0;
      }
    }
  }

  if( rc==SQLITE4_OK ){

    pRet->nRef++;
    *ppPg = pRet;
  }
  return rc;
}

int sqlite4BtPageWrite(BtPage *pPg){







>







498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
        btFreePage(p, pRet);
        pRet = 0;
      }
    }
  }

  if( rc==SQLITE4_OK ){
    p->nTotalRef++;
    pRet->nRef++;
    *ppPg = pRet;
  }
  return rc;
}

int sqlite4BtPageWrite(BtPage *pPg){
526
527
528
529
530
531
532

533
534
535
536
537
538
539

540
541
542
543
544
545
546
  return SQLITE4_OK;
}

int sqlite4BtPageRelease(BtPage *pPg){
  if( pPg ){
    assert( pPg->nRef>=1 );
    pPg->nRef--;

  }
  return SQLITE4_OK;
}

void sqlite4BtPageReference(BtPage *pPg){
  assert( pPg->nRef>=1 );
  pPg->nRef++;

}

/*
** Allocate a new database page and return a writable reference to it.
*/
int sqlite4BtPageAllocate(BtPager *p, BtPage **ppPg){
  BtPage *pPg = 0;







>







>







528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
  return SQLITE4_OK;
}

int sqlite4BtPageRelease(BtPage *pPg){
  if( pPg ){
    assert( pPg->nRef>=1 );
    pPg->nRef--;
    pPg->pPager->nTotalRef--;
  }
  return SQLITE4_OK;
}

void sqlite4BtPageReference(BtPage *pPg){
  assert( pPg->nRef>=1 );
  pPg->nRef++;
  pPg->pPager->nTotalRef++;
}

/*
** Allocate a new database page and return a writable reference to it.
*/
int sqlite4BtPageAllocate(BtPager *p, BtPage **ppPg){
  BtPage *pPg = 0;
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
int sqlite4BtPagerGetCookie(BtPager *p, u32 *piVal){
  assert( p->iTransactionLevel>=1 );
  *piVal = p->dbhdr.cookie;
  return SQLITE4_OK;
}

#ifndef NDEBUG
static void btPagerRefcountCb(void *pCtx, BtPage *pPg){
  assert( pPg->nRef>=0 );
  (*(int*)pCtx) += pPg->nRef;
}
int sqlite4BtPagerRefcount(BtPager *p){
  int nRef = 0;
  btHashIterate(p, btPagerRefcountCb, (void*)&nRef);
  return nRef;
}
#endif








<
<
<
<

<
<
|



599
600
601
602
603
604
605




606


607
608
609
610
int sqlite4BtPagerGetCookie(BtPager *p, u32 *piVal){
  assert( p->iTransactionLevel>=1 );
  *piVal = p->dbhdr.cookie;
  return SQLITE4_OK;
}

#ifndef NDEBUG




int sqlite4BtPagerRefcount(BtPager *p){


  return p->nTotalRef;
}
#endif