Search in sources :

Example 6 with MessageIn

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

the class ActiveRepairService method prepareForRepair.

public UUID prepareForRepair(UUID parentRepairSession, InetAddress coordinator, Set<InetAddress> endpoints, RepairOption options, List<ColumnFamilyStore> columnFamilyStores) {
    // we only want repairedAt for incremental repairs, for non incremental repairs, UNREPAIRED_SSTABLE will preserve repairedAt on streamed sstables
    long repairedAt = options.isIncremental() ? Clock.instance.currentTimeMillis() : ActiveRepairService.UNREPAIRED_SSTABLE;
    registerParentRepairSession(parentRepairSession, coordinator, columnFamilyStores, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal());
    final CountDownLatch prepareLatch = new CountDownLatch(endpoints.size());
    final AtomicBoolean status = new AtomicBoolean(true);
    final Set<String> failedNodes = Collections.synchronizedSet(new HashSet<String>());
    IAsyncCallbackWithFailure callback = new IAsyncCallbackWithFailure() {

        public void response(MessageIn msg) {
            prepareLatch.countDown();
        }

        public boolean isLatencyForSnitch() {
            return false;
        }

        public void onFailure(InetAddress from, RequestFailureReason failureReason) {
            status.set(false);
            failedNodes.add(from.getHostAddress());
            prepareLatch.countDown();
        }
    };
    List<TableId> tableIds = new ArrayList<>(columnFamilyStores.size());
    for (ColumnFamilyStore cfs : columnFamilyStores) tableIds.add(cfs.metadata.id);
    for (InetAddress neighbour : endpoints) {
        if (FailureDetector.instance.isAlive(neighbour)) {
            PrepareMessage message = new PrepareMessage(parentRepairSession, tableIds, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal());
            MessageOut<RepairMessage> msg = message.createMessage();
            MessagingService.instance().sendRR(msg, neighbour, callback, DatabaseDescriptor.getRpcTimeout(), true);
        } else {
            status.set(false);
            failedNodes.add(neighbour.getHostAddress());
            prepareLatch.countDown();
        }
    }
    try {
        prepareLatch.await(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        removeParentRepairSession(parentRepairSession);
        throw new RuntimeException("Did not get replies from all endpoints. List of failed endpoint(s): " + failedNodes, e);
    }
    if (!status.get()) {
        removeParentRepairSession(parentRepairSession);
        throw new RuntimeException("Did not get positive replies from all endpoints. List of failed endpoint(s): " + failedNodes);
    }
    return parentRepairSession;
}
Also used : TableId(org.apache.cassandra.schema.TableId) IAsyncCallbackWithFailure(org.apache.cassandra.net.IAsyncCallbackWithFailure) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageIn(org.apache.cassandra.net.MessageIn) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) InetAddress(java.net.InetAddress)

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