timoninmaxim commented on a change in pull request #8490: URL: https://github.com/apache/ignite/pull/8490#discussion_r579621637
########## File path: modules/core/src/main/java/org/apache/ignite/internal/cache/query/index/sorted/inline/InlineRecommender.java ########## @@ -0,0 +1,145 @@ +/* + * 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 java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.SystemProperty; +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.inline.io.IndexRow; +import org.apache.ignite.internal.cache.query.index.sorted.inline.io.IndexSearchRowImpl; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** + * Write to a log recommendation for inline size. + */ +public class InlineRecommender { + /** @see #IGNITE_THROTTLE_INLINE_SIZE_CALCULATION */ + public static final int DFLT_THROTTLE_INLINE_SIZE_CALCULATION = 1_000; + + /** */ + @SystemProperty(value = "How often real invocation of inline size calculation will be skipped.", type = Long.class, + defaults = "" + DFLT_THROTTLE_INLINE_SIZE_CALCULATION) + public static final String IGNITE_THROTTLE_INLINE_SIZE_CALCULATION = "IGNITE_THROTTLE_INLINE_SIZE_CALCULATION"; + + /** Counter of inline size calculation for throttling real invocations. */ + private final ThreadLocal<Long> inlineSizeCalculationCntr = ThreadLocal.withInitial(() -> 0L); + + /** How often real invocation of inline size calculation will be skipped. */ + private final int inlineSizeThrottleThreshold = + IgniteSystemProperties.getInteger(IGNITE_THROTTLE_INLINE_SIZE_CALCULATION, + DFLT_THROTTLE_INLINE_SIZE_CALCULATION); + + /** Keep max calculated inline size for current index. */ + private final AtomicInteger maxCalculatedInlineSize = new AtomicInteger(); + + /** Ignite logger. */ + private final IgniteLogger log; + + /** Index definition. */ + private final SortedIndexDefinition def; + + /** Constructor. */ + public InlineRecommender(GridCacheContext cctx, SortedIndexDefinition def) { + log = cctx.kernalContext().indexing().getLogger(); + this.def = def; + } + + /** + * Calculate aggregate inline size for given indexes and log recommendation in case calculated size more than + * current inline size. + */ + @SuppressWarnings({"ConditionalBreakInInfiniteLoop", "IfMayBeConditional"}) + public void recommend(IndexRow row, int currInlineSize) { + // Do the check only for put operations. + if (row instanceof IndexSearchRowImpl) + return; + + Long invokeCnt = inlineSizeCalculationCntr.get(); + + inlineSizeCalculationCntr.set(++invokeCnt); + + boolean throttle = invokeCnt % inlineSizeThrottleThreshold != 0; + + if (throttle) + return; Review comment: Hi, agree. Replaced with optimistic CAS. ---------------------------------------------------------------- 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]
