use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO in project ignite by apache.
the class DefragIndexFactory method createIndexSegment.
/**
* {@inheritDoc}
*/
@Override
protected InlineIndexTree createIndexSegment(GridCacheContext<?, ?> cctx, SortedIndexDefinition def, RootPage rootPage, IoStatisticsHolder stats, InlineRecommender recommender, int segmentNum) throws Exception {
InlineIndexTree tree = new InlineIndexTree(def, cctx.group(), def.treeName(), offheap, offheap.reuseListForIndex(def.treeName()), newCachePageMemory, // Use old row handler to have access to inline index key types.
pageIoResolver(), rootPage.pageId().pageId(), rootPage.isAllocated(), oldIdx.inlineSize(), cctx.config().getSqlIndexMaxInlineSize(), def.keyTypeSettings(), null, stats, rowHndFactory, null);
final MetaPageInfo oldInfo = oldIdx.segment(segmentNum).metaInfo();
// Set IO wrappers for the new tree.
BPlusInnerIO<IndexRow> innerIO = (BPlusInnerIO<IndexRow>) wrap(tree.latestInnerIO(), tree.rowHandler());
BPlusLeafIO<IndexRow> leafIo = (BPlusLeafIO<IndexRow>) wrap(tree.latestLeafIO(), tree.rowHandler());
tree.setIos(new IOVersions<>(innerIO), new IOVersions<>(leafIo));
tree.copyMetaInfo(oldInfo);
tree.enableSequentialWriteMode();
return tree;
}
use of org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO in project ignite by apache.
the class IgniteIndexReader method horizontalTreeScan.
/**
* Traverse single index tree by each level horizontally.
*
* @param rootPageId Root page id.
* @param treeName Tree name.
* @param itemStorage Items storage.
* @return Tree traversal info.
*/
private TreeTraversalInfo horizontalTreeScan(long rootPageId, String treeName, ItemStorage itemStorage) {
FilePageStore store = filePageStore(partId(rootPageId));
Map<Long, List<Throwable>> errors = new HashMap<>();
Map<Class, Long> ioStat = new HashMap<>();
TreeTraverseContext treeCtx = new TreeTraverseContext(treeName, store, ioStat, errors, null, null, null);
ByteBuffer buf = allocateBuffer(pageSize);
try {
long addr = bufferAddress(buf);
readPage(store, rootPageId, buf);
PageIO pageIO = PageIO.getPageIO(addr);
if (!(pageIO instanceof BPlusMetaIO))
throw new IgniteException("Root page is not meta, pageId=" + rootPageId);
BPlusMetaIO metaIO = (BPlusMetaIO) pageIO;
ioStat.compute(metaIO.getClass(), (k, v) -> v == null ? 1 : v + 1);
int lvlsCnt = metaIO.getLevelsCount(addr);
long[] firstPageIds = IntStream.range(0, lvlsCnt).mapToLong(i -> metaIO.getFirstPageId(addr, i)).toArray();
for (int i = 0; i < lvlsCnt; i++) {
long pageId = firstPageIds[i];
while (pageId > 0) {
try {
buf.rewind();
readPage(store, pageId, buf);
pageIO = PageIO.getPageIO(addr);
if (i == 0 && !(pageIO instanceof BPlusLeafIO))
throw new IgniteException("Not-leaf page found on leaf level, pageId=" + pageId + ", level=" + i);
if (!(pageIO instanceof BPlusIO))
throw new IgniteException("Not-BPlus page found, pageId=" + pageId + ", level=" + i);
ioStat.compute(pageIO.getClass(), (k, v) -> v == null ? 1 : v + 1);
if (pageIO instanceof BPlusLeafIO) {
PageIOProcessor ioProcessor = getIOProcessor(pageIO);
PageContent pageContent = ioProcessor.getContent(pageIO, addr, pageId, treeCtx);
pageContent.items.forEach(itemStorage::add);
}
pageId = ((BPlusIO) pageIO).getForward(addr);
} catch (Throwable e) {
errors.computeIfAbsent(pageId, k -> new LinkedList<>()).add(e);
pageId = 0;
}
}
}
} catch (Throwable e) {
errors.computeIfAbsent(rootPageId, k -> new LinkedList<>()).add(e);
} finally {
freeBuffer(buf);
}
return new TreeTraversalInfo(ioStat, errors, null, rootPageId, itemStorage);
}
Aggregations