use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class PartitionDenylistTest method checkTimerRetriesLoad.
@Test
public void checkTimerRetriesLoad() throws IOException {
int nodeCount = 3;
try (Cluster cluster = Cluster.build(nodeCount).withConfig(config -> config.with(NETWORK).with(GOSSIP).set("partition_denylist_enabled", true).set("denylist_initial_load_retry", "1s")).createWithoutStarting()) {
// Starting without networking enabled in the hope it doesn't trigger
// node lifecycle events when nodes start up.
cluster.get(1).startup();
cluster.get(1).runOnInstance(PartitionDenylistTest::checkTimerActive);
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class GossipSettlesTest method testGossipSettles.
@Test
public void testGossipSettles() throws Throwable {
/* Use withSubnet(1) to prove seed provider is set correctly - without the fix to pass a seed provider, this test fails */
try (Cluster cluster = builder().withNodes(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withSubnet(1).start()) {
// Verify the 4.0 WithPort versions of status reporting methods match their InetAddress
// counterparts. Disable Gossip first to prevent any bump in heartbeats that would
// invalidate the comparison. Compare the newer WithPort versions by adding the
// storage port to IP addresses in keys/values/strings as appropriate.
cluster.forEach(i -> i.runOnInstance(() -> {
Gossiper.instance.stop();
}));
cluster.get(1).runOnInstance(() -> {
// First prove that the storage port is added
Assert.assertEquals("stuff 127.0.0.1:7012 morestuff 127.0.0.2:7012", addStoragePortToIP("stuff 127.0.0.1 morestuff 127.0.0.2"));
FailureDetector fd = ((FailureDetector) FailureDetector.instance);
Assert.assertEquals(addStoragePortToInstanceName(fd.getAllEndpointStates(false)), fd.getAllEndpointStates(true));
Assert.assertEquals(addPortToKeys(fd.getSimpleStates()), fd.getSimpleStatesWithPort());
StorageProxy sp = StorageProxy.instance;
Assert.assertEquals(addPortToSchemaVersions(sp.getSchemaVersions()), sp.getSchemaVersionsWithPort());
StorageService ss = StorageService.instance;
Assert.assertEquals(addPortToValues(ss.getTokenToEndpointMap()), ss.getTokenToEndpointWithPortMap());
Assert.assertEquals(addPortToKeys(ss.getEndpointToHostId()), ss.getEndpointWithPortToHostId());
Assert.assertEquals(addPortToValues(ss.getHostIdToEndpoint()), ss.getHostIdToEndpointWithPort());
Assert.assertEquals(addPortToKeys(ss.getLoadMap()), ss.getLoadMapWithPort());
Assert.assertEquals(addPortToList(ss.getLiveNodes()), ss.getLiveNodesWithPort());
List<String> naturalEndpointsAddedPort = ss.getNaturalEndpoints(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, SystemDistributedKeyspace.VIEW_BUILD_STATUS, "dummy").stream().map(e -> addStoragePortToIP(e.getHostAddress())).collect(Collectors.toList());
Assert.assertEquals(naturalEndpointsAddedPort, ss.getNaturalEndpointsWithPort(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, SystemDistributedKeyspace.VIEW_BUILD_STATUS, "dummy"));
naturalEndpointsAddedPort = ss.getNaturalEndpoints(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, ByteBufferUtil.EMPTY_BYTE_BUFFER).stream().map(e -> addStoragePortToIP(e.getHostAddress())).collect(Collectors.toList());
Assert.assertEquals(naturalEndpointsAddedPort, ss.getNaturalEndpointsWithPort(SchemaConstants.DISTRIBUTED_KEYSPACE_NAME, ByteBufferUtil.EMPTY_BYTE_BUFFER));
// Difference in key type... convert to String and add the port to the older format
Map<String, Float> getOwnershipKeyAddedPort = ss.getOwnership().entrySet().stream().collect(Collectors.<Map.Entry<InetAddress, Float>, String, Float>toMap(e -> addStoragePortToIP(e.getKey().toString()), Map.Entry::getValue));
Assert.assertEquals(getOwnershipKeyAddedPort, ss.getOwnershipWithPort());
MessagingService ms = MessagingService.instance();
Assert.assertEquals(addPortToKeys(ms.getTimeoutsPerHost()), ms.getTimeoutsPerHostWithPort());
Assert.assertEquals(addPortToKeys(ms.getLargeMessagePendingTasks()), ms.getLargeMessagePendingTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getLargeMessageCompletedTasks()), ms.getLargeMessageCompletedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getLargeMessageDroppedTasks()), ms.getLargeMessageDroppedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getSmallMessagePendingTasks()), ms.getSmallMessagePendingTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getSmallMessageCompletedTasks()), ms.getSmallMessageCompletedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getSmallMessageDroppedTasks()), ms.getSmallMessageDroppedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getGossipMessagePendingTasks()), ms.getGossipMessagePendingTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getGossipMessageCompletedTasks()), ms.getGossipMessageCompletedTasksWithPort());
Assert.assertEquals(addPortToKeys(ms.getGossipMessageDroppedTasks()), ms.getGossipMessageDroppedTasksWithPort());
});
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class PrepareBatchStatementsTest method testPreparedBatch.
@Test
public void testPreparedBatch() throws Exception {
try (ICluster<IInvokableInstance> c = init(builder().withNodes(1).withConfig(config -> config.with(GOSSIP, NETWORK, NATIVE_PROTOCOL)).start())) {
try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint("127.0.0.1").build();
Session s = cluster.connect()) {
c.schemaChange(withKeyspace("CREATE KEYSPACE ks1 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"));
c.schemaChange(withKeyspace("CREATE TABLE ks1.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
c.schemaChange(withKeyspace("CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"));
c.schemaChange(withKeyspace("CREATE TABLE ks2.tbl (pk int, ck int, v int, PRIMARY KEY (pk, ck));"));
String batch1 = "BEGIN BATCH\n" + "UPDATE ks1.tbl SET v = ? where pk = ? and ck = ?;\n" + "UPDATE ks2.tbl SET v = ? where pk = ? and ck = ?;\n" + "APPLY BATCH;";
String batch2 = "BEGIN BATCH\n" + "INSERT INTO ks1.tbl (pk, ck, v) VALUES (?, ?, ?);\n" + "INSERT INTO tbl (pk, ck, v) VALUES (?, ?, ?);\n" + "APPLY BATCH;";
PreparedStatement prepared;
prepared = s.prepare(batch1);
s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
c.get(1).runOnInstance(() -> {
// no USE here, only a fully qualified batch - should get stored ONCE
List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
assertEquals(Lists.newArrayList(batch1), stmts);
QueryProcessor.clearPreparedStatements(false);
});
s.execute("use ks2");
prepared = s.prepare(batch1);
s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
c.get(1).runOnInstance(() -> {
// after USE, fully qualified - should get stored twice! Once with null keyspace (new behaviour) once with ks2 keyspace (old behaviour)
List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
assertEquals(Lists.newArrayList(batch1, batch1), stmts);
QueryProcessor.clearPreparedStatements(false);
});
prepared = s.prepare(batch2);
s.execute(prepared.bind(1, 1, 1, 1, 1, 1));
c.get(1).runOnInstance(() -> {
// after USE, should get stored twice, once with keyspace, once without
List<String> stmts = StorageService.instance.getPreparedStatements().stream().map(p -> p.right).collect(Collectors.toList());
assertEquals(Lists.newArrayList(batch2, batch2), stmts);
QueryProcessor.clearPreparedStatements(false);
});
}
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK 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