Search in sources :

Example 1 with RepairMessage

use of org.apache.cassandra.repair.messages.RepairMessage in project cassandra by apache.

the class CoordinatorSession method finalizePropose.

public synchronized Future<Void> finalizePropose() {
    Preconditions.checkArgument(allStates(State.REPAIRING));
    logger.info("Proposing finalization of repair session {}", sessionID);
    Message<RepairMessage> message = Message.out(Verb.FINALIZE_PROPOSE_MSG, new FinalizePropose(sessionID));
    for (final InetAddressAndPort participant : participants) {
        sendMessage(participant, message);
    }
    return finalizeProposeFuture;
}
Also used : RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose)

Example 2 with RepairMessage

use of org.apache.cassandra.repair.messages.RepairMessage in project cassandra by apache.

the class CoordinatorSession method prepare.

public Future<Void> prepare() {
    Preconditions.checkArgument(allStates(State.PREPARING));
    logger.info("Beginning prepare phase of incremental repair session {}", sessionID);
    Message<RepairMessage> message = Message.out(Verb.PREPARE_CONSISTENT_REQ, new PrepareConsistentRequest(sessionID, coordinator, participants));
    for (final InetAddressAndPort participant : participants) {
        sendMessage(participant, message);
    }
    return prepareFuture;
}
Also used : RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest)

Example 3 with RepairMessage

use of org.apache.cassandra.repair.messages.RepairMessage in project cassandra by apache.

the class CoordinatorSession method finalizeCommit.

public synchronized void finalizeCommit() {
    Preconditions.checkArgument(allStates(State.FINALIZE_PROMISED));
    logger.info("Committing finalization of repair session {}", sessionID);
    Message<RepairMessage> message = Message.out(Verb.FINALIZE_COMMIT_MSG, new FinalizeCommit(sessionID));
    for (final InetAddressAndPort participant : participants) {
        sendMessage(participant, message);
    }
    setAll(State.FINALIZED);
    logger.info("Incremental repair session {} completed", sessionID);
}
Also used : FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort)

Example 4 with RepairMessage

use of org.apache.cassandra.repair.messages.RepairMessage in project cassandra by apache.

the class ActiveRepairService method handleMessage.

public void handleMessage(Message<? extends RepairMessage> message) {
    RepairMessage payload = message.payload;
    RepairJobDesc desc = payload.desc;
    RepairSession session = sessions.get(desc.sessionId);
    if (session == null) {
        if (payload instanceof ValidationResponse) {
            // The trees may be off-heap, and will therefore need to be released.
            ValidationResponse validation = (ValidationResponse) payload;
            MerkleTrees trees = validation.trees;
            // The response from a failed validation won't have any trees.
            if (trees != null)
                trees.release();
        }
        return;
    }
    switch(message.verb()) {
        case VALIDATION_RSP:
            ValidationResponse validation = (ValidationResponse) payload;
            session.validationComplete(desc, message.from(), validation.trees);
            break;
        case SYNC_RSP:
            // one of replica is synced.
            SyncResponse sync = (SyncResponse) payload;
            session.syncComplete(desc, sync.nodes, sync.success, sync.summaries);
            break;
        default:
            break;
    }
}
Also used : RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) MerkleTrees(org.apache.cassandra.utils.MerkleTrees) SyncResponse(org.apache.cassandra.repair.messages.SyncResponse) RepairJobDesc(org.apache.cassandra.repair.RepairJobDesc) ValidationResponse(org.apache.cassandra.repair.messages.ValidationResponse) RepairSession(org.apache.cassandra.repair.RepairSession)

Example 5 with RepairMessage

use of org.apache.cassandra.repair.messages.RepairMessage in project cassandra by apache.

the class ActiveRepairService method prepareForRepair.

public UUID prepareForRepair(UUID parentRepairSession, InetAddressAndPort coordinator, Set<InetAddressAndPort> endpoints, RepairOption options, boolean isForcedRepair, List<ColumnFamilyStore> columnFamilyStores) {
    if (!verifyCompactionsPendingThreshold(parentRepairSession, options.getPreviewKind()))
        // failRepair throws exception
        failRepair(parentRepairSession, "Rejecting incoming repair, pending compactions above threshold");
    long repairedAt = getRepairedAt(options, isForcedRepair);
    registerParentRepairSession(parentRepairSession, coordinator, columnFamilyStores, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal(), options.getPreviewKind());
    final CountDownLatch prepareLatch = newCountDownLatch(endpoints.size());
    final AtomicBoolean status = new AtomicBoolean(true);
    final Set<String> failedNodes = synchronizedSet(new HashSet<String>());
    final AtomicInteger timeouts = new AtomicInteger(0);
    RequestCallback callback = new RequestCallback() {

        @Override
        public void onResponse(Message msg) {
            prepareLatch.decrement();
        }

        @Override
        public void onFailure(InetAddressAndPort from, RequestFailureReason failureReason) {
            status.set(false);
            failedNodes.add(from.toString());
            if (failureReason == RequestFailureReason.TIMEOUT)
                timeouts.incrementAndGet();
            prepareLatch.decrement();
        }

        @Override
        public boolean invokeOnFailure() {
            return true;
        }
    };
    List<TableId> tableIds = new ArrayList<>(columnFamilyStores.size());
    for (ColumnFamilyStore cfs : columnFamilyStores) tableIds.add(cfs.metadata.id);
    for (InetAddressAndPort neighbour : endpoints) {
        if (FailureDetector.instance.isAlive(neighbour)) {
            PrepareMessage message = new PrepareMessage(parentRepairSession, tableIds, options.getRanges(), options.isIncremental(), repairedAt, options.isGlobal(), options.getPreviewKind());
            Message<RepairMessage> msg = out(PREPARE_MSG, message);
            MessagingService.instance().sendWithCallback(msg, neighbour, callback);
        } else {
            // remaining ones go down, we still want to fail so we don't create repair sessions that can't complete
            if (isForcedRepair && !options.isIncremental()) {
                prepareLatch.decrement();
            } else {
                // bailout early to avoid potentially waiting for a long time.
                failRepair(parentRepairSession, "Endpoint not alive: " + neighbour);
            }
        }
    }
    try {
        if (!prepareLatch.await(getRpcTimeout(MILLISECONDS), MILLISECONDS) || timeouts.get() > 0)
            failRepair(parentRepairSession, "Did not get replies from all endpoints.");
    } catch (InterruptedException e) {
        failRepair(parentRepairSession, "Interrupted while waiting for prepare repair response.");
    }
    if (!status.get()) {
        failRepair(parentRepairSession, "Got negative replies from endpoints " + failedNodes);
    }
    return parentRepairSession;
}
Also used : TableId(org.apache.cassandra.schema.TableId) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) PrepareMessage(org.apache.cassandra.repair.messages.PrepareMessage) Message(org.apache.cassandra.net.Message) CleanupMessage(org.apache.cassandra.repair.messages.CleanupMessage) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) CountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch) CountDownLatch.newCountDownLatch(org.apache.cassandra.utils.concurrent.CountDownLatch.newCountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) RequestFailureReason(org.apache.cassandra.exceptions.RequestFailureReason) PrepareMessage(org.apache.cassandra.repair.messages.PrepareMessage) RequestCallback(org.apache.cassandra.net.RequestCallback) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Aggregations

RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)10 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 PrepareConsistentRequest (org.apache.cassandra.repair.messages.PrepareConsistentRequest)5 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)4 CoordinatedRepairResult (org.apache.cassandra.repair.CoordinatedRepairResult)4 Future (org.apache.cassandra.utils.concurrent.Future)4 Test (org.junit.Test)4 RepairSessionResult (org.apache.cassandra.repair.RepairSessionResult)3 FailSession (org.apache.cassandra.repair.messages.FailSession)3 FinalizePropose (org.apache.cassandra.repair.messages.FinalizePropose)3 FinalizeCommit (org.apache.cassandra.repair.messages.FinalizeCommit)2 Assert (org.junit.Assert)2 Collection (java.util.Collection)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Token (org.apache.cassandra.dht.Token)1 RequestFailureReason (org.apache.cassandra.exceptions.RequestFailureReason)1 Message (org.apache.cassandra.net.Message)1 RequestCallback (org.apache.cassandra.net.RequestCallback)1