Search in sources :

Example 11 with FailSession

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

the class CoordinatorSessionTest method failedPropose.

@Test
public void failedPropose() {
    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) {
        RepairMessage 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), createResult(coordinator), createResult(coordinator));
    coordinator.sentMessages.clear();
    repairFuture.set(results);
    // propose messages should have been sent once all repair sessions completed successfully
    for (InetAddress participant : PARTICIPANTS) {
        RepairMessage expected = new FinalizePropose(coordinator.sessionID);
        assertMessageSent(coordinator, participant, expected);
    }
    // finalize commit messages will be sent once all participants respond with a promize to finalize
    coordinator.sentMessages.clear();
    Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
    coordinator.handleFinalizePromise(PARTICIPANT1, true);
    Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
    Assert.assertFalse(coordinator.failCalled);
    coordinator.handleFinalizePromise(PARTICIPANT2, false);
    Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
    Assert.assertTrue(coordinator.failCalled);
    // additional success messages should be ignored
    Assert.assertFalse(coordinator.finalizeCommitCalled);
    coordinator.onFinalizeCommit = Assert::fail;
    coordinator.handleFinalizePromise(PARTICIPANT3, true);
    Assert.assertFalse(coordinator.finalizeCommitCalled);
    Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
    // failure messages should have been sent to all participants
    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) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) 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) Assert(org.junit.Assert) 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)

Example 12 with FailSession

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

the class CoordinatorSessionTest method failedPrepare.

@Test
public void failedPrepare() {
    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);
    }
    coordinator.sentMessages.clear();
    // 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());
    // participant 2 fails to prepare for consistent repair
    Assert.assertFalse(coordinator.failCalled);
    coordinator.handlePrepareResponse(PARTICIPANT2, false);
    Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
    Assert.assertTrue(coordinator.failCalled);
    // additional success messages should be ignored
    Assert.assertFalse(coordinator.setRepairingCalled);
    coordinator.onSetRepairing = Assert::fail;
    coordinator.handlePrepareResponse(PARTICIPANT3, true);
    Assert.assertFalse(coordinator.setRepairingCalled);
    Assert.assertFalse(repairSubmitted.get());
    // 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) Assert(org.junit.Assert) 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)

Example 13 with FailSession

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

the class CoordinatorSessionsTest method handleFailureMessageNoSession.

@Test
public void handleFailureMessageNoSession() {
    InstrumentedCoordinatorSessions sessions = new InstrumentedCoordinatorSessions();
    UUID fakeID = UUIDGen.getTimeUUID();
    sessions.handleFailSessionMessage(new FailSession(fakeID));
    Assert.assertNull(sessions.getSession(fakeID));
}
Also used : UUID(java.util.UUID) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 14 with FailSession

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

the class LocalSessionTest method failSession.

@Test
public void failSession() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    LocalSession session = sessions.prepareForTest(sessionID);
    Assert.assertEquals(PREPARED, session.getState());
    sessions.sentMessages.clear();
    // fail session
    sessions.failSession(sessionID);
    Assert.assertEquals(FAILED, session.getState());
    assertMessagesSent(sessions, COORDINATOR, new FailSession(sessionID));
}
Also used : UUID(java.util.UUID) FailSession(org.apache.cassandra.repair.messages.FailSession) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 15 with FailSession

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

the class LocalSessionTest method finalizeProposeInvalidStateFailure.

/**
     * Trying to propose finalization when the session isn't in the repaired
     * state should fail the session and send a failure message to the proposer
     */
@Test
public void finalizeProposeInvalidStateFailure() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    LocalSession session = sessions.prepareForTest(sessionID);
    Assert.assertEquals(PREPARED, session.getState());
    // should fail the session and send a failure message to the coordinator
    sessions.sentMessages.clear();
    sessions.handleFinalizeProposeMessage(COORDINATOR, new FinalizePropose(sessionID));
    Assert.assertEquals(FAILED, session.getState());
    Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
    assertMessagesSent(sessions, COORDINATOR, new FailSession(sessionID));
}
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)

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