/ Check-in [a323bd29]
Login

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

Overview
Comment:Instead of marking a page as clean when sqlite3PagerDontWrite() is called, set a dedictated flag - PGHDR_DONT_WRITE. (CVS 5604)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a323bd29a600abddbcc2cc9961ab84d82cccc5e5
User & Date: danielk1977 2008-08-23 18:53:08
Context
2008-08-25
07:12
If the sector size is greater than the database page size, SQLite journals all pages that lie within a sector before writing to any of them. This change ensure that a journal sync does not occur halfway through journalling the set of pages that belong to a single sector. (CVS 5605) check-in: 16f612d6 user: danielk1977 tags: trunk
2008-08-23
18:53
Instead of marking a page as clean when sqlite3PagerDontWrite() is called, set a dedictated flag - PGHDR_DONT_WRITE. (CVS 5604) check-in: a323bd29 user: danielk1977 tags: trunk
16:17
Do not incorrectly detect corruption when an auto-vacuum database is converted to a non-auto-vacuum database within a vacuum. Ticket #3332. (CVS 5603) check-in: cb869946 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.476 2008/08/22 17:34:45 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.477 2008/08/23 18:53:08 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   
    26     26   /*
    27     27   ** Macros for troubleshooting.  Normally turned off
    28     28   */
................................................................................
  2397   2397       }
  2398   2398   
  2399   2399       /* If there are dirty pages in the page cache with page numbers greater
  2400   2400       ** than Pager.dbSize, this means sqlite3PagerTruncate() was called to
  2401   2401       ** make the file smaller (presumably by auto-vacuum code). Do not write
  2402   2402       ** any such pages to the file.
  2403   2403       */
  2404         -    if( pList->pgno<=pPager->dbSize ){
         2404  +    if( pList->pgno<=pPager->dbSize && 0==(pList->flags&PGHDR_DONT_WRITE) ){
  2405   2405         i64 offset = (pList->pgno-1)*(i64)pPager->pageSize;
  2406   2406         char *pData = CODEC2(pPager, pList->pData, pList->pgno, 6);
  2407   2407         PAGERTRACE4("STORE %d page %d hash(%08x)\n",
  2408   2408                      PAGERID(pPager), pList->pgno, pager_pagehash(pList));
  2409   2409         IOTRACE(("PGOUT %p %d\n", pPager, pList->pgno));
  2410   2410         rc = sqlite3OsWrite(pPager->fd, pData, pPager->pageSize, offset);
  2411   2411         PAGER_INCR(sqlite3_pager_writedb_count);
................................................................................
  2853   2853     }
  2854   2854     if( pPg->pPager==0 ){
  2855   2855       /* The pager cache has created a new page. Its content needs to 
  2856   2856       ** be initialized.
  2857   2857       */
  2858   2858       int nMax;
  2859   2859       PAGER_INCR(pPager->nMiss);
  2860         -    /* pPager->nRef++; */
  2861   2860       pPg->pPager = pPager;
  2862   2861       if( sqlite3BitvecTest(pPager->pInJournal, pgno) ){
  2863   2862         pPg->flags |= PGHDR_IN_JOURNAL;
  2864   2863       }
  2865   2864       memset(pPg->pExtra, 0, pPager->nExtra);
  2866   2865   
  2867   2866       rc = sqlite3PagerPagecount(pPager, &nMax);
................................................................................
  3491   3490         ** size. If you do not write this page and the size of the file
  3492   3491         ** on the disk ends up being too small, that can lead to database
  3493   3492         ** corruption during the next transaction.
  3494   3493         */
  3495   3494       }else{
  3496   3495         PAGERTRACE3("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager));
  3497   3496         IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno))
  3498         -      makeClean(pPg);
         3497  +      pPg->flags |= PGHDR_DONT_WRITE;
  3499   3498   #ifdef SQLITE_CHECK_PAGES
  3500   3499         pPg->pageHash = pager_pagehash(pPg);
  3501   3500   #endif
  3502   3501       }
  3503   3502     }
  3504   3503     pagerLeave(pPager);
  3505   3504   }

Changes to src/pcache.c.

     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     12   ** This file implements that page cache.
    13     13   **
    14         -** @(#) $Id: pcache.c,v 1.10 2008/08/22 17:34:45 drh Exp $
           14  +** @(#) $Id: pcache.c,v 1.11 2008/08/23 18:53:08 danielk1977 Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   
    18     18   /*
    19     19   ** A complete page cache is an instance of this structure.
    20     20   */
    21     21   struct PCache {
................................................................................
   735    735   /*
   736    736   ** Make sure the page is marked as dirty.  If it isn't dirty already,
   737    737   ** make it so.
   738    738   */
   739    739   void sqlite3PcacheMakeDirty(PgHdr *p){
   740    740     PCache *pCache;
   741    741     assert( p->pCache->iInUseDB );
          742  +  p->flags &= ~PGHDR_DONT_WRITE;
   742    743     if( p->flags & PGHDR_DIRTY ) return;
   743    744     assert( (p->flags & PGHDR_DIRTY)==0 );
   744    745     assert( p->nRef>0 );
   745    746     pCache = p->pCache;
   746    747     pcacheRemoveFromList(&pCache->pClean, p);
   747    748     pcacheAddToList(&pCache->pDirty, p);
   748    749     p->flags |= PGHDR_DIRTY;

Changes to src/pcache.h.

     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     12   ** This header file defines the interface that the sqlite page cache
    13     13   ** subsystem. 
    14     14   **
    15         -** @(#) $Id: pcache.h,v 1.4 2008/08/22 16:22:17 danielk1977 Exp $
           15  +** @(#) $Id: pcache.h,v 1.5 2008/08/23 18:53:08 danielk1977 Exp $
    16     16   */
    17     17   
    18     18   #ifndef _PCACHE_H_
    19     19   
    20     20   typedef struct PgHdr PgHdr;
    21     21   typedef struct PCache PCache;
    22     22   
................................................................................
    48     48   #define PGHDR_IN_STMTJRNL       0x002  /* Page is in the statement journal */
    49     49   #define PGHDR_DIRTY             0x004  /* Page has changed */
    50     50   #define PGHDR_NEED_SYNC         0x008  /* Peed to fsync this page */
    51     51   #define PGHDR_ALWAYS_ROLLBACK   0x010  /* Force writing to journal */
    52     52   #define PGHDR_NEED_READ         0x020  /* Content is unread */
    53     53   #define PGHDR_IS_INIT           0x040  /* pData is initialized */
    54     54   #define PGHDR_REUSE_UNLIKELY    0x080  /* Hint: Reuse is unlikely */
    55         -
           55  +#define PGHDR_DONT_WRITE        0x100  /* Do not write content to disk */
    56     56   
    57     57   /* Initialize and shutdown the page cache subsystem */
    58     58   int sqlite3PcacheInitialize(void);
    59     59   void sqlite3PcacheShutdown(void);
    60     60   
    61     61   /* Page cache buffer management:
    62     62   ** These routines implement SQLITE_CONFIG_PAGECACHE.