Search in sources :

Example 1 with BPlusLeafIO

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;
}
Also used : IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) InlineIndexTree(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree) BPlusInnerIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO) BPlusLeafIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO) MetaPageInfo(org.apache.ignite.internal.cache.query.index.sorted.MetaPageInfo)

Example 2 with BPlusLeafIO

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);
}
Also used : Arrays(java.util.Arrays) PAGE_SIZE(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.PAGE_SIZE) PART_CNT(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.PART_CNT) IgnitePair(org.apache.ignite.internal.util.lang.IgnitePair) MvccInnerIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.MvccInnerIO) Collections.singletonList(java.util.Collections.singletonList) Matcher(java.util.regex.Matcher) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) Arrays.asList(java.util.Arrays.asList) PageIdUtils.itemId(org.apache.ignite.internal.pagemem.PageIdUtils.itemId) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) Objects.isNull(java.util.Objects.isNull) GridStringBuilder(org.apache.ignite.internal.util.GridStringBuilder) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) CLIArgument.optionalArg(org.apache.ignite.internal.commandline.argument.parser.CLIArgument.optionalArg) StringBuilderOutputStream(org.apache.ignite.internal.commandline.StringBuilderOutputStream) Collectors.joining(java.util.stream.Collectors.joining) PageIO.getType(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getType) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) GridUnsafe.allocateBuffer(org.apache.ignite.internal.util.GridUnsafe.allocateBuffer) CLIArgument.mandatoryArg(org.apache.ignite.internal.commandline.argument.parser.CLIArgument.mandatoryArg) PageIdUtils(org.apache.ignite.internal.pagemem.PageIdUtils) PageIdUtils.pageIndex(org.apache.ignite.internal.pagemem.PageIdUtils.pageIndex) Supplier(java.util.function.Supplier) PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) PageIO.getVersion(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getVersion) PagesListMetaIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO) AbstractInlineInnerIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.AbstractInlineInnerIO) PageIdUtils.partId(org.apache.ignite.internal.pagemem.PageIdUtils.partId) LongStream(java.util.stream.LongStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) InnerIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.InnerIO) File(java.io.File) BPlusMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO) AtomicLong(java.util.concurrent.atomic.AtomicLong) PageIdUtils.flag(org.apache.ignite.internal.pagemem.PageIdUtils.flag) PageIdUtils.pageId(org.apache.ignite.internal.pagemem.PageIdUtils.pageId) StorageException(org.apache.ignite.internal.processors.cache.persistence.StorageException) FLAG_DATA(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_DATA) MvccLeafIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.MvccLeafIO) ByteBuffer(java.nio.ByteBuffer) GridLongList(org.apache.ignite.internal.util.GridLongList) PAGE_STORE_VER(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.PAGE_STORE_VER) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MvccDataLeafIO(org.apache.ignite.internal.processors.cache.tree.mvcc.data.MvccDataLeafIO) INDEXES(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.INDEXES) PendingRowIO(org.apache.ignite.internal.processors.cache.tree.PendingRowIO) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) BPlusLeafIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO) Predicate(java.util.function.Predicate) IgniteException(org.apache.ignite.IgniteException) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) DEST_FILE(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.DEST_FILE) String.format(java.lang.String.format) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) GridUnsafe.freeBuffer(org.apache.ignite.internal.util.GridUnsafe.freeBuffer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Pattern(java.util.regex.Pattern) AbstractInlineLeafIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.AbstractInlineLeafIO) CLIArgumentParser(org.apache.ignite.internal.commandline.argument.parser.CLIArgumentParser) Objects.nonNull(java.util.Objects.nonNull) InlineIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.InlineIO) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) IntStream(java.util.stream.IntStream) ProgressPrinter(org.apache.ignite.internal.commandline.ProgressPrinter) DataPagePayload(org.apache.ignite.internal.processors.cache.persistence.tree.io.DataPagePayload) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) IndexStorageImpl(org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl) GridUnsafe.bufferAddress(org.apache.ignite.internal.util.GridUnsafe.bufferAddress) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) DIR(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.DIR) LinkedList(java.util.LinkedList) AbstractDataLeafIO(org.apache.ignite.internal.processors.cache.tree.AbstractDataLeafIO) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RowLinkIO(org.apache.ignite.internal.processors.cache.tree.RowLinkIO) F(org.apache.ignite.internal.util.typedef.F) BPlusIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO) GridClosure3(org.apache.ignite.internal.util.lang.GridClosure3) Integer.parseInt(java.lang.Integer.parseInt) AbstractDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO) BPlusInnerIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO) LeafIO(org.apache.ignite.internal.cache.query.index.sorted.inline.io.LeafIO) CLIArgument(org.apache.ignite.internal.commandline.argument.parser.CLIArgument) Collectors.toList(java.util.stream.Collectors.toList) INDEX_FILE_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.INDEX_FILE_NAME) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) CHECK_PARTS(org.apache.ignite.internal.commandline.indexreader.IgniteIndexReader.Args.CHECK_PARTS) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BPlusIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) BPlusLeafIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO) ByteBuffer(java.nio.ByteBuffer) BPlusMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO) IgniteException(org.apache.ignite.IgniteException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) GridLongList(org.apache.ignite.internal.util.GridLongList) List(java.util.List) LinkedList(java.util.LinkedList) Collectors.toList(java.util.stream.Collectors.toList) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) AbstractDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Integer.parseInt (java.lang.Integer.parseInt)1 String.format (java.lang.String.format)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1