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);
}
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
}
Aggregations