Index: ext/lsm1/lsmInt.h ================================================================== --- ext/lsm1/lsmInt.h +++ ext/lsm1/lsmInt.h @@ -63,12 +63,10 @@ /* Initial values for log file checksums. These are only used if the ** database file does not contain a valid checkpoint. */ #define LSM_CKSUM0_INIT 42 #define LSM_CKSUM1_INIT 42 -#define LSM_META_PAGE_SIZE 4096 - /* "mmap" mode is currently only used in environments with 64-bit address ** spaces. The following macro is used to test for this. */ #define LSM_IS_64_BIT (sizeof(void*)==8) #define LSM_AUTOWORK_QUANT 32 @@ -152,10 +150,19 @@ #define LSM_LOCK_CHECKPOINTER 6 #define LSM_LOCK_ROTRANS 7 #define LSM_LOCK_READER(i) ((i) + LSM_LOCK_ROTRANS + 1) #define LSM_LOCK_RWCLIENT(i) ((i) + LSM_LOCK_READER(LSM_LOCK_NREADER)) +#define LSM_N_LOCK LSM_LOCK_RWCLIENT(LSM_LOCK_NRWCLIENT) + +/* +** Meta-page size and usable size. +*/ +#define LSM_META_PAGE_SIZE 4096 + +#define LSM_META_RW_PAGE_SIZE (LSM_META_PAGE_SIZE - LSM_N_LOCK) + /* ** Hard limit on the number of free-list entries that may be stored in ** a checkpoint (the remainder are stored as a system record in the LSM). ** See also LSM_CONFIG_MAX_FREELIST. */ Index: ext/lsm1/lsm_ckpt.c ================================================================== --- ext/lsm1/lsm_ckpt.c +++ ext/lsm1/lsm_ckpt.c @@ -715,11 +715,13 @@ static int ckptChecksumOk(u32 *aCkpt){ u32 nCkpt = aCkpt[CKPT_HDR_NCKPT]; u32 cksum1; u32 cksum2; - if( nCkpt(LSM_META_PAGE_SIZE)/sizeof(u32) ) return 0; + if( nCkpt(LSM_META_RW_PAGE_SIZE)/sizeof(u32) ){ + return 0; + } ckptChecksum(aCkpt, nCkpt, &cksum1, &cksum2); return (cksum1==aCkpt[nCkpt-2] && cksum2==aCkpt[nCkpt-1]); } /* @@ -868,20 +870,20 @@ ShmHeader *pShm = pDb->pShmhdr; while( (nRem--)>0 ){ int nInt; nInt = pShm->aSnap1[CKPT_HDR_NCKPT]; - if( nInt<=(LSM_META_PAGE_SIZE / sizeof(u32)) ){ + if( nInt<=(LSM_META_RW_PAGE_SIZE / sizeof(u32)) ){ memcpy(pDb->aSnapshot, pShm->aSnap1, nInt*sizeof(u32)); if( ckptChecksumOk(pDb->aSnapshot) ){ if( piRead ) *piRead = 1; return LSM_OK; } } nInt = pShm->aSnap2[CKPT_HDR_NCKPT]; - if( nInt<=(LSM_META_PAGE_SIZE / sizeof(u32)) ){ + if( nInt<=(LSM_META_RW_PAGE_SIZE / sizeof(u32)) ){ memcpy(pDb->aSnapshot, pShm->aSnap2, nInt*sizeof(u32)); if( ckptChecksumOk(pDb->aSnapshot) ){ if( piRead ) *piRead = 2; return LSM_OK; } @@ -1083,11 +1085,11 @@ pSnap->iId++; rc = ckptExportSnapshot(pDb, bFlush, pSnap->iId, 1, &p, &n); if( rc!=LSM_OK ) return rc; assert( ckptChecksumOk((u32 *)p) ); - assert( n<=LSM_META_PAGE_SIZE ); + assert( n<=LSM_META_RW_PAGE_SIZE ); memcpy(pShm->aSnap2, p, n); lsmShmBarrier(pDb); memcpy(pShm->aSnap1, p, n); lsmFree(pDb->pEnv, p); @@ -1118,13 +1120,13 @@ int nCkpt; int nData; u8 *aData; aData = lsmFsMetaPageData(pPg, &nData); - assert( nData==LSM_META_PAGE_SIZE ); + assert( nData==LSM_META_RW_PAGE_SIZE ); nCkpt = lsmGetU32(&aData[CKPT_HDR_NCKPT*sizeof(u32)]); - if( nCkpt<(LSM_META_PAGE_SIZE/sizeof(u32)) ){ + if( nCkpt<(LSM_META_RW_PAGE_SIZE/sizeof(u32)) ){ u32 *aCopy = lsmMallocRc(pDb->pEnv, sizeof(u32) * nCkpt, &rc); if( aCopy ){ memcpy(aCopy, aData, nCkpt*sizeof(u32)); ckptChangeEndianness(aCopy, nCkpt); if( ckptChecksumOk(aCopy) ){ Index: ext/lsm1/lsm_file.c ================================================================== --- ext/lsm1/lsm_file.c +++ ext/lsm1/lsm_file.c @@ -212,10 +212,11 @@ lsm_db *pDb; /* Database handle that owns this object */ lsm_env *pEnv; /* Environment pointer */ char *zDb; /* Database file name */ char *zLog; /* Database file name */ int nMetasize; /* Size of meta pages in bytes */ + int nMetaRwSize; /* Read/written size of meta pages in bytes */ int nPagesize; /* Database page-size in bytes */ int nBlocksize; /* Database block-size in bytes */ /* r/w file descriptors for both files. */ LsmFile *pLsmFile; /* Used after lsm_close() to link into list */ @@ -633,11 +634,12 @@ LsmFile *pLsmFile; pFS->zDb = (char *)&pFS[1]; pFS->zLog = &pFS->zDb[nDb+1]; pFS->nPagesize = LSM_DFLT_PAGE_SIZE; pFS->nBlocksize = LSM_DFLT_BLOCK_SIZE; - pFS->nMetasize = 4 * 1024; + pFS->nMetasize = LSM_META_PAGE_SIZE; + pFS->nMetaRwSize = LSM_META_RW_PAGE_SIZE; pFS->pDb = pDb; pFS->pEnv = pDb->pEnv; /* Make a copy of the database and log file names. */ memcpy(pFS->zDb, zDb, nDb+1); @@ -2269,11 +2271,13 @@ fsGrowMapping(pFS, 2*pFS->nMetasize, &rc); pPg->aData = (u8 *)(pFS->pMap) + iOff; }else{ pPg->aData = lsmMallocRc(pFS->pEnv, pFS->nMetasize, &rc); if( rc==LSM_OK && bWrite==0 ){ - rc = lsmEnvRead(pFS->pEnv, pFS->fdDb, iOff, pPg->aData, pFS->nMetasize); + rc = lsmEnvRead( + pFS->pEnv, pFS->fdDb, iOff, pPg->aData, pFS->nMetaRwSize + ); } #ifndef NDEBUG /* pPg->aData causes an uninitialized access via a downstreadm write(). After discussion on this list, this memory should not, for performance reasons, be memset. However, tracking down "real" misuse is more @@ -2309,11 +2313,11 @@ FileSystem *pFS = pPg->pFS; if( pFS->nMapLimit==0 ){ if( pPg->bWrite ){ i64 iOff = (pPg->iPg==2 ? pFS->nMetasize : 0); - int nWrite = pFS->nMetasize; + int nWrite = pFS->nMetaRwSize; rc = lsmEnvWrite(pFS->pEnv, pFS->fdDb, iOff, pPg->aData, nWrite); } lsmFree(pFS->pEnv, pPg->aData); } @@ -2326,11 +2330,11 @@ ** Return a pointer to a buffer containing the data associated with the ** meta-page passed as the first argument. If parameter pnData is not NULL, ** set *pnData to the size of the meta-page in bytes before returning. */ u8 *lsmFsMetaPageData(MetaPage *pPg, int *pnData){ - if( pnData ) *pnData = pPg->pFS->nMetasize; + if( pnData ) *pnData = pPg->pFS->nMetaRwSize; return pPg->aData; } /* ** Return true if page is currently writable. This is used in assert()