Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| SHA1 Hash: | d4c5a3bad7edad16f7f06666e9c15ee59beffe53 |
|---|---|
| Date: | 2012-11-29 19:14:46 |
| User: | dan |
| Comment: | Avoid reading and checksumming an entire meta-page every time a write transaction is opened. |
Tags And Properties
- branch=trunk inherited from [84d5dea8fd]
- sym-trunk inherited from [84d5dea8fd]
Changes
Changes to src/lsmInt.h
704 int lsmEnvLock(lsm_env *pEnv, lsm_file *pFile, int iLock, int eLock); 704 int lsmEnvLock(lsm_env *pEnv, lsm_file *pFile, int iLock, int eLock); 705 705 706 int lsmEnvShmMap(lsm_env *, lsm_file *, int, int, void **); 706 int lsmEnvShmMap(lsm_env *, lsm_file *, int, int, void **); 707 void lsmEnvShmBarrier(lsm_env *); 707 void lsmEnvShmBarrier(lsm_env *); 708 void lsmEnvShmUnmap(lsm_env *, lsm_file *, int); 708 void lsmEnvShmUnmap(lsm_env *, lsm_file *, int); 709 709 710 void lsmEnvSleep(lsm_env *, int); 710 void lsmEnvSleep(lsm_env *, int); > 711 > 712 int lsmFsReadSyncedId(lsm_db *db, int, i64 *piVal); 711 713 712 /* 714 /* 713 ** End of functions from "lsm_file.c". 715 ** End of functions from "lsm_file.c". 714 **************************************************************************/ 716 **************************************************************************/ 715 717 716 /* 718 /* 717 ** Functions from file "lsm_sorted.c". 719 ** Functions from file "lsm_sorted.c".
Changes to src/lsm_file.c
1221 }else{ 1221 }else{ 1222 p->nData = pFS->nPagesize; 1222 p->nData = pFS->nPagesize; 1223 } 1223 } 1224 pFS->nOut += (p->nRef==0); 1224 pFS->nOut += (p->nRef==0); 1225 p->nRef++; 1225 p->nRef++; 1226 } 1226 } 1227 *ppPg = p; 1227 *ppPg = p; > 1228 return rc; > 1229 } > 1230 > 1231 /* > 1232 ** Read the 64-bit checkpoint id of the checkpoint currently stored on meta > 1233 ** page iMeta of the database file. If no error occurs, store the id value > 1234 ** in *piVal and return LSM_OK. Otherwise, return an LSM error code and leave > 1235 ** *piVal unmodified. > 1236 ** > 1237 ** If a checkpointer connection is currently updating meta-page iMeta, or an > 1238 ** earlier checkpointer crashed while doing so, the value read into *piVal > 1239 ** may be garbage. It is the callers responsibility to deal with this. > 1240 */ > 1241 int lsmFsReadSyncedId(lsm_db *db, int iMeta, i64 *piVal){ > 1242 FileSystem *pFS = db->pFS; > 1243 int rc = LSM_OK; > 1244 > 1245 assert( iMeta==1 || iMeta==2 ); > 1246 if( pFS->bUseMmap ){ > 1247 fsGrowMapping(pFS, iMeta*LSM_META_PAGE_SIZE, &rc); > 1248 if( rc==LSM_OK ){ > 1249 *piVal = (i64)lsmGetU64(&((u8 *)pFS->pMap)[(iMeta-1)*LSM_META_PAGE_SIZE]); > 1250 } > 1251 }else{ > 1252 MetaPage *pMeta = 0; > 1253 rc = lsmFsMetaPageGet(pFS, 0, iMeta, &pMeta); > 1254 if( rc==LSM_OK ){ > 1255 *piVal = (i64)lsmGetU64(pMeta->aData); > 1256 lsmFsMetaPageRelease(pMeta); > 1257 } > 1258 } > 1259 1228 return rc; 1260 return rc; 1229 } 1261 } 1230 1262 1231 1263 1232 static int fsRunEndsBetween( 1264 static int fsRunEndsBetween( 1233 Segment *pRun, 1265 Segment *pRun, 1234 Segment *pIgnore, 1266 Segment *pIgnore,
Changes to src/lsm_log.c
298 /* 298 /* 299 ** If possible, reclaim log file space. Log file space is reclaimed after 299 ** If possible, reclaim log file space. Log file space is reclaimed after 300 ** a snapshot that points to the same data in the database file is synced 300 ** a snapshot that points to the same data in the database file is synced 301 ** into the db header. 301 ** into the db header. 302 */ 302 */ 303 static int logReclaimSpace(lsm_db *pDb){ 303 static int logReclaimSpace(lsm_db *pDb){ 304 int rc = LSM_OK; 304 int rc = LSM_OK; > 305 int iMeta; > 306 305 if( pDb->pShmhdr->iMetaPage ){ | 307 iMeta = (int)pDb->pShmhdr->iMetaPage; > 308 if( iMeta==1 || iMeta==2 ){ 306 DbLog *pLog = &pDb->treehdr.log; 309 DbLog *pLog = &pDb->treehdr.log; > 310 i64 iSyncedId; > 311 > 312 /* Read the snapshot-id of the snapshot stored on meta-page iMeta. Note > 313 ** that in theory, the value read is untrustworthy (due to a race > 314 ** condition - see comments above lsmFsReadSyncedId()). So it is only > 315 ** ever used to conclude that no log space can be reclaimed. If it seems > 316 ** to indicate that it may be possible to reclaim log space, a > 317 ** second call to lsmCheckpointSynced() (which does return trustworthy > 318 ** values) is made below to confirm. */ > 319 rc = lsmFsReadSyncedId(pDb, iMeta, &iSyncedId); > 320 > 321 if( rc==LSM_OK && pLog->iSnapshotId!=iSyncedId ){ 307 i64 iSnapshotId = 0; | 322 i64 iSnapshotId = 0; 308 i64 iOff = 0; | 323 i64 iOff = 0; 309 rc = lsmCheckpointSynced(pDb, &iSnapshotId, &iOff, 0); | 324 rc = lsmCheckpointSynced(pDb, &iSnapshotId, &iOff, 0); 310 if( rc==LSM_OK && pLog->iSnapshotId<iSnapshotId ){ | 325 if( rc==LSM_OK && pLog->iSnapshotId<iSnapshotId ){ 311 int iRegion; | 326 int iRegion; 312 for(iRegion=0; iRegion<3; iRegion++){ | 327 for(iRegion=0; iRegion<3; iRegion++){ 313 LogRegion *p = &pLog->aRegion[iRegion]; | 328 LogRegion *p = &pLog->aRegion[iRegion]; 314 if( iOff>=p->iStart && iOff<=p->iEnd ) break; | 329 if( iOff>=p->iStart && iOff<=p->iEnd ) break; 315 p->iStart = 0; | 330 p->iStart = 0; 316 p->iEnd = 0; | 331 p->iEnd = 0; 317 } | 332 } 318 assert( iRegion<3 ); | 333 assert( iRegion<3 ); 319 pLog->aRegion[iRegion].iStart = iOff; | 334 pLog->aRegion[iRegion].iStart = iOff; 320 pLog->iSnapshotId = iSnapshotId; | 335 pLog->iSnapshotId = iSnapshotId; > 336 } 321 } 337 } 322 } 338 } 323 return rc; 339 return rc; 324 } 340 } 325 341 326 /* 342 /* 327 ** This function is called when a write-transaction is first opened. It 343 ** This function is called when a write-transaction is first opened. It
Changes to src/lsm_sorted.c
338 u32 lsmGetU32(u8 *aOut){ 338 u32 lsmGetU32(u8 *aOut){ 339 return ((u32)aOut[0] << 24) 339 return ((u32)aOut[0] << 24) 340 + ((u32)aOut[1] << 16) 340 + ((u32)aOut[1] << 16) 341 + ((u32)aOut[2] << 8) 341 + ((u32)aOut[2] << 8) 342 + ((u32)aOut[3]); 342 + ((u32)aOut[3]); 343 } 343 } 344 344 345 u32 lsmGetU64(u8 *aOut){ | 345 u64 lsmGetU64(u8 *aOut){ 346 return ((u64)aOut[0] << 56) 346 return ((u64)aOut[0] << 56) 347 + ((u64)aOut[1] << 48) 347 + ((u64)aOut[1] << 48) 348 + ((u64)aOut[2] << 40) 348 + ((u64)aOut[2] << 40) 349 + ((u64)aOut[3] << 32) 349 + ((u64)aOut[3] << 32) 350 + ((u64)aOut[4] << 24) 350 + ((u64)aOut[4] << 24) 351 + ((u32)aOut[5] << 16) 351 + ((u32)aOut[5] << 16) 352 + ((u32)aOut[6] << 8) 352 + ((u32)aOut[6] << 8)