Search in sources :

Example 1 with IAsyncCallbackWithFailure

use of org.apache.cassandra.net.IAsyncCallbackWithFailure 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

InetAddress (java.net.InetAddress)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 RequestFailureReason (org.apache.cassandra.exceptions.RequestFailureReason)1 IAsyncCallbackWithFailure (org.apache.cassandra.net.IAsyncCallbackWithFailure)1 MessageIn (org.apache.cassandra.net.MessageIn)1 TableId (org.apache.cassandra.schema.TableId)1