Index: lsm-test/lsmtest_tdb3.c ================================================================== --- lsm-test/lsmtest_tdb3.c +++ lsm-test/lsmtest_tdb3.c @@ -13,12 +13,12 @@ typedef struct LsmDb LsmDb; typedef struct LsmWorker LsmWorker; typedef struct LsmFile LsmFile; -#define LSMTEST_DFLT_MT_MAX_CKPT (8*1024*1024) -#define LSMTEST_DFLT_MT_MIN_CKPT (2*1024*1024) +#define LSMTEST_DFLT_MT_MAX_CKPT (8*1024) +#define LSMTEST_DFLT_MT_MIN_CKPT (2*1024) #ifdef LSM_MUTEX_PTHREADS #include #define LSMTEST_THREAD_CKPT 1 @@ -498,17 +498,17 @@ return rc; } static int waitOnCheckpointer(LsmDb *pDb, lsm_db *db){ int nSleep = 0; - int nByte; + int nKB; int rc; do { - nByte = 0; - rc = lsm_info(db, LSM_INFO_CHECKPOINT_SIZE, &nByte); - if( rc!=LSM_OK || nBytenMtMaxCkpt ) break; + nKB = 0; + rc = lsm_info(db, LSM_INFO_CHECKPOINT_SIZE, &nKB); + if( rc!=LSM_OK || nKBnMtMaxCkpt ) break; usleep(5000); nSleep += 5; }while( 1 ); #if 0 @@ -523,14 +523,14 @@ int nLimit = -1; int nSleep = 0; rc = lsm_config(pDb->db, LSM_CONFIG_AUTOFLUSH, &nLimit); do { - int bOld, nNew, rc; - rc = lsm_info(pDb->db, LSM_INFO_TREE_SIZE, &bOld, &nNew); + int nOld, nNew, rc; + rc = lsm_info(pDb->db, LSM_INFO_TREE_SIZE, &nOld, &nNew); if( rc!=LSM_OK ) return rc; - if( bOld==0 || nNew<(nLimit/2) ) break; + if( nOld==0 || nNew<(nLimit/2) ) break; usleep(5000); nSleep += 5; }while( 1 ); #if 0 @@ -1120,13 +1120,13 @@ /* Do some work. If an error occurs, exit. */ pthread_mutex_unlock(&p->worker_mutex); if( p->eType==LSMTEST_THREAD_CKPT ){ - int nByte = 0; - rc = lsm_info(pWorker, LSM_INFO_CHECKPOINT_SIZE, &nByte); - if( rc==LSM_OK && nByte>=p->pDb->nMtMinCkpt ){ + int nKB = 0; + rc = lsm_info(pWorker, LSM_INFO_CHECKPOINT_SIZE, &nKB); + if( rc==LSM_OK && nKB>=p->pDb->nMtMinCkpt ){ rc = lsm_checkpoint(pWorker, 0); } }else{ int nWrite; do { Index: src/lsm.h ================================================================== --- src/lsm.h +++ src/lsm.h @@ -394,11 +394,11 @@ ** free block in the database. The element itself consists of two ** integers - the block number and the id of the snapshot that freed it. ** ** LSM_INFO_CHECKPOINT_SIZE: ** The third argument should be of type (int *). The location pointed to -** by this argument is populated with the number of bytes written to the +** by this argument is populated with the number of KB written to the ** database file since the most recent checkpoint. ** ** LSM_INFO_TREE_SIZE: ** If this value is passed as the second argument to an lsm_info() call, it ** should be followed by two arguments of type (int *) (for a total of four @@ -411,11 +411,11 @@ ** accumulate new data written to the database. The other tree structure - ** the old tree - is a read-only tree holding older data and may be flushed ** to disk at any time. ** ** Assuming no error occurs, the location pointed to by the first of the two -** (int *) arguments is set to the size of the old in-memory tree in bytes. +** (int *) arguments is set to the size of the old in-memory tree in KB. ** The second is set to the size of the current, or live in-memory tree. */ #define LSM_INFO_NWRITE 1 #define LSM_INFO_NREAD 2 #define LSM_INFO_DB_STRUCTURE 3 @@ -498,17 +498,17 @@ /* ** Attempt to checkpoint the current database snapshot. Return an LSM ** error code if an error occurs or LSM_OK otherwise. ** ** If the current snapshot has already been checkpointed, calling this -** function is a no-op. In this case if pnByte is not NULL, *pnByte is +** function is a no-op. In this case if pnKB is not NULL, *pnKB is ** set to 0. Or, if the current snapshot is successfully checkpointed -** by this function and pbCkpt is not NULL, *pnByte is set to the number +** by this function and pbKB is not NULL, *pnKB is set to the number ** of bytes written to the database file since the previous checkpoint ** (the same measure as returned by the LSM_INFO_CHECKPOINT_SIZE query). */ -int lsm_checkpoint(lsm_db *pDb, int *pnByte); +int lsm_checkpoint(lsm_db *pDb, int *pnKB); /* ** CAPI: Opening and Closing Database Cursors ** ** Open and close a database cursor. Index: src/lsm_ckpt.c ================================================================== --- src/lsm_ckpt.c +++ src/lsm_ckpt.c @@ -1184,20 +1184,27 @@ memcpy(pDb->pShmhdr->aSnap1, pDb->aSnapshot, nCkpt*sizeof(u32)); memcpy(pDb->pShmhdr->aSnap2, pDb->aSnapshot, nCkpt*sizeof(u32)); } -int lsmCheckpointSize(lsm_db *db, int *pnByte){ +/* +** Set the output variable to the number of KB of data written into the +** database file since the most recent checkpoint. +*/ +int lsmCheckpointSize(lsm_db *db, int *pnKB){ ShmHeader *pShm = db->pShmhdr; int rc = LSM_OK; u32 nSynced; + /* Set nSynced to the number of pages that had been written when the + ** database was last checkpointed. */ rc = lsmCheckpointSynced(db, 0, 0, &nSynced); + if( rc==LSM_OK ){ u32 nPgsz = db->pShmhdr->aSnap1[CKPT_HDR_PGSZ]; u32 nWrite = db->pShmhdr->aSnap1[CKPT_HDR_NWRITE]; - *pnByte = (int)((nWrite - nSynced) * nPgsz); + *pnKB = (int)(( ((i64)(nWrite - nSynced) * nPgsz) + 1023) / 1024); } return rc; } Index: src/lsm_main.c ================================================================== --- src/lsm_main.c +++ src/lsm_main.c @@ -453,11 +453,11 @@ } static int infoFreelistSize(lsm_db *pDb, int *pnFree, int *pnWaiting){ } -static int infoTreeSize(lsm_db *db, int *pnOld, int *pnNew){ +static int infoTreeSize(lsm_db *db, int *pnOldKB, int *pnNewKB){ ShmHeader *pShm = db->pShmhdr; TreeHeader *p = &pShm->hdr1; /* The following code suffers from two race conditions, as it accesses and ** trusts the contents of shared memory without verifying checksums: @@ -476,19 +476,19 @@ ** ** Given the context in which this function is called (as a result of an ** lsm_info(LSM_INFO_TREE_SIZE) request), neither of these are considered to ** be problems. */ - *pnNew = (int)p->root.nByte; + *pnNewKB = ((int)p->root.nByte + 1023) / 1024; if( p->iOldShmid ){ if( p->iOldLog==lsmCheckpointLogOffset(pShm->aSnap1) ){ - *pnOld = 0; + *pnOldKB = 0; }else{ - *pnOld = (int)p->oldroot.nByte; + *pnOldKB = ((int)p->oldroot.nByte + 1023) / 1024; } }else{ - *pnOld = 0; + *pnOldKB = 0; } return LSM_OK; } @@ -555,12 +555,12 @@ rc = lsmInfoFreelist(pDb, pzVal); break; } case LSM_INFO_CHECKPOINT_SIZE: { - int *pnByte = va_arg(ap, int *); - rc = lsmCheckpointSize(pDb, pnByte); + int *pnKB = va_arg(ap, int *); + rc = lsmCheckpointSize(pDb, pnKB); break; } case LSM_INFO_TREE_SIZE: { int *pnOld = va_arg(ap, int *); Index: src/lsm_shared.c ================================================================== --- src/lsm_shared.c +++ src/lsm_shared.c @@ -1582,26 +1582,26 @@ void lsmShmBarrier(lsm_db *db){ lsmEnvShmBarrier(db->pEnv); } -int lsm_checkpoint(lsm_db *pDb, int *pnByte){ +int lsm_checkpoint(lsm_db *pDb, int *pnKB){ int rc; /* Return code */ u32 nWrite = 0; /* Number of pages checkpointed */ /* Attempt the checkpoint. If successful, nWrite is set to the number of ** pages written between this and the previous checkpoint. */ rc = lsmCheckpointWrite(pDb, 0, &nWrite); - /* If required, calculate the output variable (bytes of data checkpointed). + /* If required, calculate the output variable (KB of data checkpointed). ** Set it to zero if an error occured. */ - if( pnByte ){ - int nByte = 0; + if( pnKB ){ + int nKB = 0; if( rc==LSM_OK && nWrite ){ - nByte = (int)nWrite * lsmFsPageSize(pDb->pFS); + nKB = (((i64)nWrite * lsmFsPageSize(pDb->pFS)) + 1023) / 1024; } - *pnByte = nByte; + *pnKB = nKB; } return rc; }