use of org.apache.cassandra.distributed.api.IInvokableInstance 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.IInvokableInstance in project cassandra by apache.
the class BootstrapBinaryDisabledTest method bootstrap.
private static void bootstrap(Cluster cluster, Map<String, Object> config, boolean isWriteSurvey) throws TimeoutException {
IInstanceConfig nodeConfig = cluster.newInstanceConfig();
nodeConfig.set("auto_bootstrap", true);
config.forEach(nodeConfig::set);
// TODO can we make this more isolated?
System.setProperty("cassandra.ring_delay_ms", "5000");
if (isWriteSurvey)
System.setProperty("cassandra.write_survey", "true");
RewriteEnabled.enable();
cluster.bootstrap(nodeConfig).startup();
IInvokableInstance node = cluster.get(cluster.size());
assertLogHas(node, "Some data streaming failed");
assertLogHas(node, isWriteSurvey ? "Not starting client transports in write_survey mode as it's bootstrapping or auth is enabled" : "Node is not yet bootstrapped completely");
node.nodetoolResult("join").asserts().failure().errorContains("Cannot join the ring until bootstrap completes");
RewriteEnabled.disable();
node.nodetoolResult("bootstrap", "resume").asserts().success();
if (isWriteSurvey)
assertLogHas(node, "Not starting client transports in write_survey mode as it's bootstrapping or auth is enabled");
if (isWriteSurvey) {
node.nodetoolResult("join").asserts().success();
assertLogHas(node, "Leaving write survey mode and joining ring at operator request");
}
node.logs().watchFor("Starting listening for CQL clients");
assertBootstrapState(node, "COMPLETED");
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class OnClusterJoin method performSimple.
public ActionList performSimple() {
IInvokableInstance joinInstance = actions.cluster.get(joining);
before(joinInstance);
return ActionList.of(// setup the node's own gossip state for pending ownership, and return gossip actions to disseminate
new OnClusterUpdateGossip(actions, joining, new OnInstanceSetBootstrapping(actions, joining)), new OnInstanceSyncSchemaForBootstrap(actions, joining), // stream/repair from a peer
new OnInstanceBootstrap(actions, joinInstance), // setup the node's own gossip state for natural ownership, and return gossip actions to disseminate
new OnClusterUpdateGossip(actions, joining, new OnInstanceSetNormal(actions, joining)));
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class OnClusterReplace method performSimple.
public ActionList performSimple() {
// need to mark it as DOWN, and perhaps shut it down
Map<InetSocketAddress, IInvokableInstance> lookup = Cluster.getUniqueAddressLookup(actions.cluster);
IInvokableInstance leaveInstance = actions.cluster.get(leaving);
IInvokableInstance joinInstance = actions.cluster.get(joining);
before(leaveInstance);
UUID hostId = leaveInstance.unsafeCallOnThisThread(SystemKeyspace::getLocalHostId);
String movingToken = leaveInstance.unsafeCallOnThisThread(() -> Utils.currentToken().toString());
List<Map.Entry<String, String>> repairRanges = leaveInstance.unsafeApplyOnThisThread((String keyspaceName) -> StorageService.instance.getLocalAndPendingRanges(keyspaceName).stream().map(OnClusterReplace::toStringEntry).collect(Collectors.toList()), actions.keyspace);
int[] others = repairRanges.stream().mapToInt(repairRange -> lookup.get(leaveInstance.unsafeApplyOnThisThread((String keyspaceName, String tk) -> Keyspace.open(keyspaceName).getReplicationStrategy().getNaturalReplicasForToken(Utils.parseToken(tk)).stream().map(Replica::endpoint).filter(i -> !i.equals(getBroadcastAddressAndPort())).findFirst().orElseThrow(IllegalStateException::new), actions.keyspace, repairRange.getValue())).config().num()).toArray();
return ActionList.of(// first sync gossip so that newly joined nodes are known by all, so that when we markdown we do not throw UnavailableException
ReliableAction.transitively("Sync Gossip", () -> actions.gossipWithAll(leaving)), // "shutdown" the leaving instance
new OnClusterUpdateGossip(actions, ActionList.of(new OnInstanceMarkShutdown(actions, leaving), new OnClusterMarkDown(actions, leaving)), new OnInstanceSendShutdownToAll(actions, leaving)), new OnClusterRepairRanges(actions, others, true, false, repairRanges), // stream/repair from a peer
new OnClusterUpdateGossip(actions, joining, new OnInstanceSetBootstrapReplacing(actions, joining, leaving, hostId, movingToken)), new OnInstanceSyncSchemaForBootstrap(actions, joining), new OnInstanceBootstrap(actions, joinInstance, movingToken, true), // setup the node's own gossip state for natural ownership, and return gossip actions to disseminate
new OnClusterUpdateGossip(actions, joining, new OnInstanceSetNormal(actions, joining, hostId, movingToken)));
}
use of org.apache.cassandra.distributed.api.IInvokableInstance in project cassandra by apache.
the class OnClusterLeave method performSimple.
public ActionList performSimple() {
IInvokableInstance leaveInstance = actions.cluster.get(leaving);
before(leaveInstance);
AtomicReference<Supplier<? extends Future<?>>> preparedUnbootstrap = new AtomicReference<>();
return ActionList.of(// setup the node's own gossip state for pending ownership, and return gossip actions to disseminate
new OnClusterUpdateGossip(actions, leaving, new OnInstanceSetLeaving(actions, leaving)), new SimulatedActionConsumer<>("Prepare unbootstrap on " + leaving, RELIABLE_NO_TIMEOUTS, RELIABLE_NO_TIMEOUTS, actions, leaveInstance, ref -> ref.set(StorageService.instance.prepareUnbootstrapStreaming()), preparedUnbootstrap), new SimulatedActionConsumer<>("Execute unbootstrap on " + leaving, RELIABLE_NO_TIMEOUTS, RELIABLE_NO_TIMEOUTS, actions, leaveInstance, ref -> FBUtilities.waitOnFuture(ref.get().get()), preparedUnbootstrap), // setup the node's own gossip state for natural ownership, and return gossip actions to disseminate
new OnClusterUpdateGossip(actions, leaving, new OnInstanceSetLeft(actions, leaving)));
}
Aggregations