Search in sources :

Example 1 with FailSession

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

the class CoordinatorSession method fail.

public synchronized void fail(Executor executor) {
    logger.debug("Failing session {}", sessionID);
    FailSession message = new FailSession(sessionID);
    for (final InetAddress participant : participants) {
        if (participantStates.get(participant) != State.FAILED) {
            executor.execute(() -> sendMessage(participant, message));
        }
    }
    setAll(State.FAILED);
}
Also used : InetAddress(java.net.InetAddress) FailSession(org.apache.cassandra.repair.messages.FailSession)

Example 2 with FailSession

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

the class LocalSessions method handlePrepareMessage.

/**
     * The PrepareConsistentRequest effectively promotes the parent repair session to a consistent
     * incremental session, and begins the 'pending anti compaction' which moves all sstable data
     * that is to be repaired into it's own silo, preventing it from mixing with other data.
     *
     * No response is sent to the repair coordinator until the pending anti compaction has completed
     * successfully. If the pending anti compaction fails, a failure message is sent to the coordinator,
     * cancelling the session.
     */
public void handlePrepareMessage(InetAddress from, PrepareConsistentRequest request) {
    logger.debug("received {} from {}", request, from);
    UUID sessionID = request.parentSession;
    InetAddress coordinator = request.coordinator;
    Set<InetAddress> peers = request.participants;
    ActiveRepairService.ParentRepairSession parentSession;
    try {
        parentSession = getParentRepairSession(sessionID);
    } catch (Throwable e) {
        logger.debug("Error retrieving ParentRepairSession for session {}, responding with failure", sessionID);
        sendMessage(coordinator, new FailSession(sessionID));
        return;
    }
    LocalSession session = createSessionUnsafe(sessionID, parentSession, peers);
    putSessionUnsafe(session);
    logger.debug("created local session for {}", sessionID);
    ExecutorService executor = Executors.newFixedThreadPool(parentSession.getColumnFamilyStores().size());
    ListenableFuture pendingAntiCompaction = submitPendingAntiCompaction(session, executor);
    Futures.addCallback(pendingAntiCompaction, new FutureCallback() {

        public void onSuccess(@Nullable Object result) {
            logger.debug("pending anti-compaction for {} completed", sessionID);
            setStateAndSave(session, PREPARED);
            sendMessage(coordinator, new PrepareConsistentResponse(sessionID, getBroadcastAddress(), true));
            executor.shutdown();
        }

        public void onFailure(Throwable t) {
            logger.debug("pending anti-compaction for {} failed", sessionID);
            failSession(sessionID);
            executor.shutdown();
        }
    });
}
Also used : ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) FailSession(org.apache.cassandra.repair.messages.FailSession) ExecutorService(java.util.concurrent.ExecutorService) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) UUID(java.util.UUID) InetAddress(java.net.InetAddress) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 3 with FailSession

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

the class LocalSessions method cancelSession.

/**
     * hook for operators to cancel sessions, cancelling from a non-coordinator is an error, unless
     * force is set to true. Messages are sent out to other participants, but we don't wait for a response
     */
public void cancelSession(UUID sessionID, boolean force) {
    logger.debug("cancelling session {}", sessionID);
    LocalSession session = getSession(sessionID);
    Preconditions.checkArgument(session != null, "Session {} does not exist", sessionID);
    Preconditions.checkArgument(force || session.coordinator.equals(getBroadcastAddress()), "Cancel session %s from it's coordinator (%s) or use --force", sessionID, session.coordinator);
    setStateAndSave(session, FAILED);
    for (InetAddress participant : session.participants) {
        if (!participant.equals(getBroadcastAddress()))
            sendMessage(participant, new FailSession(sessionID));
    }
}
Also used : InetAddress(java.net.InetAddress) FailSession(org.apache.cassandra.repair.messages.FailSession)

Example 4 with FailSession

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

the class LocalSessions method failSession.

public void failSession(UUID sessionID, boolean sendMessage) {
    logger.debug("failing session {}", sessionID);
    LocalSession session = getSession(sessionID);
    if (session != null) {
        setStateAndSave(session, FAILED);
        if (sendMessage) {
            sendMessage(session.coordinator, new FailSession(sessionID));
        }
    }
}
Also used : FailSession(org.apache.cassandra.repair.messages.FailSession)

Example 5 with FailSession

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

the class LocalSessionTest method handleFailMessage.

/**
     * Session should be failed, but no messages should be sent
     */
@Test
public void handleFailMessage() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    LocalSession session = sessions.prepareForTest(sessionID);
    Assert.assertEquals(PREPARED, session.getState());
    sessions.sentMessages.clear();
    sessions.handleFailSessionMessage(PARTICIPANT1, new FailSession(sessionID));
    Assert.assertEquals(FAILED, session.getState());
    Assert.assertTrue(sessions.sentMessages.isEmpty());
}
Also used : UUID(java.util.UUID) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Aggregations

FailSession (org.apache.cassandra.repair.messages.FailSession)17 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)12 Test (org.junit.Test)12 UUID (java.util.UUID)10 InetAddress (java.net.InetAddress)7 PrepareConsistentRequest (org.apache.cassandra.repair.messages.PrepareConsistentRequest)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Executor (java.util.concurrent.Executor)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 RepairSessionResult (org.apache.cassandra.repair.RepairSessionResult)3 FinalizePropose (org.apache.cassandra.repair.messages.FinalizePropose)3 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)3 Assert (org.junit.Assert)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ExecutorService (java.util.concurrent.ExecutorService)1 FinalizePromise (org.apache.cassandra.repair.messages.FinalizePromise)1 PrepareConsistentResponse (org.apache.cassandra.repair.messages.PrepareConsistentResponse)1 ActiveRepairService (org.apache.cassandra.service.ActiveRepairService)1