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();
}
}
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);
}
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);
}
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);
}
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.");
}
}
Aggregations