SQLite4
Check-in [84e9aca245]
Not logged in

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

Overview
Comment:Fix a compressed database mode bug.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | prefix-mmap
Files: files | file ages | folders
SHA1: 84e9aca2455b73e4939a1e2fd43b5a252b69112d
User & Date: dan 2013-03-07 19:54:38
Context
2013-03-07
20:12
Fix some test cases to account for sqlite4 memory mapping the file. Leaf check-in: 5f9133f8a8 user: dan tags: prefix-mmap
19:54
Fix a compressed database mode bug. check-in: 84e9aca245 user: dan tags: prefix-mmap
18:36
When recycling an lsm cursor, reset the flags field. check-in: 4d830d87e4 user: dan tags: prefix-mmap
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/lsm_file.c.

   241    241     /* Page cache parameters for non-mmap() pages */
   242    242     int nCacheMax;                  /* Configured cache size (in pages) */
   243    243     int nCacheAlloc;                /* Current cache size (in pages) */
   244    244     Page *pLruFirst;                /* Head of the LRU list */
   245    245     Page *pLruLast;                 /* Tail of the LRU list */
   246    246     int nHash;                      /* Number of hash slots in hash table */
   247    247     Page **apHash;                  /* nHash Hash slots */
   248         -
   249         -  /* Both types of pages */
   250    248     Page *pWaiting;                 /* b-tree pages waiting to be written */
   251    249   
   252    250     /* Statistics */
   253    251     int nOut;                       /* Number of outstanding pages */
   254    252     int nWrite;                     /* Total number of pages written */
   255    253     int nRead;                      /* Total number of pages read */
   256    254   };
................................................................................
   977    975   
   978    976     iHash = fsHashKey(pFS->nHash, pPg->iPg);
   979    977     for(pp=&pFS->apHash[iHash]; *pp!=pPg; pp=&(*pp)->pHashNext);
   980    978     *pp = pPg->pHashNext;
   981    979     pPg->pHashNext = 0;
   982    980   }
   983    981   
          982  +static void fsPageBufferFree(Page *pPg){
          983  +  pPg->pFS->nCacheAlloc--;
          984  +  lsmFree(pPg->pFS->pEnv, pPg->aData);
          985  +  lsmFree(pPg->pFS->pEnv, pPg);
          986  +}
          987  +
   984    988   
   985    989   /*
   986    990   ** Purge the cache of all non-mmap pages with nRef==0.
   987    991   */
   988    992   void lsmFsPurgeCache(FileSystem *pFS){
   989    993     Page *pPg;
   990    994   
   991    995     pPg = pFS->pLruFirst;
   992    996     while( pPg ){
   993    997       Page *pNext = pPg->pLruNext;
   994    998       assert( pPg->flags & PAGE_FREE );
   995    999       fsPageRemoveFromHash(pFS, pPg);
   996         -    lsmFree(pFS->pEnv, pPg->aData);
   997         -    lsmFree(pFS->pEnv, pPg);
         1000  +    fsPageBufferFree(pPg);
   998   1001       pPg = pNext;
   999         -    pFS->nCacheAlloc--;
  1000   1002     }
  1001   1003     pFS->pLruFirst = 0;
  1002   1004     pFS->pLruLast = 0;
  1003   1005   
  1004   1006     assert( pFS->nCacheAlloc<=pFS->nOut && pFS->nCacheAlloc>=0 );
  1005   1007   }
  1006   1008   
................................................................................
  1060   1062     if( pPage ){
  1061   1063       pPage->flags = PAGE_FREE;
  1062   1064     }
  1063   1065     *ppOut = pPage;
  1064   1066     return rc;
  1065   1067   }
  1066   1068   
  1067         -static void fsPageBufferFree(Page *pPg){
  1068         -  assert( pPg->pLruNext==0 );
  1069         -  assert( pPg->pLruPrev==0 );
  1070         -  assert( pPg->pFS->pLruFirst!=pPg );
  1071         -  assert( pPg->pFS->pLruLast!=pPg );
  1072         -
  1073         -  lsmFree(pPg->pFS->pEnv, pPg->aData);
  1074         -  lsmFree(pPg->pFS->pEnv, pPg);
  1075         -}
  1076         -
  1077   1069   static void fsGrowMapping(
  1078   1070     FileSystem *pFS,
  1079   1071     i64 iSz,
  1080   1072     int *pRc
  1081   1073   ){
  1082   1074     /* This function won't work with compressed databases yet. */
  1083   1075     assert( pFS->pCompress==0 );

Changes to src/lsm_unix.c.

   198    198     lsm_i64 *pnOut
   199    199   ){
   200    200     off_t iSz;
   201    201     int prc;
   202    202     PosixFile *p = (PosixFile *)pFile;
   203    203     struct stat buf;
   204    204   
          205  +  /* If the file is between 0 and 2MB in size, extend it in chunks of 256K.
          206  +  ** Thereafter, in chunks of 1MB at a time.  */
          207  +  const int aIncrSz[] = {256*1024, 1024*1024};
          208  +  int nIncrSz = aIncrSz[iMin>(2*1024*1024)];
          209  +
   205    210     if( p->pMap ){
   206    211       munmap(p->pMap, p->nMap);
   207    212       *ppOut = p->pMap = 0;
   208    213       *pnOut = p->nMap = 0;
   209    214     }
   210    215   
   211    216     if( iMin>=0 ){
   212    217       memset(&buf, 0, sizeof(buf));
   213    218       prc = fstat(p->fd, &buf);
   214    219       if( prc!=0 ) return LSM_IOERR_BKPT;
   215    220       iSz = buf.st_size;
   216    221       if( iSz<iMin ){
   217         -      iSz = ((iMin + (2<<20) - 1) / (2<<20)) * (2<<20);
          222  +      iSz = ((iMin + nIncrSz-1) / nIncrSz) * nIncrSz;
   218    223         prc = ftruncate(p->fd, iSz);
   219    224         if( prc!=0 ) return LSM_IOERR_BKPT;
   220    225       }
   221    226   
   222    227       p->pMap = mmap(0, iSz, PROT_READ|PROT_WRITE, MAP_SHARED, p->fd, 0);
   223    228       p->nMap = iSz;
   224    229     }