use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class TestBaseImpl method bootstrapAndJoinNode.
protected void bootstrapAndJoinNode(Cluster cluster) {
IInstanceConfig config = cluster.newInstanceConfig();
config.set("auto_bootstrap", true);
IInvokableInstance newInstance = cluster.bootstrap(config);
withProperty(BOOTSTRAP_SCHEMA_DELAY_MS.getKey(), Integer.toString(90 * 1000), () -> withProperty("cassandra.join_ring", false, () -> newInstance.startup(cluster)));
newInstance.nodetoolResult("join").asserts().success();
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class PendingWritesTest method testPendingWrites.
@Test
public void testPendingWrites() throws Throwable {
int originalNodeCount = 2;
int expandedNodeCount = originalNodeCount + 1;
try (Cluster cluster = builder().withNodes(originalNodeCount).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(expandedNodeCount)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(expandedNodeCount, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP)).start()) {
BootstrapTest.populate(cluster, 0, 100);
IInstanceConfig config = cluster.newInstanceConfig();
IInvokableInstance newInstance = cluster.bootstrap(config);
withProperty("cassandra.join_ring", false, () -> newInstance.startup(cluster));
cluster.forEach(statusToBootstrap(newInstance));
cluster.run(bootstrap(false, Duration.ofSeconds(60), Duration.ofSeconds(60)), newInstance.config().num());
cluster.get(1).acceptsOnInstance((InetSocketAddress ip) -> {
Set<InetAddressAndPort> set = new HashSet<>();
for (Map.Entry<Range<Token>, EndpointsForRange.Builder> e : StorageService.instance.getTokenMetadata().getPendingRanges(KEYSPACE)) {
set.addAll(e.getValue().build().endpoints());
}
Assert.assertEquals(set.size(), 1);
Assert.assertTrue(String.format("%s should contain %s", set, ip), set.contains(DistributedTestSnitch.toCassandraInetAddressAndPort(ip)));
}).accept(cluster.get(3).broadcastAddress());
BootstrapTest.populate(cluster, 100, 150);
newInstance.nodetoolResult("join").asserts().success();
cluster.run(disseminateGossipState(newInstance), 1, 2);
cluster.run((instance) -> {
instance.runOnInstance(() -> {
PendingRangeCalculatorService.instance.update();
PendingRangeCalculatorService.instance.blockUntilFinished();
});
}, 1, 2);
cluster.get(1).acceptsOnInstance((InetSocketAddress ip) -> {
Set<InetAddressAndPort> set = new HashSet<>();
for (Map.Entry<Range<Token>, EndpointsForRange.Builder> e : StorageService.instance.getTokenMetadata().getPendingRanges(KEYSPACE)) set.addAll(e.getValue().build().endpoints());
assert set.size() == 0 : set;
}).accept(cluster.get(3).broadcastAddress());
for (Map.Entry<Integer, Long> e : BootstrapTest.count(cluster).entrySet()) Assert.assertEquals("Node " + e.getKey() + " has incorrect row state", e.getValue().longValue(), 150L);
}
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class RepairOperationalTest method emptyDC.
@Test
public void emptyDC() throws IOException {
try (Cluster cluster = Cluster.build().withRacks(2, 1, 2).start()) {
// 1-2 : datacenter1
// 3-4 : datacenter2
cluster.schemaChange("CREATE KEYSPACE " + KEYSPACE + " WITH replication = {'class': 'NetworkTopologyStrategy', 'datacenter1':2, 'datacenter2':0}");
cluster.schemaChange("CREATE TABLE " + KEYSPACE + ".tbl (id int PRIMARY KEY, i int)");
for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("INSERT INTO " + KEYSPACE + ".tbl (id, i) VALUES (?, ?)", ConsistencyLevel.ALL, i, i);
cluster.forEach(i -> i.flush(KEYSPACE));
// choose a node in the DC that doesn't have any replicas
IInvokableInstance node = cluster.get(3);
Assertions.assertThat(node.config().localDatacenter()).isEqualTo("datacenter2");
// fails with [2020-09-10 11:30:04,139] Repair command #1 failed with error Nothing to repair for (0,1000] in distributed_test_keyspace - aborting. Check the logs on the repair participants for further details
node.nodetoolResult("repair", "-full", "--ignore-unreplicated-keyspaces", "-st", "0", "-et", "1000", KEYSPACE, "tbl").asserts().success();
}
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class StreamCloseInMiddleTest method triggerStreaming.
private static void triggerStreaming(Cluster cluster, boolean expectedEntireSSTable) {
IInvokableInstance node1 = cluster.get(1);
IInvokableInstance node2 = cluster.get(2);
// repair will do streaming IFF there is a mismatch; so cause one
for (int i = 0; i < 10; i++) // timestamp won't match, causing a mismatch
node1.executeInternal(withKeyspace("INSERT INTO %s.tbl (pk) VALUES (?)"), i);
// trigger streaming; expected to fail as streaming socket closed in the middle (currently this is an unrecoverable event)
node2.nodetoolResult("repair", "-full", KEYSPACE, "tbl").asserts().failure();
assertStreamingType(node2, expectedEntireSSTable);
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class StreamCloseInMiddleTest method streamClose.
private void streamClose(boolean zeroCopyStreaming) throws IOException {
try (Cluster cluster = Cluster.build(2).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(3)).withInstanceInitializer(BBHelper::install).withConfig(c -> c.with(Feature.values()).set("stream_entire_sstables", zeroCopyStreaming).set("disk_failure_policy", "die")).start()) {
init(cluster);
cluster.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int PRIMARY KEY)"));
triggerStreaming(cluster, zeroCopyStreaming);
// make sure disk failure policy is not triggered
assertNoNodeShutdown(cluster);
// now bootstrap a new node; streaming will fail
IInvokableInstance node3 = ClusterUtils.addInstance(cluster, cluster.get(1).config(), c -> c.set("auto_bootstrap", true));
node3.startup();
for (String line : // bootstrap failed
Arrays.asList(// bootstrap failed
"Error while waiting on bootstrap to complete. Bootstrap will have to be restarted", // didn't join ring because bootstrap failed
"Some data streaming failed. Use nodetool to check bootstrap state and resume")) Assertions.assertThat(node3.logs().grep(line).getResult()).hasSize(1);
assertNoNodeShutdown(cluster);
}
}
Aggregations