Search in sources :

Example 6 with CoordinatedRepairResult

use of org.apache.cassandra.repair.CoordinatedRepairResult in project cassandra by apache.

the class CoordinatorMessagingTest method testMockedMessagingPrepareTimeout.

@Test
public void testMockedMessagingPrepareTimeout() throws InterruptedException, ExecutionException, TimeoutException, NoSuchRepairSessionException {
    MockMessagingSpy spyPrepare = createPrepareSpy(Collections.emptySet(), Collections.singleton(PARTICIPANT3), new CountDownLatch(0));
    MockMessagingSpy sendFailSessionUnexpectedSpy = createFailSessionSpy(Lists.newArrayList(PARTICIPANT1, PARTICIPANT2, PARTICIPANT3));
    UUID uuid = registerSession(cfs, true, true);
    CoordinatorSession coordinator = ActiveRepairService.instance.consistent.coordinated.registerSession(uuid, PARTICIPANTS, false);
    AtomicBoolean repairSubmitted = new AtomicBoolean(false);
    Promise<CoordinatedRepairResult> repairFuture = AsyncPromise.uncancellable();
    Supplier<Future<CoordinatedRepairResult>> sessionSupplier = () -> {
        repairSubmitted.set(true);
        return repairFuture;
    };
    // coordinator sends prepare requests to create local session and perform anticompaction
    Assert.assertFalse(repairSubmitted.get());
    // execute repair and start prepare phase
    Future<CoordinatedRepairResult> sessionResult = coordinator.execute(sessionSupplier);
    try {
        sessionResult.get(1, TimeUnit.SECONDS);
        fail("Completed session without failure after prepare failed");
    } catch (ExecutionException e) {
        fail("Failed session in prepare failed during timeout from participant");
    } catch (TimeoutException e) {
    // expected
    }
    // we won't send out any fail session message in case of timeouts
    spyPrepare.expectMockedMessage(2).get(100, TimeUnit.MILLISECONDS);
    sendFailSessionUnexpectedSpy.interceptNoMsg(100, TimeUnit.MILLISECONDS);
    Assert.assertFalse(repairSubmitted.get());
    Assert.assertEquals(ConsistentSession.State.PREPARING, coordinator.getState());
    Assert.assertFalse(ActiveRepairService.instance.consistent.local.isSessionInProgress(uuid));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoordinatedRepairResult(org.apache.cassandra.repair.CoordinatedRepairResult) Future(org.apache.cassandra.utils.concurrent.Future) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy) TimeoutException(java.util.concurrent.TimeoutException) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 7 with CoordinatedRepairResult

use of org.apache.cassandra.repair.CoordinatedRepairResult in project cassandra by apache.

the class CoordinatorMessagingTest method testMockedMessagingPrepareFailure.

private void testMockedMessagingPrepareFailure(CountDownLatch prepareLatch) throws InterruptedException, ExecutionException, TimeoutException, NoSuchRepairSessionException {
    // we expect FailSession messages to all participants
    MockMessagingSpy sendFailSessionExpectedSpy = createFailSessionSpy(Lists.newArrayList(PARTICIPANT1, PARTICIPANT2, PARTICIPANT3));
    UUID uuid = registerSession(cfs, true, true);
    CoordinatorSession coordinator = ActiveRepairService.instance.consistent.coordinated.registerSession(uuid, PARTICIPANTS, false);
    AtomicBoolean repairSubmitted = new AtomicBoolean(false);
    Promise<CoordinatedRepairResult> repairFuture = AsyncPromise.uncancellable();
    Supplier<Future<CoordinatedRepairResult>> sessionSupplier = () -> {
        repairSubmitted.set(true);
        return repairFuture;
    };
    // coordinator sends prepare requests to create local session and perform anticompaction
    Assert.assertFalse(repairSubmitted.get());
    // execute repair and start prepare phase
    Future<CoordinatedRepairResult> sessionResult = coordinator.execute(sessionSupplier);
    prepareLatch.countDown();
    // prepare completed
    try {
        sessionResult.get(1, TimeUnit.SECONDS);
        fail("Completed session without failure after prepare failed");
    } catch (ExecutionException e) {
    }
    sendFailSessionExpectedSpy.interceptMessageOut(3).get(1, TimeUnit.SECONDS);
    Assert.assertFalse(repairSubmitted.get());
    Assert.assertTrue(sessionResult.isDone());
    Assert.assertNotNull(sessionResult.cause());
    Assert.assertEquals(ConsistentSession.State.FAILED, coordinator.getState());
    Assert.assertFalse(ActiveRepairService.instance.consistent.local.isSessionInProgress(uuid));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoordinatedRepairResult(org.apache.cassandra.repair.CoordinatedRepairResult) Future(org.apache.cassandra.utils.concurrent.Future) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException) MockMessagingSpy(org.apache.cassandra.net.MockMessagingSpy)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 CoordinatedRepairResult (org.apache.cassandra.repair.CoordinatedRepairResult)7 Future (org.apache.cassandra.utils.concurrent.Future)7 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)6 Test (org.junit.Test)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 PrepareConsistentRequest (org.apache.cassandra.repair.messages.PrepareConsistentRequest)4 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)4 UUID (java.util.UUID)3 MockMessagingSpy (org.apache.cassandra.net.MockMessagingSpy)3 RepairSessionResult (org.apache.cassandra.repair.RepairSessionResult)3 FailSession (org.apache.cassandra.repair.messages.FailSession)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 FinalizePropose (org.apache.cassandra.repair.messages.FinalizePropose)2 Assert (org.junit.Assert)2 Collection (java.util.Collection)1 TimeoutException (java.util.concurrent.TimeoutException)1 Token (org.apache.cassandra.dht.Token)1 FinalizeCommit (org.apache.cassandra.repair.messages.FinalizeCommit)1