Search in sources :

Example 16 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class DistributedTestSnitch method toCassandraInetAddressAndPort.

public static InetAddressAndPort toCassandraInetAddressAndPort(InetSocketAddress addressAndPort) {
    InetAddressAndPort m = cacheInverse.get(addressAndPort);
    if (m == null) {
        m = InetAddressAndPort.getByAddressOverrideDefaults(addressAndPort.getAddress(), addressAndPort.getPort());
        cache.put(m, addressAndPort);
    }
    return m;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort)

Example 17 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class SimulatedAction method applyToMessage.

Action applyToMessage(IInvokableInstance from, IInvokableInstance to, IMessage message) {
    Executor executor = to.executorFor(message.verb());
    if (executor instanceof ImmediateExecutor)
        executor = to.executor();
    InterceptedExecution.InterceptedTaskExecution task = new InterceptedRunnableExecution((InterceptingExecutor) executor, () -> to.receiveMessageWithInvokingThread(message));
    Verb verb = Verb.fromId(message.verb());
    Modifiers self = verbModifiers.getOrDefault(verb, NONE);
    int fromNum = from.config().num();
    int toNum = to.config().num();
    Deliver deliver;
    if (is(Modifier.RELIABLE) || self.is(Modifier.RELIABLE))
        deliver = DELIVER;
    else
        deliver = simulated.futureScheduler.shouldDeliver(fromNum, toNum);
    Action action;
    switch(deliver) {
        default:
            throw new AssertionError();
        case DELIVER:
            {
                Object description = lazy(() -> String.format("%s(%d) from %s to %s", Verb.fromId(message.verb()), message.id(), message.from(), to.broadcastAddress()));
                OrderOn orderOn = task.executor.orderAppliesAfterScheduling();
                action = applyTo(description, MESSAGE, orderOn, self, verb, task);
                action.setDeadline(simulated.futureScheduler.messageDeadlineNanos(fromNum, toNum));
                break;
            }
        case FAILURE:
        case TIMEOUT:
            {
                task.cancel();
                self = DROP.with(self);
                InetSocketAddress failedOn;
                IInvokableInstance notify;
                if (verb.isResponse()) {
                    failedOn = from.broadcastAddress();
                    notify = to;
                } else {
                    failedOn = to.broadcastAddress();
                    notify = from;
                }
                InterceptedExecution.InterceptedTaskExecution failTask = new InterceptedRunnableExecution((InterceptingExecutor) notify.executorFor(verb.id), () -> notify.unsafeApplyOnThisThread((socketAddress, id, isTimeout) -> {
                    InetAddressAndPort address = InetAddressAndPort.getByAddress(socketAddress);
                    RequestCallbacks.CallbackInfo callback = instance().callbacks.remove(id, address);
                    if (callback != null) {
                        RequestCallback<?> invokeOn = (RequestCallback<?>) callback.callback;
                        RequestFailureReason reason = isTimeout ? RequestFailureReason.TIMEOUT : RequestFailureReason.UNKNOWN;
                        invokeOn.onFailure(address, reason);
                    }
                    return null;
                }, failedOn, message.id(), deliver == TIMEOUT));
                Object description = (lazy(() -> String.format("Report Timeout of %s(%d) from %s to %s", Verb.fromId(message.verb()), message.id(), failedOn, notify.broadcastAddress())));
                OrderOn orderOn = failTask.executor.orderAppliesAfterScheduling();
                action = applyTo(description, MESSAGE, orderOn, self, failTask);
                switch(deliver) {
                    default:
                        throw new AssertionError();
                    case TIMEOUT:
                        long expiresAfterNanos = from.unsafeApplyOnThisThread(id -> Verb.fromId(id).expiresAfterNanos(), (verb.isResponse() ? forVerb : verb).id);
                        action.setDeadline(simulated.futureScheduler.messageTimeoutNanos(expiresAfterNanos));
                        break;
                    case FAILURE:
                        action.setDeadline(simulated.futureScheduler.messageFailureNanos(toNum, fromNum));
                        break;
                }
                break;
            }
    }
    return action;
}
Also used : Actions(org.apache.cassandra.simulator.Actions) START_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_TASK) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) OrderOn(org.apache.cassandra.simulator.OrderOn) DELIVER(org.apache.cassandra.simulator.FutureActionScheduler.Deliver.DELIVER) TASK(org.apache.cassandra.simulator.systems.SimulatedAction.Kind.TASK) LazyToString.lazy(org.apache.cassandra.utils.LazyToString.lazy) START_DAEMON_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_DAEMON_TASK) InterceptedRunnableExecution(org.apache.cassandra.simulator.systems.InterceptedExecution.InterceptedRunnableExecution) ActionList(org.apache.cassandra.simulator.ActionList) RequestCallbacks(org.apache.cassandra.net.RequestCallbacks) Deliver(org.apache.cassandra.simulator.FutureActionScheduler.Deliver) IMessage(org.apache.cassandra.distributed.api.IMessage) ArrayList(java.util.ArrayList) MESSAGE(org.apache.cassandra.simulator.systems.SimulatedAction.Kind.MESSAGE) UNBOUNDED_WAIT(org.apache.cassandra.simulator.systems.InterceptedWait.Kind.UNBOUNDED_WAIT) SIMULATION(org.apache.cassandra.utils.Shared.Scope.SIMULATION) Map(java.util.Map) WAKE_UP_THREAD(org.apache.cassandra.simulator.Action.Modifiers.WAKE_UP_THREAD) TIMEOUT(org.apache.cassandra.simulator.FutureActionScheduler.Deliver.TIMEOUT) MessagingService.instance(org.apache.cassandra.net.MessagingService.instance) START_THREAD(org.apache.cassandra.simulator.Action.Modifiers.START_THREAD) Action(org.apache.cassandra.simulator.Action) Nullable(javax.annotation.Nullable) EnumMap(java.util.EnumMap) Executor(java.util.concurrent.Executor) NONE(org.apache.cassandra.simulator.Action.Modifiers.NONE) DROP(org.apache.cassandra.simulator.Action.Modifiers.DROP) Verb(org.apache.cassandra.net.Verb) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) RequestCallback(org.apache.cassandra.net.RequestCallback) START_INFINITE_LOOP(org.apache.cassandra.simulator.Action.Modifiers.START_INFINITE_LOOP) InetSocketAddress(java.net.InetSocketAddress) START_SCHEDULED_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_SCHEDULED_TASK) START_TIMEOUT_TASK(org.apache.cassandra.simulator.Action.Modifiers.START_TIMEOUT_TASK) List(java.util.List) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) TriggerListener(org.apache.cassandra.simulator.systems.InterceptedWait.TriggerListener) SCHEDULED_TIMEOUT(org.apache.cassandra.simulator.systems.SimulatedAction.Kind.SCHEDULED_TIMEOUT) Shared(org.apache.cassandra.utils.Shared) LOG(org.apache.cassandra.simulator.Debug.Info.LOG) ImmediateExecutor(org.apache.cassandra.concurrent.ImmediateExecutor) Collections(java.util.Collections) LazyToString(org.apache.cassandra.utils.LazyToString) Deliver(org.apache.cassandra.simulator.FutureActionScheduler.Deliver) Action(org.apache.cassandra.simulator.Action) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) InterceptedRunnableExecution(org.apache.cassandra.simulator.systems.InterceptedExecution.InterceptedRunnableExecution) InetSocketAddress(java.net.InetSocketAddress) OrderOn(org.apache.cassandra.simulator.OrderOn) Executor(java.util.concurrent.Executor) ImmediateExecutor(org.apache.cassandra.concurrent.ImmediateExecutor) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) RequestCallback(org.apache.cassandra.net.RequestCallback) ImmediateExecutor(org.apache.cassandra.concurrent.ImmediateExecutor) Verb(org.apache.cassandra.net.Verb) RequestCallbacks(org.apache.cassandra.net.RequestCallbacks)

Example 18 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class CompactionIteratorTest method duplicateRowsTest.

@Test
public void duplicateRowsTest() throws Throwable {
    System.setProperty("cassandra.diagnostic_snapshot_interval_nanos", "0");
    // Create a table and insert some data. The actual rows read in the test will be synthetic
    // but this creates an sstable on disk to be snapshotted.
    createTable("CREATE TABLE %s (pk text, ck1 int, ck2 int, v int, PRIMARY KEY (pk, ck1, ck2))");
    for (int i = 0; i < 10; i++) execute("insert into %s (pk, ck1, ck2, v) values (?, ?, ?, ?)", "key", i, i, i);
    getCurrentColumnFamilyStore().forceBlockingFlush();
    DatabaseDescriptor.setSnapshotOnDuplicateRowDetection(true);
    TableMetadata metadata = getCurrentColumnFamilyStore().metadata();
    final HashMap<InetAddressAndPort, Message<?>> sentMessages = new HashMap<>();
    MessagingService.instance().outboundSink.add((message, to) -> {
        sentMessages.put(to, message);
        return false;
    });
    // no duplicates
    sentMessages.clear();
    iterate(makeRow(metadata, 0, 0), makeRow(metadata, 0, 1), makeRow(metadata, 0, 2));
    assertCommandIssued(sentMessages, false);
    // now test with a duplicate row and see that we issue a snapshot command
    sentMessages.clear();
    iterate(makeRow(metadata, 0, 0), makeRow(metadata, 0, 1), makeRow(metadata, 0, 1));
    assertCommandIssued(sentMessages, true);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Message(org.apache.cassandra.net.Message) Test(org.junit.Test)

Example 19 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class CancelCompactionsTest method testAnticompaction.

@Test
public void testAnticompaction() throws InterruptedException, ExecutionException {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    List<SSTableReader> sstables = createSSTables(cfs, 10, 0);
    List<SSTableReader> alreadyRepairedSSTables = createSSTables(cfs, 10, 10);
    for (SSTableReader sstable : alreadyRepairedSSTables) AbstractPendingRepairTest.mutateRepaired(sstable, System.currentTimeMillis());
    assertEquals(20, cfs.getLiveSSTables().size());
    List<TestCompactionTask> tcts = new ArrayList<>();
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(0, 2))));
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(3, 4))));
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(5, 7))));
    tcts.add(new TestCompactionTask(cfs, new HashSet<>(sstables.subList(8, 9))));
    List<TestCompactionTask> nonAffectedTcts = new ArrayList<>();
    nonAffectedTcts.add(new TestCompactionTask(cfs, new HashSet<>(alreadyRepairedSSTables)));
    try {
        tcts.forEach(TestCompactionTask::start);
        nonAffectedTcts.forEach(TestCompactionTask::start);
        List<CompactionInfo.Holder> activeCompactions = getActiveCompactionsForTable(cfs);
        assertEquals(5, activeCompactions.size());
        // make sure that sstables are fully contained so that the metadata gets mutated
        Range<Token> range = new Range<>(token(-1), token(49));
        UUID prsid = UUID.randomUUID();
        ActiveRepairService.instance.registerParentRepairSession(prsid, InetAddressAndPort.getLocalHost(), Collections.singletonList(cfs), Collections.singleton(range), true, 1, true, PreviewKind.NONE);
        InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort();
        RangesAtEndpoint rae = RangesAtEndpoint.builder(local).add(new Replica(local, range, true)).build();
        PendingAntiCompaction pac = new PendingAntiCompaction(prsid, Collections.singleton(cfs), rae, Executors.newSingleThreadExecutor(), () -> false);
        Future<?> fut = pac.run();
        Thread.sleep(600);
        List<TestCompactionTask> toAbort = new ArrayList<>();
        for (CompactionInfo.Holder holder : getActiveCompactionsForTable(cfs)) {
            if (holder.getCompactionInfo().getSSTables().stream().anyMatch(sstable -> sstable.intersects(Collections.singleton(range)) && !sstable.isRepaired() && !sstable.isPendingRepair())) {
                assertTrue(holder.isStopRequested());
                for (TestCompactionTask tct : tcts) if (tct.sstables.equals(holder.getCompactionInfo().getSSTables()))
                    toAbort.add(tct);
            } else
                assertFalse(holder.isStopRequested());
        }
        assertEquals(2, toAbort.size());
        toAbort.forEach(TestCompactionTask::abort);
        fut.get();
        for (SSTableReader sstable : sstables) assertTrue(!sstable.intersects(Collections.singleton(range)) || sstable.isPendingRepair());
    } finally {
        tcts.forEach(TestCompactionTask::abort);
        nonAffectedTcts.forEach(TestCompactionTask::abort);
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) Replica(org.apache.cassandra.locator.Replica) PendingAntiCompaction(org.apache.cassandra.db.repair.PendingAntiCompaction) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class SystemKeyspace method loadTokens.

/**
 * Return a map of stored tokens to IP addresses
 */
public static SetMultimap<InetAddressAndPort, Token> loadTokens() {
    SetMultimap<InetAddressAndPort, Token> tokenMap = HashMultimap.create();
    for (UntypedResultSet.Row row : executeInternal("SELECT peer, peer_port, tokens FROM system." + PEERS_V2)) {
        InetAddress address = row.getInetAddress("peer");
        Integer port = row.getInt("peer_port");
        InetAddressAndPort peer = InetAddressAndPort.getByAddressOverrideDefaults(address, port);
        if (row.has("tokens"))
            tokenMap.putAll(peer, deserializeTokens(row.getSet("tokens", UTF8Type.instance)));
    }
    return tokenMap;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) InetAddress(java.net.InetAddress)

Aggregations

InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)281 Test (org.junit.Test)129 Token (org.apache.cassandra.dht.Token)65 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)43 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)39 Range (org.apache.cassandra.dht.Range)28 Replica (org.apache.cassandra.locator.Replica)25 ArrayList (java.util.ArrayList)24 ByteBuffer (java.nio.ByteBuffer)23 HashMap (java.util.HashMap)23 UUID (java.util.UUID)22 HashSet (java.util.HashSet)20 Map (java.util.Map)20 Mutation (org.apache.cassandra.db.Mutation)17 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)17 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)16 VisibleForTesting (com.google.common.annotations.VisibleForTesting)15 IPartitioner (org.apache.cassandra.dht.IPartitioner)15 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)15