use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class ReprepareTestBase method testReprepareTwoKeyspaces.
public void testReprepareTwoKeyspaces(BiConsumer<ClassLoader, Integer> instanceInitializer) throws Throwable {
try (ICluster<IInvokableInstance> c = init(builder().withNodes(2).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).withInstanceInitializer(instanceInitializer).start())) {
c.schemaChange(withKeyspace("CREATE KEYSPACE %s2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2};"));
c.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
ForceHostLoadBalancingPolicy lbp = new ForceHostLoadBalancingPolicy();
for (int firstContact : new int[] { 1, 2 }) try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").addContactPoint("127.0.0.2").withLoadBalancingPolicy(lbp).build();
Session session = cluster.connect()) {
{
session.execute(withKeyspace("USE %s"));
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
lbp.setPrimary(firstContact);
final PreparedStatement select = session.prepare(withKeyspace("SELECT * FROM %s.tbl"));
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
lbp.setPrimary(firstContact == 1 ? 2 : 1);
session.execute(withKeyspace("USE %s2"));
try {
session.execute(select.bind());
} catch (DriverInternalError e) {
Assert.assertTrue(e.getCause().getMessage().contains("can't execute it on"));
continue;
}
fail("Should have thrown");
}
}
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class ReprepareTestBase method testReprepare.
public void testReprepare(BiConsumer<ClassLoader, Integer> instanceInitializer, ReprepareTestConfiguration... configs) throws Throwable {
try (ICluster<IInvokableInstance> c = init(builder().withNodes(2).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).withInstanceInitializer(instanceInitializer).start())) {
ForceHostLoadBalancingPolicy lbp = new ForceHostLoadBalancingPolicy();
c.schemaChange(withKeyspace("CREATE TABLE %s.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
for (ReprepareTestConfiguration config : configs) {
// 1 has old behaviour
for (int firstContact : new int[] { 1, 2 }) {
try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").addContactPoint("127.0.0.2").withLoadBalancingPolicy(lbp).build();
Session session = cluster.connect()) {
lbp.setPrimary(firstContact);
final PreparedStatement select = session.prepare(withKeyspace("SELECT * FROM %s.tbl"));
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
lbp.setPrimary(firstContact == 1 ? 2 : 1);
if (config.withUse)
session.execute(withKeyspace("USE %s"));
// Re-preparing on the node
if (!config.skipBrokenBehaviours && firstContact == 1)
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
lbp.setPrimary(firstContact);
// Re-preparing on the node with old behaviour will break no matter where the statement was initially prepared
if (!config.skipBrokenBehaviours)
session.execute(select.bind());
c.stream().forEach((i) -> i.runOnInstance(QueryProcessor::clearPreparedStatementsCache));
}
}
}
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK 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.Feature.NETWORK in project cassandra by apache.
the class RepairOperationalTest method compactionBehindTest.
@Test
public void compactionBehindTest() throws IOException {
try (Cluster cluster = init(Cluster.build(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(ByteBuddyHelper::install).start())) {
cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int primary key, x int)");
for (int i = 0; i < 10; i++) cluster.coordinator(1).execute("insert into " + KEYSPACE + ".tbl (id, x) VALUES (?,?)", ConsistencyLevel.ALL, i, i);
cluster.forEach(i -> i.flush(KEYSPACE));
cluster.forEach(i -> i.nodetoolResult("repair", "--full").asserts().success());
cluster.get(2).runOnInstance(() -> {
ByteBuddyHelper.pendingCompactions = 1000;
DatabaseDescriptor.setRepairPendingCompactionRejectThreshold(500);
});
// make sure repair gets rejected on both nodes if pendingCompactions > threshold:
cluster.forEach(i -> i.nodetoolResult("repair", "--full").asserts().failure());
cluster.get(2).runOnInstance(() -> ByteBuddyHelper.pendingCompactions = 499);
cluster.forEach(i -> i.nodetoolResult("repair", "--full").asserts().success());
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class NetstatsRepairStreamingTest method executeTest.
private void executeTest(boolean compressionEnabled) throws Exception {
final ExecutorService executorService = Executors.newFixedThreadPool(1);
try (final Cluster cluster = Cluster.build().withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(2, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL).set("stream_throughput_outbound", "122KiB/s").set("compaction_throughput", "1MiB/s").set("stream_entire_sstables", false)).start()) {
final IInvokableInstance node1 = cluster.get(1);
final IInvokableInstance node2 = cluster.get(2);
createTable(cluster, 1, compressionEnabled);
node1.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
node2.nodetoolResult("disableautocompaction", "netstats_test").asserts().success();
populateData(compressionEnabled);
node1.flush("netstats_test");
node2.flush("netstats_test");
// change RF from 1 to 2 so we need to repair it, repairing will causes streaming shown in netstats
changeReplicationFactor();
final Future<NetstatResults> resultsFuture1 = executorService.submit(new NetstatsCallable(node1));
node1.nodetoolResult("repair", "netstats_test").asserts().success();
final NetstatResults results = resultsFuture1.get(1, MINUTES);
results.assertSuccessful();
NetstatsOutputParser.validate(NetstatsOutputParser.parse(results));
}
}
Aggregations