Search in sources :

Example 6 with PaxosValue

use of com.palantir.paxos.PaxosValue in project atlasdb by palantir.

the class PaxosLeaderElectionService method getSuspectedLeader.

private Optional<PingableLeader> getSuspectedLeader(boolean useNetwork) {
    PaxosValue value = knowledge.getGreatestLearnedValue();
    if (value == null) {
        return Optional.empty();
    }
    // check leader cache
    String uuid = value.getLeaderUUID();
    if (uuidToServiceCache.containsKey(uuid)) {
        return Optional.of(uuidToServiceCache.get(uuid));
    }
    if (useNetwork) {
        return getSuspectedLeaderOverNetwork(uuid);
    } else {
        return Optional.empty();
    }
}
Also used : PaxosValue(com.palantir.paxos.PaxosValue)

Example 7 with PaxosValue

use of com.palantir.paxos.PaxosValue in project atlasdb by palantir.

the class ProtobufTest method testPaxosValuePersistence.

@Test
public void testPaxosValuePersistence() throws Exception {
    PaxosValue expected;
    byte[] persisted;
    PaxosValue actual;
    expected = new PaxosValue("leader1", 2, new byte[] { 8, 0, 1, 2, 5 });
    persisted = expected.persistToBytes();
    actual = PaxosValue.hydrateFromProto(PaxosPersistence.PaxosValue.parseFrom(persisted));
    assertEquals(expected, actual);
    expected = new PaxosValue("dealer2", 8, null);
    persisted = expected.persistToBytes();
    actual = PaxosValue.hydrateFromProto(PaxosPersistence.PaxosValue.parseFrom(persisted));
    assertEquals(expected, actual);
}
Also used : PaxosValue(com.palantir.paxos.PaxosValue) Test(org.junit.Test)

Example 8 with PaxosValue

use of com.palantir.paxos.PaxosValue in project atlasdb by palantir.

the class ProtobufTest method testPaxosProposalPersistence.

@Test
public void testPaxosProposalPersistence() throws Exception {
    PaxosProposal expected;
    PaxosAcceptorPersistence.PaxosProposal persisted;
    PaxosProposal actual;
    expected = new PaxosProposal(new PaxosProposalId(55, "nonce"), new PaxosValue("red leader", 93, null));
    persisted = expected.persistToProto();
    actual = PaxosProposal.hydrateFromProto(persisted);
    assertEquals(expected, actual);
    expected = new PaxosProposal(new PaxosProposalId(0, "noice"), new PaxosValue("", 93, new byte[] {}));
    persisted = expected.persistToProto();
    actual = PaxosProposal.hydrateFromProto(persisted);
    assertEquals(expected, actual);
}
Also used : PaxosProposal(com.palantir.paxos.PaxosProposal) PaxosProposalId(com.palantir.paxos.PaxosProposalId) PaxosAcceptorPersistence(com.palantir.paxos.persistence.generated.remoting.PaxosAcceptorPersistence) PaxosValue(com.palantir.paxos.PaxosValue) Test(org.junit.Test)

Example 9 with PaxosValue

use of com.palantir.paxos.PaxosValue in project atlasdb by palantir.

the class ProtobufTest method testPaxosPromisePersistence.

@Test
public void testPaxosPromisePersistence() throws Exception {
    PaxosPromise expected;
    PaxosPromiseProto persisted;
    PaxosPromise actual;
    expected = PaxosPromise.reject(new PaxosProposalId(3, "unique"));
    persisted = PaxosPromises.toProto(expected);
    actual = PaxosPromises.fromProto(persisted);
    assertEquals(expected, actual);
    expected = PaxosPromise.accept(new PaxosProposalId(20, "id"), new PaxosProposalId(6, "fire"), new PaxosValue("me", 5, new byte[] { 8, 8, 100 }));
    persisted = PaxosPromises.toProto(expected);
    actual = PaxosPromises.fromProto(persisted);
    assertEquals(expected, actual);
    expected = PaxosPromise.accept(new PaxosProposalId(20, "id"), null, new PaxosValue("me", 5, new byte[] { 8, 8, 100 }));
    persisted = PaxosPromises.toProto(expected);
    actual = PaxosPromises.fromProto(persisted);
    assertEquals(expected, actual);
    expected = PaxosPromise.accept(new PaxosProposalId(20, "id"), null, null);
    persisted = PaxosPromises.toProto(expected);
    actual = PaxosPromises.fromProto(persisted);
    assertEquals(expected, actual);
}
Also used : PaxosPromise(com.palantir.paxos.PaxosPromise) PaxosProposalId(com.palantir.paxos.PaxosProposalId) PaxosPromiseProto(com.palantir.paxos.persistence.generated.remoting.PaxosAcceptorPersistence.PaxosPromiseProto) PaxosValue(com.palantir.paxos.PaxosValue) Test(org.junit.Test)

Example 10 with PaxosValue

use of com.palantir.paxos.PaxosValue in project atlasdb by palantir.

the class PaxosSynchronizer method synchronizeLearner.

public static void synchronizeLearner(PaxosLearner learnerToSynchronize, List<PaxosLearner> paxosLearners) {
    Optional<PaxosValue> mostRecentValue = getMostRecentLearnedValue(paxosLearners);
    if (mostRecentValue.isPresent()) {
        PaxosValue paxosValue = mostRecentValue.get();
        if (paxosValue.equals(learnerToSynchronize.getGreatestLearnedValue())) {
            log.info("Started up and found that our value {} is already the most recent.", SafeArg.of("value", paxosValue));
        } else {
            learnerToSynchronize.learn(paxosValue.getRound(), paxosValue);
            log.info("Started up and learned the most recent value: {}.", SafeArg.of("value", paxosValue));
        }
    } else {
        log.info("Started up, and no one I talked to knows anything yet.");
    }
}
Also used : PaxosValue(com.palantir.paxos.PaxosValue)

Aggregations

PaxosValue (com.palantir.paxos.PaxosValue)10 Test (org.junit.Test)6 PaxosLearner (com.palantir.paxos.PaxosLearner)3 PaxosProposalId (com.palantir.paxos.PaxosProposalId)3 PaxosProposal (com.palantir.paxos.PaxosProposal)2 NotCurrentLeaderException (com.palantir.leader.NotCurrentLeaderException)1 PaxosAcceptor (com.palantir.paxos.PaxosAcceptor)1 PaxosPromise (com.palantir.paxos.PaxosPromise)1 PaxosRoundFailureException (com.palantir.paxos.PaxosRoundFailureException)1 PaxosUpdate (com.palantir.paxos.PaxosUpdate)1 PaxosAcceptorPersistence (com.palantir.paxos.persistence.generated.remoting.PaxosAcceptorPersistence)1 PaxosPromiseProto (com.palantir.paxos.persistence.generated.remoting.PaxosAcceptorPersistence.PaxosPromiseProto)1 Nullable (javax.annotation.Nullable)1