use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO in project ignite by apache.
the class BPlusTree method treeMeta.
/**
* @param metaPageAddr Meta page address. If equals {@code 0}, it means that we should do read lock on
* meta page and get meta page address. Otherwise we will not do the lock and will use the given address.
* @return Tree meta data.
* @throws IgniteCheckedException If failed.
*/
private TreeMetaData treeMeta(final long metaPageAddr) throws IgniteCheckedException {
TreeMetaData meta0 = treeMeta;
if (meta0 != null)
return meta0;
final long metaPage = acquirePage(metaPageId);
try {
long pageAddr;
if (metaPageAddr == 0L) {
pageAddr = readLock(metaPageId, metaPage);
assert pageAddr != 0 : "Failed to read lock meta page [metaPageId=" + U.hexLong(metaPageId) + ']';
} else
pageAddr = metaPageAddr;
try {
BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(pageAddr);
int rootLvl = io.getRootLevel(pageAddr);
long rootId = io.getFirstPageId(pageAddr, rootLvl);
treeMeta = meta0 = new TreeMetaData(rootLvl, rootId);
} finally {
if (metaPageAddr == 0L)
readUnlock(metaPageId, metaPage, pageAddr);
}
} finally {
releasePage(metaPageId, metaPage);
}
return meta0;
}
use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO in project ignite by apache.
the class BPlusTree method treeMeta.
/**
* @return Tree meta data.
* @throws IgniteCheckedException If failed.
*/
private TreeMetaData treeMeta() throws IgniteCheckedException {
TreeMetaData meta0 = treeMeta;
if (meta0 != null)
return meta0;
final long metaPage = acquirePage(metaPageId);
try {
// Meta can't be removed.
long pageAddr = readLock(metaPageId, metaPage);
assert pageAddr != 0 : "Failed to read lock meta page [metaPageId=" + U.hexLong(metaPageId) + ']';
try {
BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(pageAddr);
int rootLvl = io.getRootLevel(pageAddr);
long rootId = io.getFirstPageId(pageAddr, rootLvl);
treeMeta = meta0 = new TreeMetaData(rootLvl, rootId);
} finally {
readUnlock(metaPageId, metaPage, pageAddr);
}
} finally {
releasePage(metaPageId, metaPage);
}
return meta0;
}
use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO in project ignite by apache.
the class BPlusTree method getFirstPageIds.
/**
* @param pageAddr Meta page address.
* @return First page IDs.
*/
protected Iterable<Long> getFirstPageIds(long pageAddr) {
List<Long> res = new ArrayList<>();
BPlusMetaIO mio = BPlusMetaIO.VERSIONS.forPage(pageAddr);
for (int lvl = mio.getRootLevel(pageAddr); lvl >= 0; lvl--) res.add(mio.getFirstPageId(pageAddr, lvl));
return res;
}
use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO in project ignite by apache.
the class MetaPageCutRootRecord method applyDelta.
/**
* {@inheritDoc}
*/
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
BPlusMetaIO io = BPlusMetaIO.VERSIONS.forPage(pageAddr);
io.cutRoot(pageAddr, pageMem.realPageSize(groupId()));
}
use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO in project ignite by apache.
the class IgniteIndexReader method readIdx.
/**
* Read index file.
*/
public void readIdx() {
long partPageStoresNum = Arrays.stream(partStores).filter(Objects::nonNull).count();
print("Partitions files num: " + partPageStoresNum);
Map<Class, Long> pageClasses = new HashMap<>();
long pagesNum = isNull(idxStore) ? 0 : (idxStore.size() - idxStore.headerSize()) / pageSize;
print("Going to check " + pagesNum + " pages.");
Set<Long> pageIds = new HashSet<>();
AtomicReference<Map<String, TreeTraversalInfo>> treeInfo = new AtomicReference<>();
AtomicReference<Map<String, TreeTraversalInfo>> horizontalScans = new AtomicReference<>();
AtomicReference<PageListsInfo> pageListsInfo = new AtomicReference<>();
List<Throwable> errors;
try {
IgniteBiTuple<Long, Long> indexPartitionRoots = partitionRoots(partMetaPageId(INDEX_PARTITION, FLAG_IDX));
long metaTreeRootId = indexPartitionRoots.get1();
long pageListMetaPageId = indexPartitionRoots.get2();
// Traversing trees.
treeInfo.set(traverseAllTrees("Index trees traversal", metaTreeRootId, CountOnlyStorage::new, this::traverseTree));
treeInfo.get().forEach((name, info) -> {
pageIds.addAll(info.innerPageIds);
pageIds.add(info.rootPageId);
});
Supplier<ItemStorage> itemStorageFactory = checkParts ? LinkStorage::new : CountOnlyStorage::new;
horizontalScans.set(traverseAllTrees("Scan index trees horizontally", metaTreeRootId, itemStorageFactory, this::horizontalTreeScan));
// Scanning page reuse lists.
if (pageListMetaPageId != 0)
pageListsInfo.set(getPageListsInfo(pageListMetaPageId));
ProgressPrinter progressPrinter = new ProgressPrinter(System.out, "Reading pages sequentially", pagesNum);
// Scan all pages in file.
errors = scanFileStore(INDEX_PARTITION, FLAG_IDX, idxStore, (pageId, addr, io) -> {
progressPrinter.printProgress();
pageClasses.compute(io.getClass(), (k, v) -> v == null ? 1 : v + 1);
if (!(io instanceof PageMetaIO || io instanceof PagesListMetaIO)) {
if (idxFilter == null) {
if ((io instanceof BPlusMetaIO || io instanceof BPlusInnerIO) && !pageIds.contains(pageId) && pageListsInfo.get() != null && !pageListsInfo.get().allPages.contains(pageId)) {
throw new IgniteException("Possibly orphan " + io.getClass().getSimpleName() + " page, pageId=" + pageId);
}
}
}
return true;
});
} catch (IgniteCheckedException e) {
throw new IgniteException(INDEX_FILE_NAME + " scan problem", e);
}
if (treeInfo.get() == null)
printErr("No tree meta info found.");
else {
printTraversalResults(RECURSIVE_TRAVERSE_NAME, treeInfo.get());
printTraversalResults(HORIZONTAL_SCAN_NAME, horizontalScans.get());
}
compareTraversals(treeInfo.get(), horizontalScans.get());
if (pageListsInfo.get() == null)
printErr("No page lists meta info found.");
else
printPagesListsInfo(pageListsInfo.get());
printPageStat("", "\n---These pages types were encountered during sequential scan:", pageClasses);
if (!errors.isEmpty()) {
printErr("---");
printErr("Errors:");
errors.forEach(this::printStackTrace);
}
print("---");
print("Total pages encountered during sequential scan: " + pageClasses.values().stream().mapToLong(a -> a).sum());
print("Total errors occurred during sequential scan: " + errors.size());
if (idxFilter != null)
print("Orphan pages were not reported due to --indexes filter.");
print("Note that some pages can be occupied by meta info, tracking info, etc., so total page count can differ " + "from count of pages found in index trees and page lists.");
if (checkParts) {
Map<Integer, List<Throwable>> checkPartsErrors = checkParts(horizontalScans.get());
print("");
printErrors("", "Partitions check:", "Partitions check detected no errors.", "Errors detected in partition, partId=%s", false, checkPartsErrors);
print("\nPartition check finished, total errors: " + checkPartsErrors.values().stream().mapToInt(List::size).sum() + ", total problem partitions: " + checkPartsErrors.size());
}
}
Aggregations