Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACCUMULO-4847 Fix Retry utility's API #399

Merged
merged 1 commit into from Mar 14, 2018

Conversation

ctubbsii
Copy link
Member

@ctubbsii ctubbsii commented Mar 14, 2018

Create a builder API for Retry and RetryFactory, so that the parameters
(which all have the same type) cannot be easily confused for one another
and cause "sleep-until-heat-death-of-the-universe" bugs.

Also fix a minor bug which is caused by the assumption that nanoTime is
always positive. It is normal for nanoTime to be negative, only the
differences between two times is guaranteed to be positive.

@ctubbsii ctubbsii self-assigned this Mar 14, 2018
@ctubbsii ctubbsii force-pushed the 1.7-retry-fixes-stuck-locator branch from 42cff94 to a1528ef Compare March 14, 2018 17:11
return new RetryFactoryBuilder();
}

private static class RetryFactoryBuilder implements NeedsRetries, NeedsRetryDelay, NeedsTimeIncrement, NeedsMaxWait, NeedsLogInterval, BuilderDone,
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you changed to the builder pattern why not rename to "RetryBuilder". I think its confusing to intermingle the terms.

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically... it's a builder for RetryFactory AND Retry.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like overkill since we only use the default settings.

Copy link
Member Author

Choose a reason for hiding this comment

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

We use other settings, too, but the intent was to have a flexible class to get consistent retry implementations. This change doesn't modify that original intent... it just makes the API safer so it can't be easily used incorrectly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I understand why you did it that way, it just seems overly complex for internal code. I was thinking we could just modify the factory constructor to not have any parameters and static methods to change something other than the defaults.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was trying to move away from "defaults", because every retry scenario is different, and code in Accumulo tends to be written with the bad habit of using what's there, rather than thinking through what makes sense in the specific context.

public void logRetry(Logger log, String message, Throwable t) {
// log the first time as debug, and then after every logInterval as a warning
long now = System.nanoTime();
if (lastRetryLog < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this check hasNeverLogged?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup. Looks like I missed that.

@Override
public NeedsRetryDelay maxRetries(long max) {
checkState();
Preconditions.checkArgument(max >= 0, "Maximum number of retries must not be negative");
Copy link
Contributor

Choose a reason for hiding this comment

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

could add unit test for these new checks

Copy link
Member Author

Choose a reason for hiding this comment

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

Wilco


@Override
public Retry createRetry() {
return new Retry(maxRetries, initialWait, waitIncrement, maxWait, logInterval);
Copy link
Contributor

Choose a reason for hiding this comment

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

I manually checked the args and they line up. Then I looked for a test that does this, it seems like the properArgumentsInRetry test should check that these line up.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does.

Create a builder API for Retry and RetryFactory, so that the parameters
(which all have the same type) cannot be easily confused for one another
and cause "sleep-until-heat-death-of-the-universe" bugs.

Also fix a minor bug which is caused by the assumption that nanoTime is
always positive. It is normal for nanoTime to be negative, only the
differences between two times is guaranteed to be positive.
@ctubbsii ctubbsii force-pushed the 1.7-retry-fixes-stuck-locator branch from 734ceaf to db04591 Compare March 14, 2018 20:16
@ctubbsii ctubbsii merged commit cf0dd9c into apache:1.7 Mar 14, 2018
@ctubbsii ctubbsii deleted the 1.7-retry-fixes-stuck-locator branch March 14, 2018 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants