zstan commented on a change in pull request #9090:
URL: https://github.com/apache/ignite/pull/9090#discussion_r633240700



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/query/aware/IndexRebuildStateStorage.java
##########
@@ -0,0 +1,298 @@
+/*
+ * 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.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+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.GridBusyLock;
+import org.apache.ignite.internal.util.lang.IgniteThrowableConsumer;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+
+import static 
org.apache.ignite.internal.processors.query.aware.IndexRebuildState.State.COMPLETED;
+import static 
org.apache.ignite.internal.processors.query.aware.IndexRebuildState.State.DELETE;
+import static 
org.apache.ignite.internal.processors.query.aware.IndexRebuildState.State.INIT;
+
+/**
+ * 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 #onFinishRebuildIndexes}
+ * 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();
+
+    /** Node stop lock. */
+    private final GridBusyLock stopNodeLock = new GridBusyLock();
+
+    /** Current states. Mapping: cache name -> index rebuild state. */
+    private final ConcurrentMap<String, IndexRebuildState> states = new 
ConcurrentHashMap<>();

Review comment:
       seems that _states_ are never cleans ?




-- 
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]


Reply via email to