Skip to content
Permalink
Browse files
IGNITE-15329 Atomics should be repairable by Read Repair (#9907)
  • Loading branch information
anton-vinogradov committed May 26, 2022
1 parent 1d04e49 commit 189fc960f4d8fea4e6856a3d1a5e01b149e0121d
Showing 36 changed files with 2,220 additions and 1,061 deletions.
@@ -1056,6 +1056,14 @@ Parameters:
| `strategy`| Repair strategy [LWW, PRIMARY, RELATIVE_MAJORITY, REMOVE, CHECK_ONLY].
|===

Optional parameters:

[cols="1,3",opts="header"]
|===
| Parameter | Description
| `--parallel`| Allows performing check/repair in the fastest way, by parallel execution at all partition owners.
|===

=== Status

The command allows performing cache consistency check/repair operations status check.
@@ -20,18 +20,23 @@
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.logging.Logger;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.ReadRepairStrategy;
import org.apache.ignite.internal.client.GridClient;
import org.apache.ignite.internal.client.GridClientConfiguration;
import org.apache.ignite.internal.client.GridClientNode;
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.CommandLogger;
import org.apache.ignite.internal.visor.consistency.VisorConsistencyRepairTaskArg;
import org.apache.ignite.internal.visor.consistency.VisorConsistencyTaskResult;

import static java.util.stream.Collectors.toSet;
import static org.apache.ignite.internal.commandline.CommandList.CONSISTENCY;
import static org.apache.ignite.internal.commandline.TaskExecutor.BROADCAST_UUID;
import static org.apache.ignite.internal.commandline.TaskExecutor.executeTaskByNameOnNode;
@@ -52,43 +57,67 @@ public class ConsistencyCommand extends AbstractCommand<Object> {
/** Strategy. */
public static final String STRATEGY = "--strategy";

/** Parallel check. */
public static final String PARALLEL = "--parallel";

/** Command argument. */
private VisorConsistencyRepairTaskArg cmdArg;

/** Consistency sub-command to execute. */
private ConsistencySubCommand cmd;

/** Parallel check.*/
private boolean parallel;

/** Predicate to filter server nodes. */
private static final Predicate<GridClientNode> SRV_NODES = node -> !node.isClient() && !node.isDaemon();

/** {@inheritDoc} */
@Override public Object execute(GridClientConfiguration clientCfg, Logger log) throws Exception {
boolean failed = false;

StringBuilder sb = new StringBuilder();

try (GridClient client = Command.startClient(clientCfg)) {
VisorConsistencyTaskResult res = executeTaskByNameOnNode(
client,
cmd.taskName(),
arg(),
BROADCAST_UUID,
clientCfg
);

if (res.cancelled()) {
sb.append("Operation execution cancelled.\n\n");

failed = true;
}
Set<UUID> nodeIds = parallel ?
Collections.singleton(BROADCAST_UUID) :
client.compute().nodes().stream()
.filter(SRV_NODES)
.map(GridClientNode::nodeId)
.collect(toSet());

for (UUID nodeId : nodeIds) {
VisorConsistencyTaskResult res = executeTaskByNameOnNode(
client,
cmd.taskName(),
arg(),
nodeId,
clientCfg
);

if (res.cancelled()) {
sb.append("Operation execution cancelled.\n\n");

failed = true;
}

if (res.failed()) {
sb.append("Operation execution failed.\n\n");
if (res.failed()) {
sb.append("Operation execution failed.\n\n");

failed = true;
}
failed = true;
}

if (failed)
sb.append("[EXECUTION FAILED OR CANCELLED, RESULTS MAY BE INCOMPLETE OR INCONSISTENT]\n\n");
if (failed)
sb.append("[EXECUTION FAILED OR CANCELLED, RESULTS MAY BE INCOMPLETE OR INCONSISTENT]\n\n");

if (res.message() != null)
sb.append(res.message());
else
assert !parallel;

sb.append(res.message());
if (failed)
break;
}
}
catch (Throwable e) {
log.severe("Failed to perform operation.");
@@ -140,6 +169,8 @@ public class ConsistencyCommand extends AbstractCommand<Object> {
@Override public void parseArguments(CommandArgIterator argIter) {
cmd = of(argIter.nextArg("Expected consistency action."));

parallel = cmd != REPAIR; // REPAIR is sequential by default.

if (cmd == REPAIR) {
String cacheName = null;
int part = -1;
@@ -148,7 +179,7 @@ public class ConsistencyCommand extends AbstractCommand<Object> {
while (argIter.hasNextArg()) {
String arg = argIter.peekNextArg();

if (CACHE.equals(arg) || PARTITION.equals(arg) || STRATEGY.equals(arg)) {
if (CACHE.equals(arg) || PARTITION.equals(arg) || STRATEGY.equals(arg) || PARALLEL.equals(arg)) {
arg = argIter.nextArg("Expected parameter key.");

switch (arg) {
@@ -167,6 +198,11 @@ public class ConsistencyCommand extends AbstractCommand<Object> {

break;

case PARALLEL:
parallel = true;

break;

default:
throw new IllegalArgumentException("Illegal argument: " + arg);
}
@@ -184,6 +220,12 @@ public class ConsistencyCommand extends AbstractCommand<Object> {
if (strategy == null)
throw new IllegalArgumentException("Strategy argument missed.");

// see https://issues.apache.org/jira/browse/IGNITE-15316
if (parallel && strategy != ReadRepairStrategy.CHECK_ONLY) {
throw new UnsupportedOperationException(
"Parallel mode currently allowed only when CHECK_ONLY strategy is chosen.");
}

cmdArg = new VisorConsistencyRepairTaskArg(cacheName, part, strategy);
}
else if (cmd == STATUS)
@@ -27,6 +27,8 @@
import org.apache.ignite.util.GridCommandHandlerClusterByClassTest;
import org.apache.ignite.util.GridCommandHandlerClusterByClassWithSSLTest;
import org.apache.ignite.util.GridCommandHandlerConsistencyBinaryTest;
import org.apache.ignite.util.GridCommandHandlerConsistencyRepairCorrectnessAtomicTest;
import org.apache.ignite.util.GridCommandHandlerConsistencyRepairCorrectnessTransactionalTest;
import org.apache.ignite.util.GridCommandHandlerConsistencySensitiveTest;
import org.apache.ignite.util.GridCommandHandlerConsistencyTest;
import org.apache.ignite.util.GridCommandHandlerDefragmentationTest;
@@ -95,6 +97,8 @@
GridCommandHandlerConsistencyTest.class,
GridCommandHandlerConsistencyBinaryTest.class,
GridCommandHandlerConsistencySensitiveTest.class,
GridCommandHandlerConsistencyRepairCorrectnessTransactionalTest.class,
GridCommandHandlerConsistencyRepairCorrectnessAtomicTest.class,

SystemViewCommandTest.class,
MetricCommandTest.class,
@@ -0,0 +1,31 @@
/*
* 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.util;

import org.apache.ignite.cache.CacheAtomicityMode;

/**
*
*/
public class GridCommandHandlerConsistencyRepairCorrectnessAtomicTest extends
GridCommandHandlerConsistencyRepairCorrectnessTransactionalTest {
/** {@inheritDoc} */
@Override protected CacheAtomicityMode atomicityMode() {
return CacheAtomicityMode.ATOMIC;
}
}

0 comments on commit 189fc96

Please sign in to comment.