Search in sources :

Example 16 with NodeToolResult

use of org.apache.cassandra.distributed.api.NodeToolResult in project cassandra by apache.

the class RepairCoordinatorFailingMessageTest method validationFailure.

// TODO failure reply murkle tree
// TODO failure reply murkle tree IR
@Test(timeout = 1 * 60 * 1000)
public void validationFailure() {
    String table = tableName("validationfailure");
    CLUSTER.schemaChange(format("CREATE TABLE %s.%s (key text, value text, PRIMARY KEY (key))", KEYSPACE, table));
    IMessageFilters.Filter filter = CLUSTER.verbs(Verb.VALIDATION_REQ).messagesMatching(of(m -> {
        throw new RuntimeException("validation fail");
    })).drop();
    try {
        NodeToolResult result = repair(1, KEYSPACE, table);
        result.asserts().failure().errorContains("Some repair failed").notificationContains(NodeToolResult.ProgressEventType.ERROR, "Some repair failed").notificationContains(NodeToolResult.ProgressEventType.COMPLETE, "finished with error");
    } finally {
        filter.off();
    }
}
Also used : IMessageFilters(org.apache.cassandra.distributed.api.IMessageFilters) NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult) Test(org.junit.Test)

Example 17 with NodeToolResult

use of org.apache.cassandra.distributed.api.NodeToolResult in project cassandra by apache.

the class IncRepairTruncationTest method testTruncateDuringIncRepair.

@Test
public void testTruncateDuringIncRepair() throws IOException, InterruptedException, ExecutionException {
    ExecutorService es = Executors.newFixedThreadPool(3);
    try (Cluster cluster = init(Cluster.build(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start())) {
        cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, t int)");
        insert(cluster.coordinator(1), 0, 100);
        cluster.forEach((node) -> node.flush(KEYSPACE));
        // mark everything repaired
        cluster.get(1).nodetoolResult("repair", KEYSPACE, "tbl").asserts().success();
        /*
            make sure we are out-of-sync to make node2 stream data to node1:
             */
        cluster.get(2).executeInternal("insert into " + KEYSPACE + ".tbl (id, t) values (5, 5)");
        cluster.get(2).flush(KEYSPACE);
        /*
            start repair:
            block streaming from 2 -> 1 until truncation below has executed
             */
        BlockMessage node2Streaming = new BlockMessage();
        cluster.filters().inbound().verbs(Verb.VALIDATION_RSP.id).from(2).to(1).messagesMatching(node2Streaming).drop();
        /*
            block truncation on node2:
             */
        BlockMessage node2Truncation = new BlockMessage();
        cluster.filters().inbound().verbs(Verb.TRUNCATE_REQ.id).from(1).to(2).messagesMatching(node2Truncation).drop();
        Future<NodeToolResult> repairResult = es.submit(() -> cluster.get(1).nodetoolResult("repair", KEYSPACE, "tbl"));
        Future<?> truncationFuture = es.submit(() -> {
            try {
                /*
                    wait for streaming message to sent before truncating, to make sure we have a mismatch to make us stream later
                     */
                node2Streaming.gotMessage.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            cluster.coordinator(1).execute("TRUNCATE " + KEYSPACE + ".tbl", ConsistencyLevel.ALL);
        });
        node2Truncation.gotMessage.await();
        // make sure node1 finishes truncation, removing its files
        cluster.get(1).runOnInstance(() -> {
            ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore("tbl");
            while (!cfs.getLiveSSTables().isEmpty()) Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        });
        /* let repair finish, streaming files from 2 -> 1 */
        node2Streaming.allowMessage.signalAll();
        /* and the repair should fail: */
        repairResult.get().asserts().failure();
        /*
            and let truncation finish on node2
             */
        node2Truncation.allowMessage.signalAll();
        truncationFuture.get();
        /* wait for truncation to remove files on node2 */
        cluster.get(2).runOnInstance(() -> {
            ColumnFamilyStore cfs = Keyspace.open(KEYSPACE).getColumnFamilyStore("tbl");
            while (!cfs.getLiveSSTables().isEmpty()) {
                System.out.println(cfs.getLiveSSTables());
                Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            }
        });
        cluster.get(1).nodetoolResult("repair", "-vd", KEYSPACE, "tbl").asserts().success().notificationContains("Repair preview completed successfully");
    } finally {
        es.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Cluster(org.apache.cassandra.distributed.Cluster) NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult) Test(org.junit.Test)

Example 18 with NodeToolResult

use of org.apache.cassandra.distributed.api.NodeToolResult in project cassandra by apache.

the class OptimiseStreamsRepairTest method randomTest.

@Test
public void randomTest() throws IOException, TimeoutException {
    try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.set("hinted_handoff_enabled", false).with(GOSSIP).with(NETWORK)).start())) {
        cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, t int) with compaction={'class': 'SizeTieredCompactionStrategy'}");
        for (int i = 0; i < 1000; i++) cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, t) values (?,?)", ConsistencyLevel.ALL, i, i);
        cluster.forEach((i) -> i.flush(KEYSPACE));
        Random r = new Random();
        for (int i = 0; i < 500; i++) for (int j = 1; j <= 3; j++) cluster.get(j).executeInternal("INSERT INTO " + KEYSPACE + ".tbl (id, t) values (?,?)", r.nextInt(), i * 2 + 2);
        long[] marks = PreviewRepairTest.logMark(cluster);
        NodeToolResult res = cluster.get(1).nodetoolResult("repair", KEYSPACE, "-os");
        res.asserts().success();
        PreviewRepairTest.waitLogsRepairFullyFinished(cluster, marks);
        res = cluster.get(1).nodetoolResult("repair", KEYSPACE, "-vd");
        res.asserts().success();
        res.asserts().notificationContains("Repaired data is in sync");
        res = cluster.get(1).nodetoolResult("repair", KEYSPACE, "--preview", "--full");
        res.asserts().success();
        res.asserts().notificationContains("Previewed data was in sync");
    }
}
Also used : Random(java.util.Random) Cluster(org.apache.cassandra.distributed.Cluster) NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult) Test(org.junit.Test)

Example 19 with NodeToolResult

use of org.apache.cassandra.distributed.api.NodeToolResult in project cassandra by apache.

the class IncRepairAdminTest method awaitNodetoolRepairAdminContains.

private static void awaitNodetoolRepairAdminContains(Cluster cluster, UUID uuid, String state, boolean all) {
    cluster.forEach(i -> {
        while (true) {
            NodeToolResult res;
            if (all)
                res = i.nodetoolResult("repair_admin", "list", "--all");
            else
                res = i.nodetoolResult("repair_admin");
            res.asserts().success();
            String[] lines = res.getStdout().split("\n");
            assertTrue(lines.length > 1);
            for (String line : lines) {
                if (line.contains(uuid.toString()) && line.contains(state))
                    return;
            }
            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        }
    });
}
Also used : NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult)

Example 20 with NodeToolResult

use of org.apache.cassandra.distributed.api.NodeToolResult in project cassandra by apache.

the class IncRepairAdminTest method repairAdminCancelHelper.

private void repairAdminCancelHelper(boolean coordinator, boolean force) throws IOException {
    try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start())) {
        boolean shouldFail = !coordinator && !force;
        cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (k INT PRIMARY KEY, v INT)");
        cluster.forEach(i -> {
            NodeToolResult res = i.nodetoolResult("repair_admin");
            res.asserts().stdoutContains("no sessions");
        });
        UUID uuid = makeFakeSession(cluster);
        awaitNodetoolRepairAdminContains(cluster, uuid, "REPAIRING", false);
        IInvokableInstance instance = cluster.get(coordinator ? 1 : 2);
        NodeToolResult res;
        if (force) {
            res = instance.nodetoolResult("repair_admin", "cancel", "--session", uuid.toString(), "--force");
        } else {
            res = instance.nodetoolResult("repair_admin", "cancel", "--session", uuid.toString());
        }
        if (shouldFail) {
            res.asserts().failure();
            // if nodetool repair_admin cancel fails, the session should still be repairing:
            awaitNodetoolRepairAdminContains(cluster, uuid, "REPAIRING", true);
        } else {
            res.asserts().success();
            awaitNodetoolRepairAdminContains(cluster, uuid, "FAILED", true);
        }
    }
}
Also used : IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) NodeToolResult(org.apache.cassandra.distributed.api.NodeToolResult) UUID(java.util.UUID)

Aggregations

NodeToolResult (org.apache.cassandra.distributed.api.NodeToolResult)29 Test (org.junit.Test)24 Cluster (org.apache.cassandra.distributed.Cluster)6 IMessageFilters (org.apache.cassandra.distributed.api.IMessageFilters)5 UnknownHostException (java.net.UnknownHostException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Token (org.apache.cassandra.dht.Token)2 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Random (java.util.Random)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Future (java.util.concurrent.Future)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CassandraRelevantProperties (org.apache.cassandra.config.CassandraRelevantProperties)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Range (org.apache.cassandra.dht.Range)1 ConsistencyLevel (org.apache.cassandra.distributed.api.ConsistencyLevel)1