@Test public void forceAgreedStateCanBeUsedToGainKnowledge() { assertThat(store.forceAgreedState(1, FORTY_TWO)).isEqualTo(ONE_AND_FORTY_TWO); PaxosTimestampBoundStore additionalStore = createPaxosTimestampBoundStore(1); assertThat(additionalStore.forceAgreedState(1, null)).isEqualTo(ONE_AND_FORTY_TWO); }
@VisibleForTesting SequenceAndBound forceAgreedState(long seq, @Nullable Long oldState) { if (seq <= PaxosAcceptor.NO_LOG_ENTRY) { return ImmutableSequenceAndBound.of(PaxosAcceptor.NO_LOG_ENTRY, 0L); } Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } while (true) { try { byte[] acceptedValue = proposer.propose(seq, oldState == null ? null : PtBytes.toBytes(oldState)); Preconditions.checkNotNull(acceptedValue, "Proposed value can't be null, but was in sequence %s", seq); return ImmutableSequenceAndBound.of(seq, PtBytes.toLong(acceptedValue)); } catch (PaxosRoundFailureException e) { waitForRandomBackoff(e, Thread::sleep); } } }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound forceAgreedState(long seq, @Nullable Long oldState) { if (seq <= PaxosAcceptor.NO_LOG_ENTRY) { return ImmutableSequenceAndBound.of(PaxosAcceptor.NO_LOG_ENTRY, 0L); } Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } while (true) { try { byte[] acceptedValue = proposer.propose(seq, oldState == null ? null : PtBytes.toBytes(oldState)); Preconditions.checkNotNull(acceptedValue, "Proposed value can't be null, but was in sequence %s", seq); return ImmutableSequenceAndBound.of(seq, PtBytes.toLong(acceptedValue)); } catch (PaxosRoundFailureException e) { waitForRandomBackoff(e, Thread::sleep); } } } }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound forceAgreedState(long seq, @Nullable Long oldState) { if (seq <= PaxosAcceptor.NO_LOG_ENTRY) { return ImmutableSequenceAndBound.of(PaxosAcceptor.NO_LOG_ENTRY, 0L); } Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } while (true) { try { byte[] acceptedValue = proposer.propose(seq, oldState == null ? null : PtBytes.toBytes(oldState)); Preconditions.checkNotNull(acceptedValue, "Proposed value can't be null, but was in sequence %s", seq); return ImmutableSequenceAndBound.of(seq, PtBytes.toLong(acceptedValue)); } catch (PaxosRoundFailureException e) { waitForRandomBackoff(e, Thread::sleep); } } } PaxosTimestampBoundStore(
            PaxosProposer proposer,
            PaxosLearner knowledge,
            PaxosAcceptorNetworkClient acceptorNetworkClient,
            PaxosLearnerNetworkClient learnerClient,
            long maximumWaitBeforeProposalMs); }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound forceAgreedState(long seq, @Nullable Long oldState) { if (seq <= PaxosAcceptor.NO_LOG_ENTRY) { return ImmutableSequenceAndBound.of(PaxosAcceptor.NO_LOG_ENTRY, 0L); } Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } while (true) { try { byte[] acceptedValue = proposer.propose(seq, oldState == null ? null : PtBytes.toBytes(oldState)); Preconditions.checkNotNull(acceptedValue, "Proposed value can't be null, but was in sequence %s", seq); return ImmutableSequenceAndBound.of(seq, PtBytes.toLong(acceptedValue)); } catch (PaxosRoundFailureException e) { waitForRandomBackoff(e, Thread::sleep); } } } PaxosTimestampBoundStore(
            PaxosProposer proposer,
            PaxosLearner knowledge,
            PaxosAcceptorNetworkClient acceptorNetworkClient,
            PaxosLearnerNetworkClient learnerClient,
            long maximumWaitBeforeProposalMs); @Override synchronized long getUpperLimit(); @Override synchronized void storeUpperLimit(long limit); }
PaxosTimestampBoundStore implements TimestampBoundStore { @VisibleForTesting SequenceAndBound forceAgreedState(long seq, @Nullable Long oldState) { if (seq <= PaxosAcceptor.NO_LOG_ENTRY) { return ImmutableSequenceAndBound.of(PaxosAcceptor.NO_LOG_ENTRY, 0L); } Optional<SequenceAndBound> state = getLearnedState(seq); if (state.isPresent()) { return state.get(); } while (true) { try { byte[] acceptedValue = proposer.propose(seq, oldState == null ? null : PtBytes.toBytes(oldState)); Preconditions.checkNotNull(acceptedValue, "Proposed value can't be null, but was in sequence %s", seq); return ImmutableSequenceAndBound.of(seq, PtBytes.toLong(acceptedValue)); } catch (PaxosRoundFailureException e) { waitForRandomBackoff(e, Thread::sleep); } } } PaxosTimestampBoundStore(
            PaxosProposer proposer,
            PaxosLearner knowledge,
            PaxosAcceptorNetworkClient acceptorNetworkClient,
            PaxosLearnerNetworkClient learnerClient,
            long maximumWaitBeforeProposalMs); @Override synchronized long getUpperLimit(); @Override synchronized void storeUpperLimit(long limit);  }