Search in sources :

Example 6 with FailSession

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

the class CoordinatorSessionTest method multipleFailures.

/**
     * Coordinator should only send out failures messages once
     */
@Test
public void multipleFailures() {
    InstrumentedCoordinatorSession coordinator = createInstrumentedSession();
    Assert.assertEquals(PREPARING, coordinator.getState());
    Assert.assertTrue(coordinator.sentMessages.isEmpty());
    coordinator.fail();
    Assert.assertEquals(FAILED, coordinator.getState());
    for (InetAddress participant : PARTICIPANTS) {
        assertMessageSent(coordinator, participant, new FailSession(coordinator.sessionID));
    }
    coordinator.sentMessages.clear();
    coordinator.fail();
    Assert.assertEquals(FAILED, coordinator.getState());
    Assert.assertTrue(coordinator.sentMessages.isEmpty());
}
Also used : InetAddress(java.net.InetAddress) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 7 with FailSession

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

the class CoordinatorSessionsTest method handleFailureMessage.

@Test
public void handleFailureMessage() {
    InstrumentedCoordinatorSessions sessions = new InstrumentedCoordinatorSessions();
    UUID sessionID = registerSession();
    InstrumentedCoordinatorSession session = sessions.registerSession(sessionID, PARTICIPANTS);
    Assert.assertEquals(0, session.failCalls);
    sessions.handleFailSessionMessage(new FailSession(sessionID));
    Assert.assertEquals(1, session.failCalls);
}
Also used : UUID(java.util.UUID) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 8 with FailSession

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

the class LocalSessionTest method prepareAntiCompactFailure.

/**
     * If anti compactionn fails, we should fail the session locally,
     * and send a failure message back to the coordinator
     */
@Test
public void prepareAntiCompactFailure() {
    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.setException(new RuntimeException());
    session = sessions.getSession(sessionID);
    Assert.assertNotNull(session);
    Assert.assertEquals(FAILED, session.getState());
    Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
    // ...and we should have sent a success message back to the coordinator
    assertMessagesSent(sessions, COORDINATOR, new FailSession(sessionID));
}
Also used : UUID(java.util.UUID) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 9 with FailSession

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

the class LocalSessionTest method finalizeProposeNonExistantSessionFailure.

@Test
public void finalizeProposeNonExistantSessionFailure() {
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    UUID fakeID = UUIDGen.getTimeUUID();
    sessions.handleFinalizeProposeMessage(COORDINATOR, new FinalizePropose(fakeID));
    Assert.assertNull(sessions.getSession(fakeID));
    assertMessagesSent(sessions, COORDINATOR, new FailSession(fakeID));
}
Also used : UUID(java.util.UUID) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 10 with FailSession

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

the class CoordinatorSessionTest method failedRepairs.

@Test
public void failedRepairs() {
    InstrumentedCoordinatorSession coordinator = createInstrumentedSession();
    Executor executor = MoreExecutors.directExecutor();
    AtomicBoolean repairSubmitted = new AtomicBoolean(false);
    SettableFuture<List<RepairSessionResult>> repairFuture = SettableFuture.create();
    Supplier<ListenableFuture<List<RepairSessionResult>>> sessionSupplier = () -> {
        repairSubmitted.set(true);
        return repairFuture;
    };
    // coordinator sends prepare requests to create local session and perform anticompaction
    AtomicBoolean hasFailures = new AtomicBoolean(false);
    Assert.assertFalse(repairSubmitted.get());
    Assert.assertTrue(coordinator.sentMessages.isEmpty());
    ListenableFuture sessionResult = coordinator.execute(executor, sessionSupplier, hasFailures);
    for (InetAddress participant : PARTICIPANTS) {
        PrepareConsistentRequest expected = new PrepareConsistentRequest(coordinator.sessionID, COORDINATOR, new HashSet<>(PARTICIPANTS));
        assertMessageSent(coordinator, participant, expected);
    }
    // participants respond to coordinator, and repair begins once all participants have responded with success
    Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
    coordinator.handlePrepareResponse(PARTICIPANT1, true);
    Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
    coordinator.handlePrepareResponse(PARTICIPANT2, true);
    Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
    // set the setRepairing callback to verify the correct state when it's called
    Assert.assertFalse(coordinator.setRepairingCalled);
    coordinator.onSetRepairing = () -> Assert.assertEquals(PREPARED, coordinator.getState());
    coordinator.handlePrepareResponse(PARTICIPANT3, true);
    Assert.assertTrue(coordinator.setRepairingCalled);
    Assert.assertTrue(repairSubmitted.get());
    Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
    ArrayList<RepairSessionResult> results = Lists.newArrayList(createResult(coordinator), null, createResult(coordinator));
    coordinator.sentMessages.clear();
    Assert.assertFalse(coordinator.failCalled);
    coordinator.onFail = () -> Assert.assertEquals(REPAIRING, coordinator.getState());
    repairFuture.set(results);
    Assert.assertTrue(coordinator.failCalled);
    // all participants should have been notified of session failure
    for (InetAddress participant : PARTICIPANTS) {
        RepairMessage expected = new FailSession(coordinator.sessionID);
        assertMessageSent(coordinator, participant, expected);
    }
    Assert.assertTrue(sessionResult.isDone());
    Assert.assertTrue(hasFailures.get());
}
Also used : PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) FailSession(org.apache.cassandra.repair.messages.FailSession) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) Executor(java.util.concurrent.Executor) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ArrayList(java.util.ArrayList) List(java.util.List) InetAddress(java.net.InetAddress) RepairSessionResult(org.apache.cassandra.repair.RepairSessionResult) 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