Search in sources :

Example 1 with MessageIn

use of org.apache.cassandra.net.MessageIn in project cassandra by apache.

the class MigrationTask method runMayThrow.

public void runMayThrow() throws Exception {
    // a higher major.
    if (!MigrationManager.shouldPullSchemaFrom(endpoint)) {
        logger.info("Skipped sending a migration request: node {} has a higher major version now.", endpoint);
        return;
    }
    if (!FailureDetector.instance.isAlive(endpoint)) {
        logger.debug("Can't send schema pull request: node {} is down.", endpoint);
        return;
    }
    MessageOut message = new MessageOut<>(MessagingService.Verb.MIGRATION_REQUEST, null, MigrationManager.MigrationsSerializer.instance);
    final CountDownLatch completionLatch = new CountDownLatch(1);
    IAsyncCallback<Collection<Mutation>> cb = new IAsyncCallback<Collection<Mutation>>() {

        @Override
        public void response(MessageIn<Collection<Mutation>> message) {
            try {
                Schema.instance.mergeAndAnnounceVersion(message.payload);
            } catch (ConfigurationException e) {
                logger.error("Configuration exception merging remote schema", e);
            } finally {
                completionLatch.countDown();
            }
        }

        public boolean isLatencyForSnitch() {
            return false;
        }
    };
    // Only save the latches if we need bootstrap or are bootstrapping
    if (monitoringBootstrapStates.contains(SystemKeyspace.getBootstrapState()))
        inflightTasks.offer(completionLatch);
    MessagingService.instance().sendRR(message, endpoint, cb);
}
Also used : MessageIn(org.apache.cassandra.net.MessageIn) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) Collection(java.util.Collection) Mutation(org.apache.cassandra.db.Mutation) MessageOut(org.apache.cassandra.net.MessageOut) CountDownLatch(java.util.concurrent.CountDownLatch) IAsyncCallback(org.apache.cassandra.net.IAsyncCallback)

Example 2 with MessageIn

use of org.apache.cassandra.net.MessageIn in project cassandra by apache.

the class HintVerbHandler method doVerb.

public void doVerb(MessageIn<HintMessage> message, int id) {
    UUID hostId = message.payload.hostId;
    Hint hint = message.payload.hint;
    InetAddress address = StorageService.instance.getEndpointForHostId(hostId);
    // is schema agreement between the sender and the receiver.
    if (hint == null) {
        logger.trace("Failed to decode and apply a hint for {}: {} - table with id {} is unknown", address, hostId, message.payload.unknownTableID);
        reply(id, message.from);
        return;
    }
    // We must perform validation before applying the hint, and there is no other place to do it other than here.
    try {
        hint.mutation.getPartitionUpdates().forEach(PartitionUpdate::validate);
    } catch (MarshalException e) {
        logger.warn("Failed to validate a hint for {}: {} - skipped", address, hostId);
        reply(id, message.from);
        return;
    }
    if (!hostId.equals(StorageService.instance.getLocalHostUUID())) {
        // the node is not the final destination of the hint (must have gotten it from a decommissioning node),
        // so just store it locally, to be delivered later.
        HintsService.instance.write(hostId, hint);
        reply(id, message.from);
    } else if (!StorageProxy.instance.appliesLocally(hint.mutation)) {
        // the topology has changed, and we are no longer a replica of the mutation - since we don't know which node(s)
        // it has been handed over to, re-address the hint to all replicas; see CASSANDRA-5902.
        HintsService.instance.writeForAllReplicas(hint);
        reply(id, message.from);
    } else {
        // the common path - the node is both the destination and a valid replica for the hint.
        hint.applyFuture().thenAccept(o -> reply(id, message.from)).exceptionally(e -> {
            logger.debug("Failed to apply hint", e);
            return null;
        });
    }
}
Also used : InetAddress(java.net.InetAddress) MessagingService(org.apache.cassandra.net.MessagingService) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Logger(org.slf4j.Logger) StorageProxy(org.apache.cassandra.service.StorageProxy) LoggerFactory(org.slf4j.LoggerFactory) StorageService(org.apache.cassandra.service.StorageService) MessageIn(org.apache.cassandra.net.MessageIn) UUID(java.util.UUID) IVerbHandler(org.apache.cassandra.net.IVerbHandler) MarshalException(org.apache.cassandra.serializers.MarshalException) MarshalException(org.apache.cassandra.serializers.MarshalException) UUID(java.util.UUID) InetAddress(java.net.InetAddress) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

Example 3 with MessageIn

use of org.apache.cassandra.net.MessageIn in project cassandra by apache.

the class AbstractPendingRepairTest method setupClass.

@BeforeClass
public static void setupClass() {
    SchemaLoader.prepareServer();
    ARS = ActiveRepairService.instance;
    LocalSessionAccessor.startup();
    // cutoff messaging service
    MessagingService.instance().addMessageSink(new IMessageSink() {

        public boolean allowOutgoingMessage(MessageOut message, int id, InetAddress to) {
            return false;
        }

        public boolean allowIncomingMessage(MessageIn message, int id) {
            return false;
        }
    });
}
Also used : MessageIn(org.apache.cassandra.net.MessageIn) IMessageSink(org.apache.cassandra.net.IMessageSink) MessageOut(org.apache.cassandra.net.MessageOut) InetAddress(java.net.InetAddress) BeforeClass(org.junit.BeforeClass)

Example 4 with MessageIn

use of org.apache.cassandra.net.MessageIn in project cassandra by apache.

the class ValidatorTest method registerOutgoingMessageSink.

private CompletableFuture<MessageOut> registerOutgoingMessageSink() {
    final CompletableFuture<MessageOut> future = new CompletableFuture<>();
    MessagingService.instance().addMessageSink(new IMessageSink() {

        public boolean allowOutgoingMessage(MessageOut message, int id, InetAddress to) {
            future.complete(message);
            return false;
        }

        public boolean allowIncomingMessage(MessageIn message, int id) {
            return false;
        }
    });
    return future;
}
Also used : MessageIn(org.apache.cassandra.net.MessageIn) CompletableFuture(java.util.concurrent.CompletableFuture) IMessageSink(org.apache.cassandra.net.IMessageSink) MessageOut(org.apache.cassandra.net.MessageOut) InetAddress(java.net.InetAddress)

Example 5 with MessageIn

use of org.apache.cassandra.net.MessageIn in project cassandra by apache.

the class Gossiper method markAlive.

private void markAlive(final InetAddress addr, final EndpointState localState) {
    localState.markDead();
    MessageOut<EchoMessage> echoMessage = new MessageOut<EchoMessage>(MessagingService.Verb.ECHO, EchoMessage.instance, EchoMessage.serializer);
    logger.trace("Sending a EchoMessage to {}", addr);
    IAsyncCallback echoHandler = new IAsyncCallback() {

        public boolean isLatencyForSnitch() {
            return false;
        }

        public void response(MessageIn msg) {
            realMarkAlive(addr, localState);
        }
    };
    MessagingService.instance().sendRR(echoMessage, addr, echoHandler);
}
Also used : MessageIn(org.apache.cassandra.net.MessageIn) MessageOut(org.apache.cassandra.net.MessageOut) IAsyncCallback(org.apache.cassandra.net.IAsyncCallback)

Aggregations

MessageIn (org.apache.cassandra.net.MessageIn)6 InetAddress (java.net.InetAddress)4 MessageOut (org.apache.cassandra.net.MessageOut)4 IAsyncCallback (org.apache.cassandra.net.IAsyncCallback)2 IMessageSink (org.apache.cassandra.net.IMessageSink)2 Collection (java.util.Collection)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Mutation (org.apache.cassandra.db.Mutation)1 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)1 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)1 RequestFailureReason (org.apache.cassandra.exceptions.RequestFailureReason)1 IAsyncCallbackWithFailure (org.apache.cassandra.net.IAsyncCallbackWithFailure)1 IVerbHandler (org.apache.cassandra.net.IVerbHandler)1 MessagingService (org.apache.cassandra.net.MessagingService)1 TableId (org.apache.cassandra.schema.TableId)1 MarshalException (org.apache.cassandra.serializers.MarshalException)1