SammyVimes commented on code in PR #10042:
URL: https://github.com/apache/ignite/pull/10042#discussion_r884531710


##########
modules/indexing/src/main/java/org/apache/ignite/internal/visor/cache/index/IndexRebuildTask.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.visor.cache.index;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
+import org.apache.ignite.internal.processors.query.GridQueryProcessor;
+import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
+import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing;
+import org.apache.ignite.internal.processors.query.h2.database.H2TreeIndexBase;
+import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
+import org.apache.ignite.internal.processors.task.GridInternal;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.visor.VisorJob;
+import org.apache.ignite.internal.visor.VisorMultiNodeTask;
+import org.apache.ignite.maintenance.MaintenanceRegistry;
+import org.apache.ignite.maintenance.MaintenanceTask;
+import org.h2.index.Index;
+import org.jetbrains.annotations.Nullable;
+
+import static 
org.apache.ignite.internal.cache.query.index.sorted.maintenance.MaintenanceRebuildIndexUtils.mergeTasks;
+import static 
org.apache.ignite.internal.cache.query.index.sorted.maintenance.MaintenanceRebuildIndexUtils.toMaintenanceTask;
+
+/**
+ * Task that schedules indexes rebuild for specified caches via the 
maintenance mode.
+ */
+@GridInternal
+public class IndexRebuildTask extends VisorMultiNodeTask<IndexRebuildTaskArg, 
IndexRebuildTaskRes, IndexRebuildJobRes> {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override protected IndexRebuildJob job(IndexRebuildTaskArg arg) {
+        return new IndexRebuildJob(arg, debug);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected @Nullable IndexRebuildTaskRes 
reduce0(List<ComputeJobResult> results) throws IgniteException {
+        Map<UUID, IndexRebuildJobRes> taskResultMap = results.stream()
+            .collect(Collectors.toMap(res -> res.getNode().id(), 
ComputeJobResult::getData));
+
+        return new IndexRebuildTaskRes(taskResultMap);
+    }
+
+    /** */
+    private static class IndexRebuildJob extends VisorJob<IndexRebuildTaskArg, 
IndexRebuildJobRes> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /**
+         * Create job with specified argument.
+         *
+         * @param arg Job argument.
+         * @param debug Flag indicating whether debug information should be 
printed into node log.
+         */
+        protected IndexRebuildJob(@Nullable IndexRebuildTaskArg arg, boolean 
debug) {
+            super(arg, debug);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected IndexRebuildJobRes run(@Nullable 
IndexRebuildTaskArg arg) throws IgniteException {
+            assert arg.cacheToIndexes() != null && 
!arg.cacheToIndexes().isEmpty() : "Cache to indexes map must be specified.";
+
+            Set<String> notFound = new HashSet<>();
+
+            GridCacheProcessor cacheProcessor = ignite.context().cache();
+
+            Map<String, Set<String>> cacheToIndexes = new HashMap<>();
+            Map<String, Set<String>> cacheToMissedIndexes = new HashMap<>();
+
+            for (Entry<String, Set<String>> indexesByCache : 
arg.cacheToIndexes().entrySet()) {
+                String cache = indexesByCache.getKey();
+                Set<String> indexesArg = indexesByCache.getValue();
+                int cacheId = CU.cacheId(cache);
+
+                GridCacheContext<?, ?> cacheCtx = 
cacheProcessor.context().cacheContext(cacheId);
+
+                if (cacheCtx == null) {
+                    notFound.add(cache);
+                    continue;
+                }
+
+                Set<String> existingIndexes = indexes(cache);
+                Set<String> indexesToRebuild = 
cacheToIndexes.computeIfAbsent(cache, s -> new HashSet<>());
+                Set<String> missedIndexes = 
cacheToMissedIndexes.computeIfAbsent(cache, s -> new HashSet<>());
+
+                if (indexesArg.isEmpty())
+                    indexesToRebuild.addAll(existingIndexes);
+                else {
+                    indexesArg.forEach(index -> {
+                        if (!existingIndexes.contains(index)) {
+                            missedIndexes.add(index);
+                            return;
+                        }
+
+                        indexesToRebuild.add(index);
+                    });
+                }
+            }
+
+            if (hasIndexes(cacheToIndexes)) {

Review Comment:
   Because it checks collections that are values of the map, not the map itself



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to