Search in sources :

Example 1 with ActionList

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);
}
Also used : ActionList(org.apache.cassandra.simulator.ActionList) ActionPlan(org.apache.cassandra.simulator.ActionPlan)

Example 2 with ActionList

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);
        }
    }
}
Also used : ClusterSimulation(org.apache.cassandra.simulator.ClusterSimulation) RandomSource(org.apache.cassandra.simulator.RandomSource) ExecutorFactory(org.apache.cassandra.concurrent.ExecutorFactory) InterceptingExecutorFactory(org.apache.cassandra.simulator.systems.InterceptingExecutorFactory) ActionList(org.apache.cassandra.simulator.ActionList)

Example 3 with ActionList

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);
}
Also used : ReliableAction(org.apache.cassandra.simulator.Actions.ReliableAction) Action(org.apache.cassandra.simulator.Action) SimulatedAction(org.apache.cassandra.simulator.systems.SimulatedAction) ActionList(org.apache.cassandra.simulator.ActionList)

Example 4 with ActionList

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)));
}
Also used : LazyToString.lazy(org.apache.cassandra.utils.LazyToString.lazy) NONE(org.apache.cassandra.simulator.Action.Modifiers.NONE) ReliableAction(org.apache.cassandra.simulator.Actions.ReliableAction) Range(org.apache.cassandra.dht.Range) StorageService(org.apache.cassandra.service.StorageService) ActionList(org.apache.cassandra.simulator.ActionList) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) Replica(org.apache.cassandra.locator.Replica) AbstractMap(java.util.AbstractMap) List(java.util.List) Token(org.apache.cassandra.dht.Token) FBUtilities.getBroadcastAddressAndPort(org.apache.cassandra.utils.FBUtilities.getBroadcastAddressAndPort) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Map(java.util.Map) STRICT(org.apache.cassandra.simulator.Action.Modifiers.STRICT) Cluster(org.apache.cassandra.distributed.Cluster) Keyspace(org.apache.cassandra.db.Keyspace) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) InetSocketAddress(java.net.InetSocketAddress) UUID(java.util.UUID)

Example 5 with ActionList

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)));
}
Also used : SimulatedActionConsumer(org.apache.cassandra.simulator.systems.SimulatedActionConsumer) RELIABLE_NO_TIMEOUTS(org.apache.cassandra.simulator.Action.Modifiers.RELIABLE_NO_TIMEOUTS) FBUtilities(org.apache.cassandra.utils.FBUtilities) LazyToString.lazy(org.apache.cassandra.utils.LazyToString.lazy) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Future(org.apache.cassandra.utils.concurrent.Future) StorageService(org.apache.cassandra.service.StorageService) ActionList(org.apache.cassandra.simulator.ActionList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Future(org.apache.cassandra.utils.concurrent.Future) Supplier(java.util.function.Supplier) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

ActionList (org.apache.cassandra.simulator.ActionList)5 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)2 StorageService (org.apache.cassandra.service.StorageService)2 ReliableAction (org.apache.cassandra.simulator.Actions.ReliableAction)2 LazyToString.lazy (org.apache.cassandra.utils.LazyToString.lazy)2 InetSocketAddress (java.net.InetSocketAddress)1 AbstractMap (java.util.AbstractMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 ExecutorFactory (org.apache.cassandra.concurrent.ExecutorFactory)1 Keyspace (org.apache.cassandra.db.Keyspace)1 SystemKeyspace (org.apache.cassandra.db.SystemKeyspace)1 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1 Cluster (org.apache.cassandra.distributed.Cluster)1 Replica (org.apache.cassandra.locator.Replica)1