You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/06/28 12:57:41 UTC

[GitHub] [ignite] SammyVimes commented on a diff in pull request #10042: IGNITE-17002 Control.sh command to schedule index rebuild in Maintenance Mode

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


##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/CacheScheduleIndexesRebuild.java:
##########
@@ -0,0 +1,320 @@
+/*
+ * 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.commandline.cache;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.commandline.TaskExecutor;
+import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
+import org.apache.ignite.internal.commandline.cache.argument.IndexRebuildCommandArg;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.visor.cache.index.ScheduleIndexRebuildTaskArg;
+import org.apache.ignite.internal.visor.cache.index.ScheduleIndexRebuildTaskRes;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.commandline.CommandLogger.INDENT;
+import static org.apache.ignite.internal.commandline.cache.argument.IndexRebuildCommandArg.CACHE_GROUPS_TARGET;
+import static org.apache.ignite.internal.commandline.cache.argument.IndexRebuildCommandArg.CACHE_NAMES_TARGET;
+import static org.apache.ignite.internal.commandline.cache.argument.IndexRebuildCommandArg.NODE_ID;
+
+/**
+ * Cache subcommand that schedules indexes rebuild via the maintenance mode.
+ */
+public class CacheScheduleIndexesRebuild extends AbstractCommand<CacheScheduleIndexesRebuild.Arguments> {
+    /** --cache-names parameter format. */
+    private static final String CACHE_NAMES_FORMAT = "cacheName[index1,...indexN],cacheName2,cacheName3[index1]";
+
+    /** --group-names parameter format. */
+    private static final String CACHE_GROUPS_FORMAT = "groupName1,groupName2,...groupNameN";
+
+    /** Command's parsed arguments. */
+    private Arguments args;
+
+    /** {@inheritDoc} */
+    @Override public void printUsage(Logger logger) {
+        String desc = "Schedules rebuild of the indexes for specified caches via the Maintenance Mode.";
+
+        Map<String, String> map = new LinkedHashMap<>(2);
+
+        map.put(NODE_ID.argName(), "(Optional) Specify node for indexes rebuild.");
+
+        map.put(
+            CACHE_NAMES_TARGET.argName(),
+            "Comma-separated list of cache names with optionally specified indexes. If indexes are not specified then all indexes "
+            + "of the cache will be scheduled for the rebuild operation."
+        );
+
+        map.put(CACHE_GROUPS_TARGET.argName(), "Comma-separated list of cache group names for which indexes should be scheduled for the "
+            + "rebuild.");
+
+        usageCache(
+            logger,
+            CacheSubcommands.INDEX_REBUILD,
+            desc,
+            map,
+            NODE_ID.argName() + " nodeId",
+            CACHE_NAMES_TARGET + " " + CACHE_NAMES_FORMAT,
+            CACHE_GROUPS_TARGET + " " + CACHE_GROUPS_FORMAT
+        );
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object execute(GridClientConfiguration clientCfg, Logger logger) throws Exception {
+        ScheduleIndexRebuildTaskRes taskRes;
+
+        try (GridClient client = Command.startClient(clientCfg)) {
+            UUID nodeId = args.nodeId;
+
+            if (nodeId == null)
+                nodeId = TaskExecutor.BROADCAST_UUID;
+
+            taskRes = TaskExecutor.executeTaskByNameOnNode(
+                client,
+                "org.apache.ignite.internal.visor.cache.index.ScheduleIndexRebuildTask",
+                new ScheduleIndexRebuildTaskArg(args.cacheToIndexes, args.cacheGroups),
+                nodeId,
+                clientCfg
+            );
+        }
+
+        printResult(taskRes, logger);
+
+        return taskRes;
+    }
+
+    /**
+     * @param taskRes Rebuild task result.
+     * @param logger Logger to print to.
+     */
+    private void printResult(ScheduleIndexRebuildTaskRes taskRes, Logger logger) {
+        taskRes.results().forEach((nodeId, res) -> {
+            printMissed(logger, "WARNING: These caches were not found:", res.notFoundCacheNames());
+            printMissed(logger, "WARNING: These cache groups were not found:", res.notFoundGroupNames());
+
+            if (!F.isEmpty(res.notFoundIndexes()) && hasAtLeastOneIndex(res.notFoundIndexes())) {
+                String warning = "WARNING: These indexes were not found:";
+
+                logger.info(warning);
+
+                printCachesAndIndexes(res.notFoundIndexes(), logger);
+            }
+
+            if (!F.isEmpty(res.cacheToIndexes()) && hasAtLeastOneIndex(res.cacheToIndexes())) {
+                logger.info("Indexes rebuild was scheduled for these caches:");
+
+                printCachesAndIndexes(res.cacheToIndexes(), logger);
+            }
+            else
+                logger.info("WARNING: Indexes rebuild was not scheduled for any cache. Check command input.");
+
+            logger.info("");
+        });
+    }
+
+    /**
+     * Prints missed caches' or cache groups' names.
+     *
+     * @param logger Logger.
+     * @param warning Warning message.
+     * @param missed Missed caches or cache groups' names.
+     */
+    private void printMissed(Logger logger, String warning, Set<String> missed) {
+        if (!F.isEmpty(missed)) {
+            logger.info(warning);

Review Comment:
   Perhaps it's just a bad name for a variable, we should use info 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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

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