zstan commented on a change in pull request #9090: URL: https://github.com/apache/ignite/pull/9090#discussion_r632316461
########## File path: modules/core/src/main/java/org/apache/ignite/internal/processors/query/aware/IndexRebuildStateStorage.java ########## @@ -0,0 +1,386 @@ +/* + * 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.processors.query.aware; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.GridCacheProcessor; +import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager; +import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener; +import org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage; +import org.apache.ignite.internal.processors.cache.persistence.metastorage.MetastorageLifecycleListener; +import org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage; +import org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage; +import org.apache.ignite.internal.processors.query.GridQueryProcessor; +import org.apache.ignite.internal.util.lang.IgniteThrowableConsumer; +import org.apache.ignite.internal.util.typedef.internal.CU; + +/** + * Holder of up-to-date information about rebuilding cache indexes. + * Helps to avoid the situation when the index rebuilding process is interrupted + * and after a node restart/reactivation the indexes will become inconsistent. + * <p/> + * To do this, before rebuilding the indexes, call {@link #onStartRebuildIndexes} + * and after it {@link #onFinishRebuildIndexes}. Use {@link #completed} to check + * if the index rebuild has completed. + * <p/> + * To prevent leaks, it is necessary to use {@link #completeRebuildIndexes} + * when detecting the fact of destroying the cache. + */ +public class IndexRebuildStateStorage implements MetastorageLifecycleListener, CheckpointListener { + /** Key prefix for the MetaStorage. */ + public static final String KEY_PREFIX = "rebuild-sql-indexes-"; + + /** Kernal context. */ + private final GridKernalContext ctx; + + /** MetaStorage synchronization mutex. */ + private final Object metaStorageMux = new Object(); + + /** Lock. */ + private final ReentrantLock lock = new ReentrantLock(); + + /** + * Stopping the grid. + * Guarded by {@link #lock}. + */ + private boolean stopGrid; + + /** + * Current states. + * Mapping: cache name -> index rebuild state. + * Guarded by {@link #lock}. + */ + private final Map<String, IndexRebuildState> states = new HashMap<>(); + + /** + * Persistent caches for which the indexes have been rebuilt, + * and need to delete an entry about this from the MetaStorage. + * Guarded by {@link #lock}. + */ + private final Set<String> toRmv = new HashSet<>(); Review comment: uninformative name, plz clarify it a bit. -- 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]
