nizhikov commented on a change in pull request #9342:
URL: https://github.com/apache/ignite/pull/9342#discussion_r705209945



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/visor/consistency/VisorConsistencyRepairTask.java
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.consistency;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.CacheException;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.events.CacheConsistencyViolationEvent;
+import org.apache.ignite.internal.processors.cache.CacheGroupContext;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import 
org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition;
+import 
org.apache.ignite.internal.processors.cache.distributed.near.consistency.IgniteConsistencyViolationException;
+import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow;
+import org.apache.ignite.internal.util.GridConcurrentHashSet;
+import org.apache.ignite.internal.util.lang.GridCursor;
+import org.apache.ignite.internal.visor.VisorJob;
+import org.apache.ignite.internal.visor.VisorMultiNodeTask;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.apache.ignite.resources.LoggerResource;
+
+import static org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION;
+
+/**
+ *
+ */
+public class VisorConsistencyRepairTask extends 
VisorMultiNodeTask<VisorConsistencyRepairTaskArg, String, String> {
+    /** Serial version uid. */
+    private static final long serialVersionUID = 0L;
+
+    /** Nothing found. */
+    private static final String NOTHING_FOUND = "Consistency violations were 
not found.";
+
+    /** Found. */
+    public static final String CONSISTENCY_VIOLATIONS_FOUND = "Consistency 
violations were FOUND";
+
+    /** Violations recorder. */
+    public static final String CONSISTENCY_VIOLATIONS_RECORDED = "Cache 
consistency violations recorded.";
+
+    /** {@inheritDoc} */
+    @Override protected VisorJob<VisorConsistencyRepairTaskArg, String> 
job(VisorConsistencyRepairTaskArg arg) {
+        return new VisorConsistencyRepairJob(arg, debug);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected String reduce0(List<ComputeJobResult> results) throws 
IgniteException {
+        StringBuilder sb = new StringBuilder();
+
+        for (ComputeJobResult res : results) {
+            String data = res.getData();
+
+            if (data != null)
+                sb.append("Node: ").append(res.getNode()).append("\n")
+                    .append("  Result: ").append(data).append("\n");
+        }
+
+        return sb.toString();
+    }
+
+    /**
+     *
+     */
+    private static class VisorConsistencyRepairJob extends 
VisorJob<VisorConsistencyRepairTaskArg, String> {
+        /** Serial version uid. */
+        private static final long serialVersionUID = 0L;
+
+        /** Injected logger. */
+        @LoggerResource
+        protected IgniteLogger log;
+
+        /** Events. */
+        private final Set<CacheConsistencyViolationEvent> evts = new 
GridConcurrentHashSet<>();
+
+        /**
+         * @param arg Arguments.
+         * @param debug Debug.
+         */
+        protected VisorConsistencyRepairJob(VisorConsistencyRepairTaskArg arg, 
boolean debug) {
+            super(arg, debug);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected String run(VisorConsistencyRepairTaskArg arg) 
throws IgniteException {
+            String cacheName = arg.cacheName();
+            int p = arg.part();
+            int batchSize = 1024;
+
+            GridCacheContext<Object, Object> cctx = 
ignite.context().cache().cache(cacheName).context();
+
+            if (!cctx.gridEvents().isRecordable(EVT_CONSISTENCY_VIOLATION))
+                throw new UnsupportedOperationException("Consistency violation 
events recording is disabled on cluster.");
+
+            CacheGroupContext grpCtx = cctx.group();
+
+            GridDhtLocalPartition part = grpCtx.topology().localPartition(p);
+
+            if (part != null) {

Review comment:
       Let's rewrite it with 
   
   ```
   if (part == null)
       return null;
   
   // Other logic goes here.
   ```
   
   to reduce indentation level.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to