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

HDDS-11226. Make ExponentialBackoffPolicy maxRetries configurable #6985

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ public void setExponentialPolicyMaxSleep(Duration duration) {
exponentialPolicyMaxSleep = duration;
}

@Config(key = "client.exponential.backoff.max.retries",
defaultValue = "2147483647",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
defaultValue = "2147483647",
defaultValue = String.valueOf(Integer.MAX_VALUE),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

String.valueOf doesn't return constant but defaultValue requires a constant String.
Other way we can change like "" + Integer.MAX_VALUE but this has overhead of StringBuilder.

Copy link
Contributor

@kerneltime kerneltime Jul 29, 2024

Choose a reason for hiding this comment

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

You could define

  private final static string intMax = Integer.toString(Integer.MAX_VALUE);

in this class and then assign defaultValue = intMax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this before. Tried again, but it doesn't work. Same error "Attribute value must be constant".

type = ConfigType.INT,
tags = { OZONE, CLIENT, PERFORMANCE },
description = "Client's max retry value for the exponential backoff policy.")
private int exponentialPolicyMaxRetries = Integer.MAX_VALUE;

public int getExponentialPolicyMaxRetries() {
return exponentialPolicyMaxRetries;
}

public void setExponentialPolicyMaxRetries(int retry) {
exponentialPolicyMaxRetries = retry;
}

@Config(key = "client.retrylimited.retry.interval",
defaultValue = "1s",
type = ConfigType.TIME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private static ExponentialBackoffRetry createExponentialBackoffPolicy(
toTimeDuration(ratisClientConfig.getExponentialPolicyBaseSleep()))
.setMaxSleepTime(
toTimeDuration(ratisClientConfig.getExponentialPolicyMaxSleep()))
.setMaxAttempts(
ratisClientConfig.getExponentialPolicyMaxRetries())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void defaults() {
subject.getWatchRequestTimeout());
assertEquals(fromConfig.getWriteRequestTimeout(),
subject.getWriteRequestTimeout());
assertEquals(fromConfig.getExponentialPolicyMaxRetries(),
subject.getExponentialPolicyMaxRetries());
}

@Test
Expand All @@ -53,16 +55,19 @@ void setAndGet() {
final Duration maxSleep = Duration.ofMinutes(2);
final Duration watchRequestTimeout = Duration.ofMillis(555);
final Duration writeRequestTimeout = Duration.ofMillis(444);
final int maxRetry = 10;

subject.setExponentialPolicyBaseSleep(baseSleep);
subject.setExponentialPolicyMaxSleep(maxSleep);
subject.setWatchRequestTimeout(watchRequestTimeout);
subject.setWriteRequestTimeout(writeRequestTimeout);
subject.setExponentialPolicyMaxRetries(maxRetry);

assertEquals(baseSleep, subject.getExponentialPolicyBaseSleep());
assertEquals(maxSleep, subject.getExponentialPolicyMaxSleep());
assertEquals(watchRequestTimeout, subject.getWatchRequestTimeout());
assertEquals(writeRequestTimeout, subject.getWriteRequestTimeout());
assertEquals(maxRetry, subject.getExponentialPolicyMaxRetries());
}

}