korlov42 commented on a change in pull request #8490: URL: https://github.com/apache/ignite/pull/8490#discussion_r571672872
########## File path: modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineIndexTree.java ########## @@ -0,0 +1,480 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.cache.query.index.sorted.inline; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cache.query.index.sorted.SortOrder; +import org.apache.ignite.failure.FailureType; +import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition; +import org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition; +import org.apache.ignite.internal.cache.query.index.sorted.SortedIndexSchema; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.IndexRow; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.IndexSearchRow; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.InnerIO; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.LeafIO; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.ThreadLocalSchemaHolder; +import org.apache.ignite.internal.metric.IoStatisticsHolder; +import org.apache.ignite.internal.pagemem.FullPageId; +import org.apache.ignite.internal.pagemem.PageIdAllocator; +import org.apache.ignite.internal.pagemem.PageMemory; +import org.apache.ignite.internal.pagemem.wal.record.PageSnapshot; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusInnerIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusLeafIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.BPlusMetaIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.IOVersions; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIoResolver; +import org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; + +import static org.apache.ignite.internal.cache.query.index.sorted.inline.keys.NullableInlineIndexKeyType.CANT_BE_COMPARE; +import static org.apache.ignite.internal.cache.query.index.sorted.inline.keys.NullableInlineIndexKeyType.COMPARE_UNSUPPORTED; + +/** + * BPlusTree where nodes stores inlined index keys. + */ +public class InlineIndexTree extends BPlusTree<IndexRow, IndexRow> { + /** Amount of bytes to store inlined index keys. */ + private final int inlineSize; + + /** Recommends change inline size if needed. */ + private final InlineRecommender recommender; + + /** Whether tree is created from scratch or reused from underlying store. */ + private final boolean created; + + /** Definition of index. */ + private final SortedIndexDefinition def; + + /** Cache context. */ + private final GridCacheContext<?, ?> cctx; + + /** Statistics holder used by underlying BPlusTree. */ + private final IoStatisticsHolder stats; + + /** + * Constructor. + */ + public InlineIndexTree( + SortedIndexDefinition def, + GridCacheContext<?, ?> cctx, + String treeName, + IgniteCacheOffheapManager offheap, + ReuseList reuseList, + PageMemory pageMemory, + PageIoResolver pageIoResolver, + long metaPageId, + boolean initNew, + int configuredInlineSize, + IoStatisticsHolder stats, + InlineRecommender recommender) throws IgniteCheckedException { + super( + treeName, + cctx.groupId(), + cctx.group().name(), + pageMemory, + cctx.shared().wal(), + offheap.globalRemoveId(), + metaPageId, + reuseList, + PageIdAllocator.FLAG_IDX, + cctx.shared().kernalContext().failure(), + null, + pageIoResolver + ); + + this.stats = stats; + + created = initNew; + + this.def = def; + + if (!initNew) { + // Init from metastore + // Page is ready - read meta information. + MetaPageInfo metaInfo = getMetaInfo(); + + this.def.setUseUnwrappedPk(metaInfo.useUnwrappedPk()); + + inlineSize = metaInfo.inlineSize(); + + boolean inlineObjSupported = inlineSize > 0 && metaInfo.inlineObjectSupported(); + + if (!metaInfo.flagsSupported()) + upgradeMetaPage(inlineObjSupported); + + } else { + this.def.setUseUnwrappedPk(true); + + inlineSize = computeInlineSize( + def.getSchema().getKeyDefinitions(), configuredInlineSize, cctx.config().getSqlIndexMaxInlineSize()); + } + + if (inlineSize == 0) + setIos(InnerIO.VERSIONS, LeafIO.VERSIONS); + else + setIos( + // -1 is required as payload starts with 1, and indexes in list of IOs are with 0. + (IOVersions<BPlusInnerIO<IndexRow>>) PageIO.getInnerVersions(inlineSize - 1, false), + (IOVersions<BPlusLeafIO<IndexRow>>) PageIO.getLeafVersions(inlineSize - 1, false)); + + initTree(initNew, inlineSize); + + this.recommender = recommender; + + this.cctx = cctx; + } + + /** {@inheritDoc} */ + @Override protected int compare(BPlusIO<IndexRow> io, long pageAddr, int idx, IndexRow row) + throws IgniteCheckedException { + IndexSearchRow r = (IndexSearchRow) row; + + int searchKeysLength = r.getSearchKeysCount(); + + if (inlineSize == 0) + return compareFullRows(getRow(io, pageAddr, idx), row, 0, searchKeysLength); + + SortedIndexSchema schema = def.getSchema(); + + if ((schema.getKeyDefinitions().length != searchKeysLength) && r.isFullSchemaSearch()) Review comment: this should be verified only once before actual search. Also message error is not clear. Who does configure the search? What actually does "full schema search" means? I'd rather get rid of this. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
