Search in sources :

Example 76 with InetAddressAndPort

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

the class CoordinatorSession method finalizePropose.

public synchronized Future<Void> finalizePropose() {
    Preconditions.checkArgument(allStates(State.REPAIRING));
    logger.info("Proposing finalization of repair session {}", sessionID);
    Message<RepairMessage> message = Message.out(Verb.FINALIZE_PROPOSE_MSG, new FinalizePropose(sessionID));
    for (final InetAddressAndPort participant : participants) {
        sendMessage(participant, message);
    }
    return finalizeProposeFuture;
}
Also used : RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose)

Example 77 with InetAddressAndPort

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

the class CoordinatorSession method prepare.

public Future<Void> prepare() {
    Preconditions.checkArgument(allStates(State.PREPARING));
    logger.info("Beginning prepare phase of incremental repair session {}", sessionID);
    Message<RepairMessage> message = Message.out(Verb.PREPARE_CONSISTENT_REQ, new PrepareConsistentRequest(sessionID, coordinator, participants));
    for (final InetAddressAndPort participant : participants) {
        sendMessage(participant, message);
    }
    return prepareFuture;
}
Also used : RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest)

Example 78 with InetAddressAndPort

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

the class GossipHelper method changeGossipState.

/**
 * Changes gossip state of the `peer` on `target`
 */
public static void changeGossipState(IInvokableInstance target, IInstance peer, List<VersionedApplicationState> newState) {
    InetSocketAddress addr = peer.broadcastAddress();
    UUID hostId = peer.config().hostId();
    int netVersion = peer.getMessagingVersion();
    target.runOnInstance(() -> {
        InetAddressAndPort endpoint = toCassandraInetAddressAndPort(addr);
        StorageService storageService = StorageService.instance;
        Gossiper.runInGossipStageBlocking(() -> {
            EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
            if (state == null) {
                Gossiper.instance.initializeNodeUnsafe(endpoint, hostId, netVersion, 1);
                state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
                if (state.isAlive() && !Gossiper.instance.isDeadState(state))
                    Gossiper.instance.realMarkAlive(endpoint, state);
            }
            for (VersionedApplicationState value : newState) {
                ApplicationState as = toApplicationState(value);
                VersionedValue vv = toVersionedValue(value);
                state.addApplicationState(as, vv);
                storageService.onChange(endpoint, as, vv);
            }
        });
    });
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) InetSocketAddress(java.net.InetSocketAddress) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) ApplicationState(org.apache.cassandra.gms.ApplicationState) UUID(java.util.UUID) StorageService(org.apache.cassandra.service.StorageService)

Example 79 with InetAddressAndPort

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

the class MessageFiltersTest method outboundBeforeInbound.

@Test
public void outboundBeforeInbound() throws Throwable {
    try (Cluster cluster = Cluster.create(2)) {
        InetAddressAndPort other = InetAddressAndPort.getByAddressOverrideDefaults(cluster.get(2).broadcastAddress().getAddress(), cluster.get(2).broadcastAddress().getPort());
        CountDownLatch waitForIt = new CountDownLatch(1);
        Set<Integer> outboundMessagesSeen = new HashSet<>();
        Set<Integer> inboundMessagesSeen = new HashSet<>();
        AtomicBoolean outboundAfterInbound = new AtomicBoolean(false);
        cluster.filters().outbound().verbs(Verb.ECHO_REQ.id, Verb.ECHO_RSP.id).messagesMatching((from, to, msg) -> {
            outboundMessagesSeen.add(msg.verb());
            if (inboundMessagesSeen.contains(msg.verb()))
                outboundAfterInbound.set(true);
            return false;
        }).drop();
        cluster.filters().inbound().verbs(Verb.ECHO_REQ.id, Verb.ECHO_RSP.id).messagesMatching((from, to, msg) -> {
            inboundMessagesSeen.add(msg.verb());
            return false;
        }).drop();
        cluster.filters().inbound().verbs(Verb.ECHO_RSP.id).messagesMatching((from, to, msg) -> {
            waitForIt.countDown();
            return false;
        }).drop();
        cluster.get(1).runOnInstance(() -> {
            MessagingService.instance().send(Message.out(Verb.ECHO_REQ, NoPayload.noPayload), other);
        });
        waitForIt.await();
        Assert.assertEquals(outboundMessagesSeen, inboundMessagesSeen);
        // since both are equal, only need to confirm the size of one
        Assert.assertEquals(2, outboundMessagesSeen.size());
        Assert.assertFalse("outbound message saw after inbound", outboundAfterInbound.get());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Instance(org.apache.cassandra.distributed.impl.Instance) IMessageFilters(org.apache.cassandra.distributed.api.IMessageFilters) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Arrays(java.util.Arrays) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Message(org.apache.cassandra.net.Message) IMessage(org.apache.cassandra.distributed.api.IMessage) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NoPayload(org.apache.cassandra.net.NoPayload) IIsolatedExecutor(org.apache.cassandra.distributed.api.IIsolatedExecutor) MessageFilters(org.apache.cassandra.distributed.shared.MessageFilters) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) MessagingService(org.apache.cassandra.net.MessagingService) Set(java.util.Set) ICluster(org.apache.cassandra.distributed.api.ICluster) Test(org.junit.Test) ConsistencyLevel(org.apache.cassandra.distributed.api.ConsistencyLevel) Verb(org.apache.cassandra.net.Verb) InetSocketAddress(java.net.InetSocketAddress) Sets(com.google.common.collect.Sets) CountDownLatch(java.util.concurrent.CountDownLatch) IInvokableInstance(org.apache.cassandra.distributed.api.IInvokableInstance) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) HintMessage(org.apache.cassandra.hints.HintMessage) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) ICluster(org.apache.cassandra.distributed.api.ICluster) Cluster(org.apache.cassandra.distributed.Cluster) CountDownLatch(java.util.concurrent.CountDownLatch) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 80 with InetAddressAndPort

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

the class DescribeStatementTest method testDescribeCluster.

@Test
public void testDescribeCluster() throws Throwable {
    for (String describeKeyword : new String[] { "DESCRIBE", "DESC" }) {
        assertRowsNet(executeDescribeNet(describeKeyword + " CLUSTER"), row("Test Cluster", "ByteOrderedPartitioner", DatabaseDescriptor.getEndpointSnitch().getClass().getName()));
        assertRowsNet(executeDescribeNet("system_virtual_schema", describeKeyword + " CLUSTER"), row("Test Cluster", "ByteOrderedPartitioner", DatabaseDescriptor.getEndpointSnitch().getClass().getName()));
    }
    TokenMetadata tokenMetadata = StorageService.instance.getTokenMetadata();
    Token token = tokenMetadata.sortedTokens().get(0);
    InetAddressAndPort addressAndPort = tokenMetadata.getAllEndpoints().iterator().next();
    assertRowsNet(executeDescribeNet(KEYSPACE, "DESCRIBE CLUSTER"), row("Test Cluster", "ByteOrderedPartitioner", DatabaseDescriptor.getEndpointSnitch().getClass().getName(), ImmutableMap.of(token.toString(), ImmutableList.of(addressAndPort.toString()))));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Test(org.junit.Test)

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