/ Check-in [32a62e3b]
Login

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

Overview
Comment:Additional debugging and tracing logic for pcache.c, turned off by default using an "#if 0".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 32a62e3bd46cf58586617d3f8b1a971c91df205e
User & Date: drh 2016-05-13 04:24:25
Context
2016-05-13
11:50
Fix pager_end_transaction() to ensure that a ROLLBACK does not clobber unwritten pages in a TEMP file pcache. check-in: 9495d338 user: drh tags: trunk
04:24
Additional debugging and tracing logic for pcache.c, turned off by default using an "#if 0". check-in: 32a62e3b user: drh tags: trunk
2016-05-12
19:17
Disable ALWAYS and NEVER when compiled with SQLITE_MUTATION_TEST. check-in: 24d9fbc1 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pcache.c.

    53     53     sqlite3_pcache *pCache;             /* Pluggable cache module */
    54     54   };
    55     55   
    56     56   /*
    57     57   ** Debug tracing macros
    58     58   */
    59     59   #if defined(SQLITE_DEBUG) && 0
    60         -  int sqlite3PcacheTrace = 1;
           60  +  int sqlite3PcacheTrace = 2;
    61     61   # define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;}
    62         -#else
           62  +  void pcacheDump(PCache *pCache){
           63  +    int N;
           64  +    int i, j;
           65  +    sqlite3_pcache_page *pLower;
           66  +    PgHdr *pPg;
           67  +    unsigned char *a;
           68  +  
           69  +    if( sqlite3PcacheTrace<2 ) return;
           70  +    if( pCache->pCache==0 ) return;
           71  +    N = sqlite3PcachePagecount(pCache);
           72  +    if( N>5 ) N = 5;
           73  +    for(i=1; i<=N; i++){
           74  +       pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0);
           75  +       if( pLower==0 ) continue;
           76  +       pPg = (PgHdr*)pLower->pExtra;
           77  +       printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
           78  +       a = (unsigned char *)pLower->pBuf;
           79  +       for(j=0; j<12; j++) printf("%02x", a[j]);
           80  +       printf("\n");
           81  +       if( pPg->pPage==0 ){
           82  +         sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0);
           83  +       }
           84  +    }
           85  +  }
           86  +  #else
    63     87   # define pcacheTrace(X)
           88  +# define pcacheDump(X)
    64     89   #endif
    65     90   
    66     91   /********************************** Linked List Management ********************/
    67     92   
    68     93   /* Allowed values for second argument to pcacheManageDirtyList() */
    69     94   #define PCACHE_DIRTYLIST_REMOVE   1    /* Remove pPage from dirty list */
    70     95   #define PCACHE_DIRTYLIST_ADD      2    /* Add pPage to the dirty list */
................................................................................
   138    163       ** entries of the dirty-list for a page with NEED_SYNC clear anyway.  */
   139    164       if( !p->pSynced 
   140    165        && 0==(pPage->flags&PGHDR_NEED_SYNC)   /*OPTIMIZATION-IF-FALSE*/
   141    166       ){
   142    167         p->pSynced = pPage;
   143    168       }
   144    169     }
          170  +  pcacheDump(p);
   145    171   }
   146    172   
   147    173   /*
   148    174   ** Wrapper around the pluggable caches xUnpin method. If the cache is
   149    175   ** being used for an in-memory database, this function is a no-op.
   150    176   */
   151    177   static void pcacheUnpin(PgHdr *p){
   152    178     if( p->pCache->bPurgeable ){
   153    179       pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno));
   154    180       sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0);
          181  +    pcacheDump(p->pCache);
   155    182     }
   156    183   }
   157    184   
   158    185   /*
   159    186   ** Compute the number of pages of cache requested.   p->szCache is the
   160    187   ** cache size requested by the "PRAGMA cache_size" statement.
   161    188   */
................................................................................
   348    375                     "spill page %d making room for %d - cache used: %d/%d",
   349    376                     pPg->pgno, pgno,
   350    377                     sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache),
   351    378                   numberOfCachePages(pCache));
   352    379   #endif
   353    380         pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno));
   354    381         rc = pCache->xStress(pCache->pStress, pPg);
          382  +      pcacheDump(pCache);
   355    383         if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
   356    384           return rc;
   357    385         }
   358    386       }
   359    387     }
   360    388     *ppPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, 2);
   361    389     return *ppPage==0 ? SQLITE_NOMEM_BKPT : SQLITE_OK;
................................................................................
   492    520   }
   493    521   
   494    522   /*
   495    523   ** Make every page in the cache clean.
   496    524   */
   497    525   void sqlite3PcacheCleanAll(PCache *pCache){
   498    526     PgHdr *p;
          527  +  pcacheTrace(("%p.CLEAN-ALL\n",pCache));
   499    528     while( (p = pCache->pDirty)!=0 ){
   500    529       sqlite3PcacheMakeClean(p);
   501    530     }
   502    531   }
   503    532   
   504    533   /*
   505    534   ** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
   506    535   */
   507    536   void sqlite3PcacheClearWritable(PCache *pCache){
   508    537     PgHdr *p;
          538  +  pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache));
   509    539     for(p=pCache->pDirty; p; p=p->pDirtyNext){
   510    540       p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
   511    541     }
   512    542     pCache->pSynced = pCache->pDirtyTail;
   513    543   }
   514    544   
   515    545   /*