Search in sources :

Example 1 with PrepareConsistentResponse

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

the class CoordinatorSessionsTest method handlePrepareResponse.

@Test
public void handlePrepareResponse() {
    InstrumentedCoordinatorSessions sessions = new InstrumentedCoordinatorSessions();
    UUID sessionID = registerSession();
    InstrumentedCoordinatorSession session = sessions.registerSession(sessionID, PARTICIPANTS);
    Assert.assertEquals(0, session.prepareResponseCalls);
    sessions.handlePrepareResponse(new PrepareConsistentResponse(sessionID, PARTICIPANT1, true));
    Assert.assertEquals(1, session.prepareResponseCalls);
    Assert.assertEquals(PARTICIPANT1, session.preparePeer);
    Assert.assertEquals(true, session.prepareSuccess);
}
Also used : PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) UUID(java.util.UUID) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 2 with PrepareConsistentResponse

use of org.apache.cassandra.repair.messages.PrepareConsistentResponse 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 PrepareConsistentResponse

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

the class CoordinatorSessionsTest method handlePrepareResponseNoSession.

@Test
public void handlePrepareResponseNoSession() {
    InstrumentedCoordinatorSessions sessions = new InstrumentedCoordinatorSessions();
    UUID fakeID = UUIDGen.getTimeUUID();
    sessions.handlePrepareResponse(new PrepareConsistentResponse(fakeID, PARTICIPANT1, true));
    Assert.assertNull(sessions.getSession(fakeID));
}
Also used : PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) UUID(java.util.UUID) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 4 with PrepareConsistentResponse

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

the class LocalSessionTest method prepareSuccessCase.

@Test
public void prepareSuccessCase() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    // replacing future so we can inspect state before and after anti compaction callback
    sessions.pendingAntiCompactionFuture = SettableFuture.create();
    Assert.assertFalse(sessions.submitPendingAntiCompactionCalled);
    sessions.handlePrepareMessage(PARTICIPANT1, new PrepareConsistentRequest(sessionID, COORDINATOR, PARTICIPANTS));
    Assert.assertTrue(sessions.submitPendingAntiCompactionCalled);
    Assert.assertTrue(sessions.sentMessages.isEmpty());
    // anti compaction hasn't finished yet, so state in memory and on disk should be PREPARING
    LocalSession session = sessions.getSession(sessionID);
    Assert.assertNotNull(session);
    Assert.assertEquals(PREPARING, session.getState());
    Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
    // anti compaction has now finished, so state in memory and on disk should be PREPARED
    sessions.pendingAntiCompactionFuture.set(new Object());
    session = sessions.getSession(sessionID);
    Assert.assertNotNull(session);
    Assert.assertEquals(PREPARED, session.getState());
    Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
    // ...and we should have sent a success message back to the coordinator
    assertMessagesSent(sessions, COORDINATOR, new PrepareConsistentResponse(sessionID, PARTICIPANT1, true));
}
Also used : PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) UUID(java.util.UUID) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)4 PrepareConsistentResponse (org.apache.cassandra.repair.messages.PrepareConsistentResponse)4 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)3 Test (org.junit.Test)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 InetAddress (java.net.InetAddress)1 ExecutorService (java.util.concurrent.ExecutorService)1 FailSession (org.apache.cassandra.repair.messages.FailSession)1 PrepareConsistentRequest (org.apache.cassandra.repair.messages.PrepareConsistentRequest)1 ActiveRepairService (org.apache.cassandra.service.ActiveRepairService)1