Search in sources :

Example 1 with IWriteResponseHandler

use of org.apache.cassandra.service.IWriteResponseHandler 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 2 with IWriteResponseHandler

use of org.apache.cassandra.service.IWriteResponseHandler in project eiger by wlloyd.

the class CounterColumn method sendToOtherReplica.

private static void sendToOtherReplica(DecoratedKey key, ColumnFamily cf) throws UnavailableException, TimeoutException, IOException {
    RowMutation rm = new RowMutation(cf.metadata().ksName, key.key);
    rm.add(cf);
    final InetAddress local = FBUtilities.getBroadcastAddress();
    String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(local);
    StorageProxy.performWrite(rm, ConsistencyLevel.ANY, localDataCenter, new StorageProxy.WritePerformer() {

        @Override
        public void apply(IMutation mutation, Collection<InetAddress> targets, IWriteResponseHandler responseHandler, String localDataCenter, ConsistencyLevel consistency_level) throws IOException, TimeoutException {
            // We should only send to the remote replica, not the local one
            targets.remove(local);
            // Fake local response to be a good lad but we won't wait on the responseHandler
            responseHandler.response(null);
            StorageProxy.sendToHintedEndpoints((RowMutation) mutation, targets, responseHandler, localDataCenter, consistency_level);
        }
    });
// we don't wait for answers
}
Also used : ConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel) StorageProxy(org.apache.cassandra.service.StorageProxy) IWriteResponseHandler(org.apache.cassandra.service.IWriteResponseHandler) IOException(java.io.IOException) InetAddress(java.net.InetAddress) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

InetAddress (java.net.InetAddress)2 IWriteResponseHandler (org.apache.cassandra.service.IWriteResponseHandler)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Message (org.apache.cassandra.net.Message)1 StorageProxy (org.apache.cassandra.service.StorageProxy)1 ConsistencyLevel (org.apache.cassandra.thrift.ConsistencyLevel)1