/ Check-in [618a83d6]
Login

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

Overview
Comment:Bug fix in the computation of the number of pages to autovacuum when nReserve is greater than zero. (CVS 6880)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 618a83d65f973183d21245721dc656a35ff594a4
User & Date: drh 2009-07-11 17:04:09
Context
2009-07-11
17:39
Fix a case where deleting a row from a corrupt database could cause an assert to fail. (CVS 6881) check-in: 6994b41a user: danielk1977 tags: trunk
17:04
Bug fix in the computation of the number of pages to autovacuum when nReserve is greater than zero. (CVS 6880) check-in: 618a83d6 user: drh tags: trunk
13:13
Unwind some complex conditions in sqlite3BtreeDelete() into separate "if" statements. (CVS 6879) check-in: d99bde9c 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.678 2009/07/11 13:13:12 drh Exp $
           12  +** $Id: btree.c,v 1.679 2009/07/11 17:04:09 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   
................................................................................
  2848   2848     Pager *pPager = pBt->pPager;
  2849   2849     VVA_ONLY( int nRef = sqlite3PagerRefcount(pPager) );
  2850   2850   
  2851   2851     assert( sqlite3_mutex_held(pBt->mutex) );
  2852   2852     invalidateAllOverflowCache(pBt);
  2853   2853     assert(pBt->autoVacuum);
  2854   2854     if( !pBt->incrVacuum ){
  2855         -    Pgno nFin;
  2856         -    Pgno nFree;
  2857         -    Pgno nPtrmap;
  2858         -    Pgno iFree;
  2859         -    const int pgsz = pBt->pageSize;
  2860         -    Pgno nOrig = pagerPagecount(pBt);
         2855  +    Pgno nFin;         /* Number of pages to be freed */
         2856  +    Pgno nFree;        /* Number of pages no the freelist */
         2857  +    Pgno nPtrmap;      /* Number of PtrMap pages to be freed */
         2858  +    Pgno iFree;        /* The next page to be freed */
         2859  +    int nEntry;        /* Number of entries on one ptrmap page */
         2860  +    Pgno nOrig;        /* Database size before freeing */
  2861   2861   
         2862  +    nOrig = pagerPagecount(pBt);
  2862   2863       if( PTRMAP_ISPAGE(pBt, nOrig) || nOrig==PENDING_BYTE_PAGE(pBt) ){
  2863   2864         /* It is not possible to create a database for which the final page
  2864   2865         ** is either a pointer-map page or the pending-byte page. If one
  2865   2866         ** is encountered, this indicates corruption.
  2866   2867         */
  2867   2868         return SQLITE_CORRUPT_BKPT;
  2868   2869       }
  2869   2870   
  2870   2871       nFree = get4byte(&pBt->pPage1->aData[36]);
  2871         -    nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+pgsz/5)/(pgsz/5);
         2872  +    nEntry = pBt->usableSize/5;
         2873  +    nPtrmap = (nFree-nOrig+PTRMAP_PAGENO(pBt, nOrig)+nEntry)/nEntry;
  2872   2874       nFin = nOrig - nFree - nPtrmap;
  2873   2875       if( nOrig>PENDING_BYTE_PAGE(pBt) && nFin<PENDING_BYTE_PAGE(pBt) ){
  2874   2876         nFin--;
  2875   2877       }
  2876   2878       while( PTRMAP_ISPAGE(pBt, nFin) || nFin==PENDING_BYTE_PAGE(pBt) ){
  2877   2879         nFin--;
  2878   2880       }