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



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
##########
@@ -3807,4 +3802,104 @@ public void manager(SchemaOperationManager mgr) {
             this.mgr = mgr;
         }
     }
+
+    /**
+     * Preparing futures of rebuilding indexes for caches.
+     * The future for the cache will be added only if the previous one is 
missing or completed.
+     *
+     * @param cacheIds Cache ids.
+     * @param initVer Initial affinity topology version of the exchange.
+     * @return Cache ids for which features have not been added.
+     */
+    public Set<Integer> prepareIndexRebuildFutures(Set<Integer> cacheIds, 
@Nullable AffinityTopologyVersion initVer) {
+        if (!cacheIds.isEmpty()) {
+            synchronized (idxRebuildFuts) {
+                Set<Integer> alreadyPrepared = new HashSet<>();
+
+                for (Integer cacheId : cacheIds) {
+                    GridFutureAdapter<Void> prevFut = 
idxRebuildFuts.get(cacheId);
+
+                    if (prevFut == null || prevFut.isDone()) {
+                        if (initVer != null) {
+                            AffinityTopologyVersion prev = 
idxRebuildTops.put(cacheId, initVer);
+
+                            assert prev == null;
+                        }
+
+                        idxRebuildFuts.put(cacheId, new GridFutureAdapter<>());
+                    }
+                    else
+                        alreadyPrepared.add(cacheId);
+                }
+
+                return alreadyPrepared;
+            }
+        }
+        else
+            return emptySet();
+    }
+
+    /**
+     * Removing futures of rebuilding indexes that should have been rebuilt on 
the exchange.
+     *
+     * @param fut Exchange future.
+     * @param cacheIds Cache ids for which futures will be deleted,
+     *      if {@code null} then ids will be taken from the {@code fut}.
+     */
+    public void removeIndexRebuildFuturesOnExchange(
+        GridDhtPartitionsExchangeFuture fut,
+        @Nullable Set<Integer> cacheIds
+    ) {
+        if (cacheIds == null)
+            cacheIds = rebuildIndexCacheIds(fut);
+
+        if (!cacheIds.isEmpty()) {
+            synchronized (idxRebuildFuts) {

Review comment:
       why do we need such sync here ? 




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