Skip to content

Commit

Permalink
HDDS-8745. Let ConfigType.TIME apply to Duration (#4932)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai committed Oct 27, 2023
1 parent d1a92b9 commit 6839345
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public static class Conf {
description = "Disk space usage information will be refreshed with the"
+ "specified period following the completion of the last check."
)
private long refreshPeriod;
private Duration refreshPeriod;

public void setRefreshPeriod(Duration duration) {
refreshPeriod = duration.toMillis();
refreshPeriod = duration;
}

public Duration getRefreshPeriod() {
return Duration.ofMillis(refreshPeriod);
return refreshPeriod;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,10 @@ public static class Conf {
description = "Disk space usage information will be refreshed with the"
+ "specified period following the completion of the last check."
)
private long refreshPeriod;

public void setRefreshPeriod(long millis) {
refreshPeriod = millis;
}
private Duration refreshPeriod;

public Duration getRefreshPeriod() {
return Duration.ofMillis(refreshPeriod);
return refreshPeriod;
}

static String configKeyForRefreshPeriod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public void setMaxOutstandingRequests(int maxOutstandingRequests) {
"The timeout duration for ratis client request (except "
+ "for watch request). It should be set greater than leader "
+ "election timeout in Ratis.")
private long rpcRequestTimeout = Duration.ofSeconds(60).toMillis();
private Duration rpcRequestTimeout = Duration.ofSeconds(60);

public Duration getRpcRequestTimeout() {
return Duration.ofMillis(rpcRequestTimeout);
return rpcRequestTimeout;
}

public void setRpcRequestTimeout(Duration duration) {
this.rpcRequestTimeout = duration.toMillis();
rpcRequestTimeout = duration;
}

@Config(key = "rpc.watch.request.timeout",
Expand All @@ -87,14 +87,14 @@ public void setRpcRequestTimeout(Duration duration) {
"The timeout duration for ratis client watch request. "
+ "Timeout for the watch API in Ratis client to acknowledge a "
+ "particular request getting replayed to all servers.")
private long rpcWatchRequestTimeout = Duration.ofSeconds(180).toMillis();
private Duration rpcWatchRequestTimeout = Duration.ofSeconds(180);

public Duration getRpcWatchRequestTimeout() {
return Duration.ofMillis(rpcWatchRequestTimeout);
return rpcWatchRequestTimeout;
}

public void setRpcWatchRequestTimeout(Duration duration) {
this.rpcWatchRequestTimeout = duration.toMillis();
rpcWatchRequestTimeout = duration;
}
}

Expand All @@ -103,30 +103,29 @@ public void setRpcWatchRequestTimeout(Duration duration) {
type = ConfigType.TIME,
tags = { OZONE, CLIENT, PERFORMANCE },
description = "Timeout for ratis client write request.")
private long writeRequestTimeoutInMs =
Duration.ofMinutes(5).toMillis();
private Duration writeRequestTimeout = Duration.ofMinutes(5);

public Duration getWriteRequestTimeout() {
return Duration.ofMillis(writeRequestTimeoutInMs);
return writeRequestTimeout;
}

public void setWriteRequestTimeout(Duration duration) {
writeRequestTimeoutInMs = duration.toMillis();
writeRequestTimeout = duration;
}

@Config(key = "client.request.watch.timeout",
defaultValue = "3m",
type = ConfigType.TIME,
tags = { OZONE, CLIENT, PERFORMANCE },
description = "Timeout for ratis client watch request.")
private long watchRequestTimeoutInMs = Duration.ofMinutes(3).toMillis();
private Duration watchRequestTimeout = Duration.ofMinutes(3);

public Duration getWatchRequestTimeout() {
return Duration.ofMillis(watchRequestTimeoutInMs);
return watchRequestTimeout;
}

public void setWatchRequestTimeout(Duration duration) {
watchRequestTimeoutInMs = duration.toMillis();
watchRequestTimeout = duration;
}

@Config(key = "client.multilinear.random.retry.policy",
Expand Down Expand Up @@ -156,15 +155,14 @@ public void setMultilinearPolicy(String multilinearPolicy) {
+ " With the default base sleep of 4s, the sleep duration for ith"
+ " retry is min(4 * pow(2, i), max_sleep) * r, where r is "
+ "random number in the range [0.5, 1.5).")
private long exponentialPolicyBaseSleepInMs =
Duration.ofSeconds(4).toMillis();
private Duration exponentialPolicyBaseSleep = Duration.ofSeconds(4);

public Duration getExponentialPolicyBaseSleep() {
return Duration.ofMillis(exponentialPolicyBaseSleepInMs);
return exponentialPolicyBaseSleep;
}

public void setExponentialPolicyBaseSleep(Duration duration) {
exponentialPolicyBaseSleepInMs = duration.toMillis();
exponentialPolicyBaseSleep = duration;
}

@Config(key = "client.exponential.backoff.max.sleep",
Expand All @@ -175,15 +173,14 @@ public void setExponentialPolicyBaseSleep(Duration duration) {
+ "policy is limited by the configured max sleep. Refer "
+ "dfs.ratis.client.exponential.backoff.base.sleep for further "
+ "details.")
private long exponentialPolicyMaxSleepInMs =
Duration.ofSeconds(40).toMillis();
private Duration exponentialPolicyMaxSleep = Duration.ofSeconds(40);

public Duration getExponentialPolicyMaxSleep() {
return Duration.ofMillis(exponentialPolicyMaxSleepInMs);
return exponentialPolicyMaxSleep;
}

public void setExponentialPolicyMaxSleep(Duration duration) {
exponentialPolicyMaxSleepInMs = duration.toMillis();
exponentialPolicyMaxSleep = duration;
}

@Config(key = "client.retrylimited.retry.interval",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class ScmConfig extends ReconfigurableConfig {
+ "queued for deletion. Unit could be defined with "
+ "postfix (ns,ms,s,m,h,d). "
)
private long blockDeletionInterval = Duration.ofSeconds(60).toMillis();
private Duration blockDeletionInterval = Duration.ofSeconds(60);

@Config(key = "init.default.layout.version",
defaultValue = "-1",
Expand All @@ -131,11 +131,11 @@ public class ScmConfig extends ReconfigurableConfig {
private int defaultLayoutVersionOnInit = -1;

public Duration getBlockDeletionInterval() {
return Duration.ofMillis(blockDeletionInterval);
return blockDeletionInterval;
}

public void setBlockDeletionInterval(Duration duration) {
this.blockDeletionInterval = duration.toMillis();
blockDeletionInterval = duration;
}

public void setKerberosPrincipal(String kerberosPrincipal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hdds.conf;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -59,6 +60,14 @@ public class SimpleConfiguration extends SimpleConfigurationParent {
tags = ConfigTag.MANAGEMENT)
private long waitTime;

@Config(key = "duration",
type = ConfigType.TIME,
timeUnit = TimeUnit.MINUTES,
defaultValue = "1h",
description = "N/A",
tags = ConfigTag.MANAGEMENT)
private Duration duration;

@Config(key = "class",
type = ConfigType.CLASS,
defaultValue = "java.lang.Object",
Expand Down Expand Up @@ -139,4 +148,12 @@ public double getThreshold() {
public void setThreshold(double threshold) {
this.threshold = threshold;
}

public Duration getDuration() {
return duration;
}

public void setDuration(Duration duration) {
this.duration = duration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.OutputStreamWriter;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -113,6 +114,8 @@ public void getConfigurationObject() {
ozoneConfig.setBoolean("test.scm.client.enabled", true);
ozoneConfig.setInt("test.scm.client.port", 5555);
ozoneConfig.setTimeDuration("test.scm.client.wait", 10, TimeUnit.MINUTES);
ozoneConfig.setTimeDuration("test.scm.client.duration",
3, TimeUnit.SECONDS);
ozoneConfig.set("test.scm.client.class", Integer.class.getName());
ozoneConfig.setDouble("test.scm.client.threshold", 10.5);

Expand All @@ -126,6 +129,7 @@ public void getConfigurationObject() {
Assertions.assertEquals(600, configuration.getWaitTime());
Assertions.assertSame(Integer.class, configuration.getMyClass());
Assertions.assertEquals(10.5, configuration.getThreshold());
Assertions.assertEquals(Duration.ofSeconds(3), configuration.getDuration());
}

@Test
Expand All @@ -139,6 +143,7 @@ public void getConfigurationObjectWithDefault() {
Assertions.assertEquals(9878, configuration.getPort());
Assertions.assertSame(Object.class, configuration.getMyClass());
Assertions.assertEquals(10, configuration.getThreshold());
Assertions.assertEquals(Duration.ofHours(1), configuration.getDuration());
}

@Test
Expand All @@ -152,6 +157,7 @@ public void setConfigFromObject() {
object.setWaitTime(600);
object.setMyClass(this.getClass());
object.setThreshold(10.5);
object.setDuration(Duration.ofMillis(100));

OzoneConfiguration subject = new OzoneConfiguration();

Expand All @@ -173,6 +179,9 @@ public void setConfigFromObject() {
subject.getClass("test.scm.client.class", null));
Assertions.assertEquals(object.getThreshold(),
subject.getDouble("test.scm.client.threshold", 20.5));
Assertions.assertEquals(object.getDuration().toMillis(),
subject.getTimeDuration("test.scm.client.duration", 0,
TimeUnit.MILLISECONDS));
}

@Test
Expand Down
Loading

0 comments on commit 6839345

Please sign in to comment.