use of org.apache.cassandra.simulator.ActionList in project cassandra by apache.
the class KeyspaceActions method plan.
public ActionPlan plan() {
ActionList pre = ActionList.of(pre(createKeyspaceCql(keyspace), createTableCql));
ActionList interleave = stream();
ActionList post = ActionList.empty();
return new ActionPlan(pre, singletonList(interleave), post);
}
use of org.apache.cassandra.simulator.ActionList in project cassandra by apache.
the class SimulationTestBase method simulate.
public static void simulate(Function<DTestClusterSimulation, ActionList> init, Function<DTestClusterSimulation, ActionList> test, Consumer<ClusterSimulation.Builder<DTestClusterSimulation>> configure) throws IOException {
SimulationRunner.beforeAll();
long seed = System.currentTimeMillis();
RandomSource random = new RandomSource.Default();
random.reset(seed);
class Factory extends ClusterSimulation.Builder<DTestClusterSimulation> {
public ClusterSimulation<DTestClusterSimulation> create(long seed) throws IOException {
return new ClusterSimulation<>(random, seed, 1, this, (c) -> {
}, (simulated, scheduler, cluster, options) -> new DTestClusterSimulation(simulated, scheduler, cluster) {
protected ActionList initialize() {
return init.apply(this);
}
protected ActionList execute() {
return test.apply(this);
}
});
}
}
Factory factory = new Factory();
configure.accept(factory);
try (ClusterSimulation<?> cluster = factory.create(seed)) {
try {
cluster.simulation.run();
} catch (Throwable t) {
throw new AssertionError(String.format("Failed on seed %s", Long.toHexString(seed)), t);
}
}
}
use of org.apache.cassandra.simulator.ActionList in project cassandra by apache.
the class OnClusterUpdateGossip method safeInvalidate.
@Override
protected Throwable safeInvalidate(boolean isCancellation) {
ActionList list = cancel;
if (list == null)
return null;
cancel = null;
return list.safeForEach(Action::invalidate);
}
use of org.apache.cassandra.simulator.ActionList 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.simulator.ActionList 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