Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix LSM_INFO_PAGE_DUMP so that it works with redirected blocks. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | block-redirects |
Files: | files | file ages | folders |
SHA1: |
deb0ccacd4949085c293b2f76965be48 |
User & Date: | dan 2013-01-21 14:23:44.739 |
Context
2013-01-21
| ||
16:53 | If a free-list-only segment is generated while a merge of the top-level segment is underway, add the new segment to the merge inputs immediately. Also, if auto-checkpoints are enabled, schedule a checkpoint after each block is moved within an lsm_work(nmerge=1) call. check-in: 89b4286682 user: dan tags: block-redirects | |
14:23 | Fix LSM_INFO_PAGE_DUMP so that it works with redirected blocks. check-in: deb0ccacd4 user: dan tags: block-redirects | |
10:02 | Fix some bugs surrounding block redirects. check-in: 73976dbcbe user: dan tags: block-redirects | |
Changes
Changes to src/lsmInt.h.
︙ | ︙ | |||
718 719 720 721 722 723 724 725 726 727 728 729 730 731 | int lsmEnvShmMap(lsm_env *, lsm_file *, int, int, void **); void lsmEnvShmBarrier(lsm_env *); void lsmEnvShmUnmap(lsm_env *, lsm_file *, int); void lsmEnvSleep(lsm_env *, int); int lsmFsReadSyncedId(lsm_db *db, int, i64 *piVal); /* ** End of functions from "lsm_file.c". **************************************************************************/ /* ** Functions from file "lsm_sorted.c". | > > | 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | int lsmEnvShmMap(lsm_env *, lsm_file *, int, int, void **); void lsmEnvShmBarrier(lsm_env *); void lsmEnvShmUnmap(lsm_env *, lsm_file *, int); void lsmEnvSleep(lsm_env *, int); int lsmFsReadSyncedId(lsm_db *db, int, i64 *piVal); int lsmFsSegmentContainsPg(FileSystem *pFS, Segment *, Pgno, int *); /* ** End of functions from "lsm_file.c". **************************************************************************/ /* ** Functions from file "lsm_sorted.c". |
︙ | ︙ |
Changes to src/lsm_file.c.
︙ | ︙ | |||
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 | assert( (*ppNext==0)==(rc!=LSM_OK || nSpace>0) ); }else{ *ppNext = 0; } }while( nSpace>0 && rc==LSM_OK ); }else{ assert( eDir==1 || eDir==-1 ); if( eDir<0 ){ if( pRun && iPg==pRun->iFirst ){ *ppNext = 0; return LSM_OK; }else if( fsIsFirst(pFS, iPg) ){ assert( pPg->flags & PAGE_HASPREV ); iPg = fsLastPageOnBlock(pFS, lsmGetU32(&pPg->aData[-4])); }else{ iPg--; } }else{ | > > | | | | > > > | | | | 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 | assert( (*ppNext==0)==(rc!=LSM_OK || nSpace>0) ); }else{ *ppNext = 0; } }while( nSpace>0 && rc==LSM_OK ); }else{ Redirect *pRedir = pRun ? pRun->pRedirect : 0; assert( eDir==1 || eDir==-1 ); if( eDir<0 ){ if( pRun && iPg==pRun->iFirst ){ *ppNext = 0; return LSM_OK; }else if( fsIsFirst(pFS, iPg) ){ assert( pPg->flags & PAGE_HASPREV ); iPg = fsLastPageOnBlock(pFS, lsmGetU32(&pPg->aData[-4])); }else{ iPg--; } }else{ if( pRun ){ Pgno iLast = fsRedirectPage(pFS, pRedir, pRun->iLastPg); if( iPg==iLast ){ *ppNext = 0; return LSM_OK; } } if( fsIsLast(pFS, iPg) ){ int iBlk = fsRedirectBlock( pRedir, lsmGetU32(&pPg->aData[pFS->nPagesize-4]) ); iPg = fsFirstPageOnBlock(pFS, iBlk); }else{ iPg++; } } rc = fsPageGet(pFS, pRedir, iPg, 0, ppNext, 0); } return rc; } static Pgno findAppendPoint(FileSystem *pFS, Level *pLvl){ int i; |
︙ | ︙ | |||
1788 1789 1790 1791 1792 1793 1794 | } /* ** Obtain a reference to page number iPg. */ int lsmFsDbPageGet(FileSystem *pFS, Segment *pSeg, Pgno iPg, Page **ppPg){ assert( pFS ); | < | | 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 | } /* ** Obtain a reference to page number iPg. */ int lsmFsDbPageGet(FileSystem *pFS, Segment *pSeg, Pgno iPg, Page **ppPg){ assert( pFS ); return fsPageGet(pFS, (pSeg ? pSeg->pRedirect : 0), iPg, 0, ppPg, 0); } /* ** Obtain a reference to the last page in the segment passed as the ** second argument. */ int lsmFsDbPageLast(FileSystem *pFS, Segment *pSeg, Page **ppPg){ |
︙ | ︙ | |||
2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 | if( bUnlock ){ int rcwork = LSM_BUSY; lsmFinishWork(pDb, 0, &rcwork); } return rc; } /* ** This function implements the lsm_info(LSM_INFO_ARRAY_PAGES) request. ** If successful, *pzOut is set to point to a nul-terminated string ** containing the array structure and LSM_OK is returned. The caller should ** eventually free the string using lsmFree(). ** | > > > > > > > > > > > > > > > > > > > > > > > > | 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 | if( bUnlock ){ int rcwork = LSM_BUSY; lsmFinishWork(pDb, 0, &rcwork); } return rc; } int lsmFsSegmentContainsPg( FileSystem *pFS, Segment *pSeg, Pgno iPg, int *pbRes ){ Redirect *pRedir = pSeg->pRedirect; int rc = LSM_OK; int iBlk; int iLastBlk; int iPgBlock; /* Block containing page iPg */ iPgBlock = fsPageToBlock(pFS, pSeg->iFirst); iBlk = fsRedirectBlock(pRedir, fsPageToBlock(pFS, pSeg->iFirst)); iLastBlk = fsRedirectBlock(pRedir, fsPageToBlock(pFS, pSeg->iLastPg)); while( iBlk!=iLastBlk && iBlk!=iPgBlock && rc==LSM_OK ){ rc = fsBlockNext(pFS, pSeg, iBlk, &iBlk); } *pbRes = (iBlk==iPgBlock); return rc; } /* ** This function implements the lsm_info(LSM_INFO_ARRAY_PAGES) request. ** If successful, *pzOut is set to point to a nul-terminated string ** containing the array structure and LSM_OK is returned. The caller should ** eventually free the string using lsmFree(). ** |
︙ | ︙ |
Changes to src/lsm_main.c.
︙ | ︙ | |||
371 372 373 374 375 376 377 | assert( *pbUnlock==0 ); if( !pDb->pWorker ){ rc = lsmBeginWork(pDb); if( rc!=LSM_OK ) return rc; *pbUnlock = 1; } | | | 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | assert( *pbUnlock==0 ); if( !pDb->pWorker ){ rc = lsmBeginWork(pDb); if( rc!=LSM_OK ) return rc; *pbUnlock = 1; } if( pp ) *pp = pDb->pWorker; return rc; } static void infoFreeWorker(lsm_db *pDb, int bUnlock){ if( bUnlock ){ int rcdummy = LSM_BUSY; lsmFinishWork(pDb, 0, &rcdummy); |
︙ | ︙ | |||
529 530 531 532 533 534 535 | break; } case LSM_INFO_PAGE_HEX_DUMP: case LSM_INFO_PAGE_ASCII_DUMP: { Pgno pgno = va_arg(ap, Pgno); char **pzVal = va_arg(ap, char **); | > > > > | > > | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | break; } case LSM_INFO_PAGE_HEX_DUMP: case LSM_INFO_PAGE_ASCII_DUMP: { Pgno pgno = va_arg(ap, Pgno); char **pzVal = va_arg(ap, char **); int bUnlock = 0; rc = infoGetWorker(pDb, 0, &bUnlock); if( rc==LSM_OK ){ int bHex = (eParam==LSM_INFO_PAGE_HEX_DUMP); rc = lsmInfoPageDump(pDb, pgno, bHex, pzVal); } infoFreeWorker(pDb, bUnlock); break; } case LSM_INFO_LOG_STRUCTURE: { char **pzVal = va_arg(ap, char **); rc = lsmInfoLogStructure(pDb, pzVal); break; |
︙ | ︙ |
Changes to src/lsm_sorted.c.
︙ | ︙ | |||
5177 5178 5179 5180 5181 5182 5183 | lsmLogMessage(pDb, LSM_OK, " Page %d: %s", lsmFsPageNumber(pPg), s.z); lsmStringClear(&s); sortedBlobFree(&blob); } static void infoCellDump( | | > < | | | < | 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 | lsmLogMessage(pDb, LSM_OK, " Page %d: %s", lsmFsPageNumber(pPg), s.z); lsmStringClear(&s); sortedBlobFree(&blob); } static void infoCellDump( lsm_db *pDb, /* Database handle */ Segment *pSeg, /* Segment page belongs to */ int bIndirect, /* True to follow indirect refs */ Page *pPg, int iCell, int *peType, int *piPgPtr, u8 **paKey, int *pnKey, u8 **paVal, int *pnVal, Blob *pBlob ){ u8 *aData; int nData; /* Page data */ u8 *aKey; int nKey = 0; /* Key */ u8 *aVal; int nVal = 0; /* Value */ int eType; int iPgPtr; Page *pRef = 0; /* Pointer to page iRef */ u8 *aCell; aData = fsPageData(pPg, &nData); aCell = pageGetCell(aData, nData, iCell); eType = *aCell++; aCell += lsmVarintGet32(aCell, &iPgPtr); if( eType==0 ){ int dummy; Pgno iRef; /* Page number of referenced page */ aCell += lsmVarintGet64(aCell, &iRef); if( bIndirect ){ lsmFsDbPageGet(pDb->pFS, pSeg, iRef, &pRef); pageGetKeyCopy(pDb->pEnv, pSeg, pRef, 0, &dummy, pBlob); aKey = (u8 *)pBlob->pData; nKey = pBlob->nData; lsmFsPageRelease(pRef); }else{ aKey = (u8 *)"<indirect>"; nKey = 11; } }else{ aCell += lsmVarintGet32(aCell, &nKey); if( rtIsWrite(eType) ) aCell += lsmVarintGet32(aCell, &nVal); sortedReadData(pSeg, pPg, (aCell-aData), nKey+nVal, (void **)&aKey, pBlob); aVal = &aKey[nKey]; } if( peType ) *peType = eType; if( piPgPtr ) *piPgPtr = iPgPtr; if( paKey ) *paKey = aKey; if( paVal ) *paVal = aVal; if( pnKey ) *pnKey = nKey; if( pnVal ) *pnVal = nVal; } static int infoAppendBlob(LsmString *pStr, int bHex, u8 *z, int n){ int iChar; for(iChar=0; iChar<n; iChar++){ if( bHex ){ lsmStringAppendf(pStr, "%02X", z[iChar]); |
︙ | ︙ | |||
5256 5257 5258 5259 5260 5261 5262 | static int infoPageDump( lsm_db *pDb, /* Database handle */ Pgno iPg, /* Page number of page to dump */ int flags, char **pzOut /* OUT: lsmMalloc'd string */ ){ int rc = LSM_OK; /* Return code */ | < > > > > > > > > > > > > > > > > > > > > | > > | 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 | static int infoPageDump( lsm_db *pDb, /* Database handle */ Pgno iPg, /* Page number of page to dump */ int flags, char **pzOut /* OUT: lsmMalloc'd string */ ){ int rc = LSM_OK; /* Return code */ Page *pPg = 0; /* Handle for page iPg */ int i, j; /* Loop counters */ const int perLine = 16; /* Bytes per line in the raw hex dump */ Segment *pSeg = 0; Snapshot *pSnap; int bValues = (flags & INFO_PAGE_DUMP_VALUES); int bHex = (flags & INFO_PAGE_DUMP_HEX); int bData = (flags & INFO_PAGE_DUMP_DATA); int bIndirect = (flags & INFO_PAGE_DUMP_INDIRECT); *pzOut = 0; if( iPg==0 ) return LSM_ERROR; assert( pDb->pClient || pDb->pWorker ); pSnap = pDb->pClient; if( pSnap==0 ) pSnap = pDb->pWorker; if( pSnap->redirect.n>0 ){ Level *pLvl; int bUse = 0; for(pLvl=pSnap->pLevel; pLvl->pNext; pLvl=pLvl->pNext); pSeg = (pLvl->nRight==0 ? &pLvl->lhs : &pLvl->aRhs[pLvl->nRight-1]); rc = lsmFsSegmentContainsPg(pDb->pFS, pSeg, iPg, &bUse); if( bUse==0 ){ pSeg = 0; } } /* iPg is a real page number (not subject to redirection). So it is safe ** to pass a NULL in place of the segment pointer as the second argument ** to lsmFsDbPageGet() here. */ if( rc==LSM_OK ){ rc = lsmFsDbPageGet(pDb->pFS, 0, iPg, &pPg); } if( rc==LSM_OK ){ Blob blob = {0, 0, 0, 0}; int nKeyWidth = 0; LsmString str; int nRec; int iPtr; int flags; |
︙ | ︙ | |||
5294 5295 5296 5297 5298 5299 5300 | lsmStringAppendf(&str, "nRec : %d\n", nRec); lsmStringAppendf(&str, "iPtr : %d\n", iPtr); lsmStringAppendf(&str, "flags: %04x\n", flags); lsmStringAppendf(&str, "\n"); for(iCell=0; iCell<nRec; iCell++){ int nKey; | > | > < | | 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 | lsmStringAppendf(&str, "nRec : %d\n", nRec); lsmStringAppendf(&str, "iPtr : %d\n", iPtr); lsmStringAppendf(&str, "flags: %04x\n", flags); lsmStringAppendf(&str, "\n"); for(iCell=0; iCell<nRec; iCell++){ int nKey; infoCellDump( pDb, pSeg, bIndirect, pPg, iCell, 0, 0, 0, &nKey, 0, 0, &blob ); if( nKey>nKeyWidth ) nKeyWidth = nKey; } if( bHex ) nKeyWidth = nKeyWidth * 2; for(iCell=0; iCell<nRec; iCell++){ u8 *aKey; int nKey = 0; /* Key */ u8 *aVal; int nVal = 0; /* Value */ int iPgPtr; int eType; Pgno iAbsPtr; char zFlags[8]; infoCellDump(pDb, pSeg, bIndirect, pPg, iCell, &eType, &iPgPtr, &aKey, &nKey, &aVal, &nVal, &blob ); iAbsPtr = iPgPtr + ((flags & SEGMENT_BTREE_FLAG) ? 0 : iPtr); lsmFlagsToString(eType, zFlags); lsmStringAppendf(&str, "%s %d (%s) ", zFlags, iAbsPtr, (rtTopic(eType) ? "sys" : "usr") |
︙ | ︙ | |||
5366 5367 5368 5369 5370 5371 5372 | } *pzOut = str.z; sortedBlobFree(&blob); lsmFsPageRelease(pPg); } | < | 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 | } *pzOut = str.z; sortedBlobFree(&blob); lsmFsPageRelease(pPg); } return rc; } int lsmInfoPageDump( lsm_db *pDb, /* Database handle */ Pgno iPg, /* Page number of page to dump */ int bHex, /* True to output key/value in hex form */ |
︙ | ︙ |