Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

[Conjure Java Runtime] Part 17: 🚨🚚🚨 Optionals for Paxos Learners #4361

Merged
merged 7 commits into from
Oct 31, 2019

Conversation

jeremyk-91
Copy link
Contributor

Goals (and why):

  • Fulfil a prerequisite for internode communication via Conjure Java Runtime

Implementation Description (bullets):

  • Switch PaxosLearner to return Optional<PaxosValue> and fix attendant breaks.
  • Also switched TimelockPaxosLearnerRpcClient to use this.

Testing (What was existing testing like? What have you done to improve it?):

  • Updated tests that used to use nullable values to now use Optionals. These passing should be sufficient.

Concerns (what feedback would you like?):

  • This is obviously an API break, is it unforgivably large?
  • There is no wire break (a wire break would obviously be disastrous) - please confirm this.

Where should we start reviewing?: PaxosLearner

Priority (whenever / two weeks / yesterday): this week please

@changelog-app
Copy link

changelog-app bot commented Oct 30, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

The PaxosLearner interface now returns Optional<PaxosValue> instead of a nullable PaxosValue for the getLearnedValue(seq) and getGreatestLearnedValue() methods. The wire format remains unchanged (so, for example, rolling upgrades of TimeLock, or servers in an embedded leader configuration, are safe). Users who require the old behaviour can use Optional.orElse(null).

Check the box to generate changelog(s)

  • Generate changelog entry

@jeremyk-91 jeremyk-91 changed the title [Conjure Java Runtime] Part 17: 🚚Optionals for Paxos Learners [Conjure Java Runtime] Part 17: 🚚 Optionals for Paxos Learners Oct 30, 2019
assertThat(learner.getGreatestLearnedValue().getData()).isEqualTo(PAXOS_DATA);

assertThat(learner.getGreatestLearnedValue())
.isPresent()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to isPresent can be removed, hasValueSatisfying will also assert that the value is present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right! Will change this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we go further:

Optional<PaxosValue> value = learner.getGreatestLearnedValue();
assertThat(value).map(PaxosValue::getLeaderUUID).contains(PAXOS_UUID);
assertThat(value).map(PaxosValue::getData).contains(PAXOS_DATA);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, map is a method on the OptionalAssert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(yep, changed to OptionalAssert's map)

if (!state.isEmpty()) {
return state.get(state.lastKey());
return Optional.ofNullable(state.get(state.lastKey()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly that empty result is a "non-standard" path I would invert the if.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to above: this shouldn't be null right? since the map is not empty, unless you're thinking it has null values, but non-null keys

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on inverting if (didn't as I just translated what was there, but yeah it does make sense).

I wrote Optional.of() first, but there were some tests that failed. Possibly a bad test, I didn't investigate in detail

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadness is sad

@@ -84,7 +84,7 @@ public void learn(long seq, PaxosValue value) {
Function<Optional<PaxosValue>, T> mapper) {
return PaxosQuorumChecker.collectQuorumResponses(
allLearners,
learner -> mapper.apply(Optional.ofNullable(learner.getLearnedValue(seq))),
learner -> mapper.apply(learner.getLearnedValue(seq)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃

@PathParam("useCase") PaxosUseCase paxosUseCase,
@PathParam("client") String client,
@PathParam("seq") long seq);

@Nullable
@Nonnull
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we need the @Nonnull annotations, since that should be implied with code wide Nonnull by default and also the fact that it's a huge code smell to pass around a null Optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done for consistency with the other methods in the client. I guess now all of them are nonnull it's probably fine to remove them.

@jeremyk-91 jeremyk-91 changed the title [Conjure Java Runtime] Part 17: 🚚 Optionals for Paxos Learners [Conjure Java Runtime] Part 17: 🚨🚚🚨 Optionals for Paxos Learners Oct 30, 2019
@jeremyk-91
Copy link
Contributor Author

Thanks!

@jeremyk-91 jeremyk-91 merged commit 47dacb2 into develop Oct 31, 2019
@delete-merged-branch delete-merged-branch bot deleted the jkong/paxos-learner-truck branch October 31, 2019 11:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants