tkalkirill commented on code in PR #2859: URL: https://github.com/apache/ignite-3/pull/2859#discussion_r1402416576
########## modules/index/src/main/java/org/apache/ignite/internal/index/IndexCollector.java: ########## @@ -0,0 +1,296 @@ +/* + * 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.index; + +import static java.util.Collections.binarySearch; +import static java.util.Collections.unmodifiableList; +import static java.util.Comparator.comparingInt; +import static java.util.concurrent.CompletableFuture.completedFuture; +import static java.util.concurrent.CompletableFuture.failedFuture; +import static org.apache.ignite.internal.util.IgniteUtils.inBusyLock; +import static org.apache.ignite.internal.util.IgniteUtils.inBusyLockAsync; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Map.Entry; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.internal.catalog.CatalogService; +import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; +import org.apache.ignite.internal.catalog.descriptors.CatalogObjectDescriptor; +import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; +import org.apache.ignite.internal.catalog.events.CatalogEvent; +import org.apache.ignite.internal.catalog.events.DropIndexEventParameters; +import org.apache.ignite.internal.catalog.events.DropTableEventParameters; +import org.apache.ignite.internal.close.ManuallyCloseable; +import org.apache.ignite.internal.util.IgniteSpinBusyLock; + +/** Index collector for various operations, for example for RW transactions. */ +class IndexCollector implements ManuallyCloseable { + private static final Comparator<CatalogIndexDescriptor> INDEX_COMPARATOR = comparingInt(CatalogObjectDescriptor::id); + + private final CatalogService catalogService; + + /** + * Map that, for each key, contains a list of all dropped available table indexes (sorted by {@link #INDEX_COMPARATOR}) for all known + * catalog versions. + * + * <p>Let's look at an example, let's say we have the following versions of a catalog with indexes:</p> + * <pre> + * 0: I0(A) I1(A) + * 1: IO(A) + * 2: I0(A) I2(R) I3(A) + * 3: I0(A) + * 4: I0(A) + * </pre> + * + * <p>Then the map will have the following values:</p> + * <pre> + * (0, 1) -> [I1(A)] + * (0, 3) -> [I1(A), I3(A)] + * </pre> + * + * <p>Then, when {@link #getDroppedAvailableIndexes(int, int) getting dropped available indexes}, we will return the following:</p> + * <pre> + * (0, 0) -> [] + * (1, 0) -> [I1(A)] + * (2, 0) -> [I1(A)] + * (3, 0) -> [I1(A), I3(A)] + * (4, 0) -> [I1(A), I3(A)] + * </pre> + * + * <p>Updated on {@link #recover() node recovery} and a catalog events processing.</p> + */ + private final ConcurrentSkipListMap<TableIdCatalogVersion, List<CatalogIndexDescriptor>> droppedAvailableTableIndexes + = new ConcurrentSkipListMap<>(); + + private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock(); + + private final AtomicBoolean closeGuard = new AtomicBoolean(); + + /** Constructor. */ + IndexCollector(CatalogService catalogService) { + this.catalogService = catalogService; + + addListeners(); + } + + /** Recovers internal structures on node recovery. */ + void recover() { Review Comment: adds todos -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
