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);
}
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();
}
});
}
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));
}
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));
}
Aggregations