use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.
the class BootstrapTest method bootstrapTest.
@Test
public void bootstrapTest() 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()) {
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(asList(pullSchemaFrom(cluster.get(1)), bootstrap()), newInstance.config().num());
for (Map.Entry<Integer, Long> e : count(cluster).entrySet()) Assert.assertEquals("Node " + e.getKey() + " has incorrect row state", 100L, e.getValue().longValue());
}
}
use of org.apache.cassandra.distributed.api.IInstanceConfig in project cassandra by apache.
the class ReadRepairTest method readRepairRTRangeMovementTest.
@Test
public void readRepairRTRangeMovementTest() throws Throwable {
ExecutorService es = Executors.newFixedThreadPool(1);
String key = "test1";
try (Cluster cluster = init(Cluster.build().withConfig(config -> config.with(Feature.GOSSIP, Feature.NETWORK).set("read_request_timeout", String.format("%dms", Integer.MAX_VALUE))).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(4)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(4, "dc0", "rack0")).withNodes(3).start())) {
cluster.schemaChange("CREATE TABLE distributed_test_keyspace.tbl (\n" + " key text,\n" + " column1 int,\n" + " PRIMARY KEY (key, column1)\n" + ") WITH CLUSTERING ORDER BY (column1 ASC)");
cluster.forEach(i -> i.runOnInstance(() -> open(KEYSPACE).getColumnFamilyStore("tbl").disableAutoCompaction()));
for (int i = 1; i <= 2; i++) {
cluster.get(i).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 50 WHERE key=?;", key);
cluster.get(i).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 80 WHERE key=? and column1 >= ? and column1 < ?;", key, 10, 100);
cluster.get(i).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 70 WHERE key=? and column1 = ?;", key, 30);
cluster.get(i).flush(KEYSPACE);
}
cluster.get(3).executeInternal("DELETE FROM distributed_test_keyspace.tbl USING TIMESTAMP 100 WHERE key=?;", key);
cluster.get(3).flush(KEYSPACE);
// pause the read until we have bootstrapped a new node below
Condition continueRead = newOneTimeCondition();
Condition readStarted = newOneTimeCondition();
cluster.filters().outbound().from(3).to(1, 2).verbs(READ_REQ.id).messagesMatching((i, i1, iMessage) -> {
try {
readStarted.signalAll();
continueRead.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return false;
}).drop();
Future<Object[][]> read = es.submit(() -> cluster.coordinator(3).execute("SELECT * FROM distributed_test_keyspace.tbl WHERE key=? and column1 >= ? and column1 <= ?", ALL, key, 20, 40));
readStarted.await();
IInstanceConfig config = cluster.newInstanceConfig();
config.set("auto_bootstrap", true);
cluster.bootstrap(config).startup();
continueRead.signalAll();
read.get();
} finally {
es.shutdown();
}
}
use of org.apache.cassandra.distributed.api.IInstanceConfig 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.IInstanceConfig 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.IInstanceConfig in project cassandra by apache.
the class MigrationCoordinatorTest method explicitVersionIgnore.
@Test
public void explicitVersionIgnore() throws Throwable {
try (Cluster cluster = Cluster.build(2).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(3)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(3, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP)).start()) {
UUID initialVersion = cluster.get(2).callsOnInstance(() -> Schema.instance.getVersion()).call();
cluster.schemaChange("CREATE KEYSPACE ks with replication={'class':'SimpleStrategy', 'replication_factor':2}");
UUID oldVersion;
do {
oldVersion = cluster.get(2).callsOnInstance(() -> Schema.instance.getVersion()).call();
} while (oldVersion.equals(initialVersion));
cluster.get(2).shutdown(false);
cluster.schemaChangeIgnoringStoppedInstances("CREATE TABLE ks.tbl (k int primary key, v int)");
IInstanceConfig config = cluster.newInstanceConfig();
config.set("auto_bootstrap", true);
System.setProperty(MigrationCoordinator.IGNORED_VERSIONS_PROP, initialVersion.toString() + ',' + oldVersion.toString());
System.setProperty("cassandra.consistent.rangemovement", "false");
cluster.bootstrap(config).startup();
}
}
Aggregations