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



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
##########
@@ -1429,25 +1432,55 @@ private int resolvePageSizeFromPartitionFile(Path 
partFile) throws IOException,
         if (defrgMgr != null)
             return;
 
-        rebuildIndexes(cctx.cacheContexts(), (cacheCtx) -> 
cacheCtx.startTopologyVersion().equals(exchangeFut.initialVersion()));
+        Collection<GridCacheContext> rejected = rebuildIndexes(
+            cctx.cacheContexts(),
+            (cacheCtx) -> 
cacheCtx.startTopologyVersion().equals(exchangeFut.initialVersion()) &&
+                
cctx.kernalContext().query().rebuildIndexOnExchange(cacheCtx.cacheId()),
+            false
+        );
+
+        if (!rejected.isEmpty()) {
+            cctx.kernalContext().query().removeIndexRebuildFuturesOnExchange(
+                exchangeFut,
+                
rejected.stream().map(GridCacheContext::cacheId).collect(toSet())
+            );
+        }
     }
 
     /** {@inheritDoc} */
-    @Override public void forceRebuildIndexes(Collection<GridCacheContext> 
contexts) {
-        contexts.forEach(ctx -> 
cctx.kernalContext().query().prepareIndexRebuildFuture(ctx.cacheId()));
+    @Override public Collection<GridCacheContext> 
forceRebuildIndexes(Collection<GridCacheContext> contexts) {
+        Set<Integer> cacheIds = 
contexts.stream().map(GridCacheContext::cacheId).collect(toSet());
+
+        Set<Integer> rejected = 
cctx.kernalContext().query().prepareIndexRebuildFutures(cacheIds, null);
+
+        if (log.isDebugEnabled()) {
+            log.debug("Preparing features of rebuilding indexes for caches on 
force rebuild [requested=" + cacheIds +
+                ", rejected=" + rejected + ']');
+        }
+
+        rebuildIndexes(contexts, (cacheCtx) -> 
!rejected.contains(cacheCtx.cacheId()), true);
 
-        rebuildIndexes(contexts, (cacheCtx) -> true);
+        return rejected.isEmpty() ? emptyList() :
+            contexts.stream().filter(ctx -> 
rejected.contains(ctx.cacheId())).collect(toList());
     }
 
     /**
+     * Rebuilding indexes for caches.
+     *
      * @param contexts Collection of cache contexts for which indexes should 
be rebuilt.
      * @param rebuildCond Condition that should be met for indexes to be 
rebuilt for specific cache.
+     * @param force Force rebuild indexes.
+     * @return Cash contexts that did not pass by {@code rebuildCond}.

Review comment:
       cool typo ))




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