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

ZOOKEEPER-2849: Exponential back-off retry for Quorum port binding #419

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

brian-lininger
Copy link

Added BackoffStrategy interface with ExponentialBackoffStrategy as a concrete implementation. Enhanced
QuorumCnxManager to utilize the provided BackoffStrategy to determine retry of port binding as opposed to
a fixed interval/count.

  Added BackoffStrategy interface with ExponentialBackoffStrategy as a concrete implementation. Enhanced
  QuorumCnxManager to utilize the provided BackoffStrategy to determine retry of port binding as opposed to
  a fixed interval/count.
  Added missing Apache license header
@@ -946,7 +946,8 @@ protected Election createElectionAlgorithm(int electionAlgorithm){
le = new AuthFastLeaderElection(this, true);
break;
case 3:
qcm = new QuorumCnxManager(this);
qcm = new QuorumCnxManager(this,
ExponentialBackoffStrategy.builder().build());
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should find a way to make this pluggable? Perhaps we can read which backoff strategy to use from a java system property?

Copy link
Contributor

Choose a reason for hiding this comment

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

For instance, it may be nice to have the default strategy perform the existing behavior.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed, included in my upcoming push.

/**
* Builder for instances of {@link ExponentialBackoffStrategy}.
*/
public static final class Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure a builder is the best way to handle this. Since I think it would be nice to have much of this be user configurable, perhaps we can just pull the config from system properties?

Copy link
Author

Choose a reason for hiding this comment

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

I agree that it should be configurable, but I don't think using a Builder pattern precludes this. I'm about to push changes that adds support for using system properties, that's a good idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I probably wasn't clear here. It would be great if it was also possible, since backoff strategy is such a nicely defined interface, if the user could include jar with their own backoff strategy in the classpath and tell zookeeper to use that. What do you think?

Copy link
Author

Choose a reason for hiding this comment

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

That should be doable.

/**
* Unit tests for {@link ExponentialBackoffStrategy}.
*/
public class ExponentialBackoffStrategyTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should extend ZKTestCase

  Unit tests extend ZKTestCase
  Added support for FixedIntervalBackoffStrategy to maintain the current retry behavior.
  BackoffStrategy is now configurable via system properties, user can select the type
  of BackoffStrategy as well as configure it as desired.
 Add FixedIntervalBackoffStrategy and unit test that got missed.
  Add support for external implementations of BackoffStrategy.
Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Looks like this patch has been abandonen.


private void validateInclusiveBetween(long min, long max, long value) {
if(value < min) {
throw new IllegalArgumentException();
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to add some information about the parameter with illegal value. Exception message would be fine for that if you could add it as a parameter of this method.

Same applies to all places where you throw IllegalArgumentException.

* @return a new {@link Builder} instance.
*/
public static Builder builder() {
return new Builder();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why do you need a method for creating Builder instance.

try {
builder.setBackoffMultiplier(Double.valueOf(multiplierProp));
} catch(NumberFormatException nfe) {
LOG.warn("{} is not a valid floating point value, ignoring it.", multiplierProp);
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to add:
...floating point value for backoffMultiplier, ignoring...

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.

3 participants