Search in sources :

Example 6 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class AbstractTransactionMessage method getMessage.

@Override
public Message getMessage(Integer version) throws IOException {
    DataOutputBuffer dob = new DataOutputBuffer();
    serializer().serialize(this, dob, version);
    logger.debug("getMessage called on " + this + " serialized into " + dob.getLength());
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.TRANSACTION_MESSAGE, Arrays.copyOf(dob.getData(), dob.getLength()), version);
}
Also used : Message(org.apache.cassandra.net.Message) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer)

Example 7 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class TransactionProxy method replicateTransactionToOtherDatacenters.

//WL TODO: Remove the assumption that datacenters have matching keyranges
private static void replicateTransactionToOtherDatacenters(MessageProducer producer, String keyspace, ByteBuffer targetKey) throws IOException {
    List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(keyspace, targetKey);
    String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
    IWriteResponseHandler ignoredResponseHandler = WriteResponseHandler.create(endpoints, ConsistencyLevel.ALL, keyspace);
    // code follows the structure of StorageProxy.sendToHintedEndpoints
    // Multimap that holds onto all the messages and addresses meant for a specific datacenter
    Map<String, Multimap<Message, InetAddress>> dcMessages = new HashMap<String, Multimap<Message, InetAddress>>(endpoints.size());
    for (InetAddress destination : endpoints) {
        assert FailureDetector.instance.isAlive(destination) : "Not dealing with failed nodes in the dc right now";
        if (destination.equals(FBUtilities.getBroadcastAddress())) {
            //no need to *replicate* to the local machine, it should already have started handling the transaction
            continue;
        }
        if (logger.isDebugEnabled())
            logger.debug("replicate transaction to " + destination);
        String dc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(destination);
        Multimap<Message, InetAddress> messages = dcMessages.get(dc);
        if (messages == null) {
            messages = HashMultimap.create();
            dcMessages.put(dc, messages);
        }
        messages.put(producer.getMessage(Gossiper.instance.getVersion(destination)), destination);
    }
    StorageProxy.sendMessages(localDataCenter, dcMessages, ignoredResponseHandler);
}
Also used : Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) Message(org.apache.cassandra.net.Message) IWriteResponseHandler(org.apache.cassandra.service.IWriteResponseHandler) InetAddress(java.net.InetAddress)

Example 8 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class BootStrapper method getBootstrapTokenFrom.

static Token<?> getBootstrapTokenFrom(InetAddress maxEndpoint) {
    Message message = new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.BOOTSTRAP_TOKEN, ArrayUtils.EMPTY_BYTE_ARRAY, Gossiper.instance.getVersion(maxEndpoint));
    int retries = 5;
    long timeout = Math.max(MessagingService.getDefaultCallbackTimeout(), BOOTSTRAP_TIMEOUT);
    while (retries > 0) {
        BootstrapTokenCallback btc = new BootstrapTokenCallback();
        MessagingService.instance().sendRR(message, maxEndpoint, btc, timeout);
        Token token = btc.getToken(timeout);
        if (token != null)
            return token;
        retries--;
    }
    throw new RuntimeException("Bootstrap failed, could not obtain token from: " + maxEndpoint);
}
Also used : Message(org.apache.cassandra.net.Message)

Example 9 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class AntiEntropyService method respond.

/**
     * Responds to the node that requested the given valid tree.
     * @param validator A locally generated validator
     * @param local localhost (parameterized for testing)
     */
void respond(Validator validator, InetAddress local) {
    MessagingService ms = MessagingService.instance();
    try {
        Message message = TreeResponseVerbHandler.makeVerb(local, validator);
        if (!validator.request.endpoint.equals(FBUtilities.getBroadcastAddress()))
            logger.info(String.format("[repair #%s] Sending completed merkle tree to %s for %s", validator.request.sessionid, validator.request.endpoint, validator.request.cf));
        ms.sendOneWay(message, validator.request.endpoint);
    } catch (Exception e) {
        logger.error(String.format("[repair #%s] Error sending completed merkle tree to %s for %s ", validator.request.sessionid, validator.request.endpoint, validator.request.cf), e);
    }
}
Also used : Message(org.apache.cassandra.net.Message) MessagingService(org.apache.cassandra.net.MessagingService)

Example 10 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class Gossiper method makeGossipDigestAckMessage.

Message makeGossipDigestAckMessage(GossipDigestAckMessage gDigestAckMessage, int version) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    GossipDigestAckMessage.serializer().serialize(gDigestAckMessage, dos, version);
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.GOSSIP_DIGEST_ACK, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message) DataOutputStream(java.io.DataOutputStream)

Aggregations

Message (org.apache.cassandra.net.Message)40 IOException (java.io.IOException)9 DataInputStream (java.io.DataInputStream)7 FastByteArrayOutputStream (org.apache.cassandra.io.util.FastByteArrayOutputStream)7 InetAddress (java.net.InetAddress)6 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)6 DataOutputStream (java.io.DataOutputStream)4 IOError (java.io.IOError)3 RangeSliceReply (org.apache.cassandra.db.RangeSliceReply)3 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TimeoutException (java.util.concurrent.TimeoutException)2 Row (org.apache.cassandra.db.Row)2 IPartitioner (org.apache.cassandra.dht.IPartitioner)2 IAsyncResult (org.apache.cassandra.net.IAsyncResult)2 Test (org.junit.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1