use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class ClearSnapshotTest method testSeqClearsSnapshot.
@Test
public void testSeqClearsSnapshot() throws IOException, TimeoutException {
try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(BB::install).start())) {
cluster.schemaChange(withKeyspace("create table %s.tbl (id int primary key, x int)"));
for (int i = 0; i < 10; i++) cluster.get(1).executeInternal(withKeyspace("insert into %s.tbl (id, x) values (?, ?)"), i, i);
cluster.get(1).nodetoolResult("repair", "-seq", "-full", KEYSPACE).asserts().success();
cluster.get(1).logs().watchFor("Clearing snapshot");
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class ClearSnapshotTest method clearSnapshotSlowTest.
@Test
public void clearSnapshotSlowTest() throws IOException, InterruptedException, ExecutionException {
try (Cluster cluster = init(Cluster.build(3).withConfig(config -> config.with(GOSSIP).with(NETWORK)).withInstanceInitializer(BB::install).start())) {
int tableCount = 50;
for (int i = 0; i < tableCount; i++) {
String ksname = "ks" + i;
cluster.schemaChange("create keyspace " + ksname + " with replication = {'class': 'SimpleStrategy', 'replication_factor': 3}");
cluster.schemaChange("create table " + ksname + ".tbl (id int primary key, t int)");
cluster.get(1).executeInternal("insert into " + ksname + ".tbl (id , t) values (?, ?)", i, i);
cluster.forEach((node) -> node.flush(ksname));
}
List<Thread> repairThreads = new ArrayList<>();
for (int i = 0; i < tableCount; i++) {
String ksname = "ks" + i;
Thread t = new Thread(() -> cluster.get(1).nodetoolResult("repair", "-full", ksname).asserts().success());
t.start();
repairThreads.add(t);
}
AtomicBoolean gotExc = new AtomicBoolean(false);
AtomicBoolean exit = new AtomicBoolean(false);
Thread reads = new Thread(() -> {
while (!exit.get()) {
try {
cluster.coordinator(1).execute("select * from ks1.tbl where id = 5", ConsistencyLevel.QUORUM);
Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
} catch (Exception e) {
if (!gotExc.get())
logger.error("Unexpected exception querying table ks1.tbl", e);
gotExc.set(true);
}
}
});
reads.start();
long activeRepairs;
do {
activeRepairs = cluster.get(1).callOnInstance(() -> ActiveRepairService.instance.parentRepairSessionCount());
Thread.sleep(50);
} while (activeRepairs < 35);
cluster.setUncaughtExceptionsFilter((t) -> t.getMessage() != null && t.getMessage().contains("Parent repair session with id"));
cluster.get(2).shutdown().get();
repairThreads.forEach(t -> {
try {
t.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
exit.set(true);
reads.join();
assertFalse(gotExc.get());
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class GossipTest method testPreventEnablingGossipDuringMove.
@Test
public void testPreventEnablingGossipDuringMove() throws Exception {
try (Cluster cluster = builder().withNodes(2).withConfig(config -> config.with(GOSSIP).with(NETWORK)).start()) {
cluster.get(1).runOnInstance(() -> {
StorageService.instance.stopGossiping();
StorageService.instance.setMovingModeUnsafe();
try {
StorageService.instance.startGossiping();
Assert.fail("startGossiping did not fail!");
} catch (Exception ex) {
Assert.assertSame(ex.getClass(), IllegalStateException.class);
Assert.assertEquals(ex.getMessage(), "Unable to start gossip because the node is not in the normal state.");
}
});
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class GossipTest method nodeDownDuringMove.
@Test
public void nodeDownDuringMove() throws Throwable {
int liveCount = 1;
try (Cluster cluster = Cluster.build(2 + liveCount).withConfig(config -> config.with(NETWORK).with(GOSSIP)).createWithoutStarting()) {
int fail = liveCount + 1;
int late = fail + 1;
for (int i = 1; i <= liveCount; ++i) cluster.get(i).startup();
cluster.get(fail).startup();
Collection<String> expectTokens = cluster.get(fail).callsOnInstance(() -> StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()).stream().map(Object::toString).collect(Collectors.toList())).call();
InetSocketAddress failAddress = cluster.get(fail).broadcastAddress();
// wait for NORMAL state
for (int i = 1; i <= liveCount; ++i) {
cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
EndpointState ep;
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("NORMAL")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10L));
}).accept(failAddress);
}
// set ourselves to MOVING, and wait for it to propagate
cluster.get(fail).runOnInstance(() -> {
Token token = Iterables.getFirst(StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()), null);
Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS_WITH_PORT, StorageService.instance.valueFactory.moving(token));
});
for (int i = 1; i <= liveCount; ++i) {
cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
EndpointState ep;
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || (ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING"))) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
}).accept(failAddress);
}
cluster.get(fail).shutdown(false).get();
cluster.get(late).startup();
cluster.get(late).acceptsOnInstance((InetSocketAddress address) -> {
EndpointState ep;
InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
}).accept(failAddress);
Collection<String> tokens = cluster.get(late).appliesOnInstance((InetSocketAddress address) -> StorageService.instance.getTokenMetadata().getTokens(toCassandraInetAddressAndPort(address)).stream().map(Object::toString).collect(Collectors.toList())).apply(failAddress);
Assert.assertEquals(expectTokens, tokens);
}
}
use of org.apache.cassandra.distributed.api.Feature.NETWORK in project cassandra by apache.
the class HintedHandoffAddRemoveNodesTest method shouldBootstrapWithHintsOutstanding.
@Ignore
@Test
public void shouldBootstrapWithHintsOutstanding() throws Exception {
try (Cluster cluster = builder().withNodes(3).withTokenSupplier(TokenSupplier.evenlyDistributedTokens(4)).withNodeIdTopology(NetworkTopology.singleDcNetworkTopology(4, "dc0", "rack0")).withConfig(config -> config.with(NETWORK, GOSSIP, NATIVE_PROTOCOL)).start()) {
cluster.schemaChange(withKeyspace("CREATE KEYSPACE %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2}"));
cluster.schemaChange(withKeyspace("CREATE TABLE %s.boot_hint_test (key int PRIMARY KEY, value int)"));
cluster.get(3).shutdown().get();
// Write data using the second node as the coordinator...
populate(cluster, "boot_hint_test", 2, 0, 128, ConsistencyLevel.ONE);
Long totalHints = countTotalHints(cluster);
// ...and verify that we've accumulated hints intended for node 3, which is down.
assertThat(totalHints).isGreaterThan(0);
// Bootstrap a new/4th node into the cluster...
bootstrapAndJoinNode(cluster);
// ...and verify that all data is available.
verify(cluster, "boot_hint_test", 4, 0, 128, ConsistencyLevel.ONE);
// Finally, bring node 3 back up and verify that all hints were delivered.
cluster.get(3).startup();
await().atMost(30, SECONDS).pollDelay(3, SECONDS).until(() -> count(cluster, "boot_hint_test", 3).equals(totalHints));
verify(cluster, "boot_hint_test", 3, 0, 128, ConsistencyLevel.ONE);
verify(cluster, "boot_hint_test", 3, 0, 128, ConsistencyLevel.TWO);
}
}
Aggregations