Search in sources :

Example 1 with FinalizeCommit

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

the class CoordinatorSession method finalizeCommit.

public synchronized void finalizeCommit(Executor executor) {
    Preconditions.checkArgument(allStates(State.FINALIZE_PROMISED));
    logger.debug("Sending FinalizeCommit message to {}", participants);
    FinalizeCommit message = new FinalizeCommit(sessionID);
    for (final InetAddress participant : participants) {
        executor.execute(() -> sendMessage(participant, message));
    }
    setAll(State.FINALIZED);
}
Also used : FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) InetAddress(java.net.InetAddress)

Example 2 with FinalizeCommit

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

the class LocalSessionTest method finalizeCommitSuccessCase.

/**
     * Session state should be set to finalized, sstables should be promoted
     * to repaired. No messages should be sent to the coordinator
     */
@Test
public void finalizeCommitSuccessCase() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    // create session and move to finalized promised
    sessions.prepareForTest(sessionID);
    sessions.maybeSetRepairing(sessionID);
    sessions.handleFinalizeProposeMessage(COORDINATOR, new FinalizePropose(sessionID));
    sessions.sentMessages.clear();
    LocalSession session = sessions.getSession(sessionID);
    sessions.handleFinalizeCommitMessage(PARTICIPANT1, new FinalizeCommit(sessionID));
    Assert.assertEquals(FINALIZED, session.getState());
    Assert.assertEquals(session, sessions.loadUnsafe(sessionID));
    Assert.assertTrue(sessions.sentMessages.isEmpty());
}
Also used : FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) UUID(java.util.UUID) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 3 with FinalizeCommit

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

the class LocalSessionTest method finalizeCommitNonExistantSession.

@Test
public void finalizeCommitNonExistantSession() {
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    UUID fakeID = UUIDGen.getTimeUUID();
    sessions.handleFinalizeCommitMessage(PARTICIPANT1, new FinalizeCommit(fakeID));
    Assert.assertNull(sessions.getSession(fakeID));
    Assert.assertTrue(sessions.sentMessages.isEmpty());
}
Also used : FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) UUID(java.util.UUID) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 4 with FinalizeCommit

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

the class CoordinatorSessionTest method successCase.

/**
     * Tests the complete coordinator side consistent repair cycle
     */
@Test
public void successCase() {
    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());
    coordinator.handleFinalizePromise(PARTICIPANT2, true);
    Assert.assertEquals(ConsistentSession.State.REPAIRING, coordinator.getState());
    // set the finalizeCommit callback so we can verify the state when it's called
    Assert.assertFalse(coordinator.finalizeCommitCalled);
    coordinator.onFinalizeCommit = () -> Assert.assertEquals(FINALIZE_PROMISED, coordinator.getState());
    coordinator.handleFinalizePromise(PARTICIPANT3, true);
    Assert.assertTrue(coordinator.finalizeCommitCalled);
    Assert.assertEquals(ConsistentSession.State.FINALIZED, coordinator.getState());
    for (InetAddress participant : PARTICIPANTS) {
        RepairMessage expected = new FinalizeCommit(coordinator.sessionID);
        assertMessageSent(coordinator, participant, expected);
    }
    Assert.assertTrue(sessionResult.isDone());
    Assert.assertFalse(hasFailures.get());
}
Also used : FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) 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)

Example 5 with FinalizeCommit

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

the class LocalSessionTest method finalRepairedAtFinalized.

@Test
public void finalRepairedAtFinalized() {
    UUID sessionID = registerSession();
    InstrumentedLocalSessions sessions = new InstrumentedLocalSessions();
    sessions.start();
    sessions.prepareForTest(sessionID);
    sessions.maybeSetRepairing(sessionID);
    sessions.handleFinalizeProposeMessage(COORDINATOR, new FinalizePropose(sessionID));
    sessions.handleFinalizeCommitMessage(PARTICIPANT1, new FinalizeCommit(sessionID));
    LocalSession session = sessions.getSession(sessionID);
    Assert.assertTrue(session.repairedAt != ActiveRepairService.UNREPAIRED_SSTABLE);
    Assert.assertEquals(session.repairedAt, sessions.getFinalSessionRepairedAt(sessionID));
}
Also used : FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) UUID(java.util.UUID) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Aggregations

FinalizeCommit (org.apache.cassandra.repair.messages.FinalizeCommit)5 AbstractRepairTest (org.apache.cassandra.repair.AbstractRepairTest)4 Test (org.junit.Test)4 UUID (java.util.UUID)3 FinalizePropose (org.apache.cassandra.repair.messages.FinalizePropose)3 InetAddress (java.net.InetAddress)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Executor (java.util.concurrent.Executor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RepairSessionResult (org.apache.cassandra.repair.RepairSessionResult)1 PrepareConsistentRequest (org.apache.cassandra.repair.messages.PrepareConsistentRequest)1 RepairMessage (org.apache.cassandra.repair.messages.RepairMessage)1