Skip to content

Commit

Permalink
Remove checkDuration, set refreshDuration=1h (default)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanvipenumudy committed Oct 12, 2023
1 parent 15ee094 commit e2334d0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,7 @@ public final class OzoneConfigKeys {
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION =
"ozone.scm.network.topology.schema.file.refresh.duration";
public static final String
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION_DEFAULT = "3h";

public static final String
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION =
"ozone.scm.network.topology.schema.file.check.duration";
public static final String
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION_DEFAULT = "5m";
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION_DEFAULT = "1h";

/**
* There is no need to instantiate this class.
Expand Down
12 changes: 1 addition & 11 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3651,21 +3651,11 @@
</property>
<property>
<name>ozone.scm.network.topology.schema.file.refresh.duration</name>
<value>3h</value>
<value>1h</value>
<tag>SCM, OZONE, OM</tag>
<description>The duration at which we periodically fetch the updated network topology schema file from SCM.
</description>
</property>
<property>
<name>ozone.scm.network.topology.schema.file.check.duration</name>
<value>5m</value>
<tag>SCM, OZONE, OM</tag>
<description>The duration at which we periodically check if it is the time for fetching the updated network
topology schema file from SCM. Example: If ozone.scm.network.topology.schema.file.refresh.duration=3h and
ozone.scm.network.topology.schema.file.check.duration=5m, the actual refresh duration will occur for each
3h +/- 5m.
</description>
</property>
<property>
<name>ozone.scm.ha.ratis.server.snapshot.creation.gap</name>
<value>1024</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import static java.util.Objects.requireNonNull;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION_DEFAULT;

/**
* This client implements a background thread which periodically checks and
Expand All @@ -63,7 +61,7 @@ public String getNetworkTopology() {
}

public void refetchNetworkTopology() {
checkAndRefresh(Duration.ZERO, Instant.now());
checkAndRefresh();
}

public void start(ConfigurationSource conf) throws IOException {
Expand Down Expand Up @@ -98,14 +96,12 @@ private void scheduleNetworkTopologyPoller(ConfigurationSource conf,
.setDaemon(true)
.build();
executorService = Executors.newScheduledThreadPool(1, threadFactory);
Duration interval = parseRefreshCheckDuration(conf);
Duration initialDelay = Duration.between(Instant.now(), nextRefresh);

LOG.info("Scheduling NetworkTopologyPoller with initial delay of {} " +
"and interval of {}", initialDelay, interval);
executorService.scheduleAtFixedRate(
() -> checkAndRefresh(refreshDuration, initialInvocation),
initialDelay.toMillis(), interval.toMillis(),
LOG.info("Scheduling NetworkTopologyPoller with an initial delay of {}.",
initialDelay);
executorService.scheduleAtFixedRate(() -> checkAndRefresh(),
initialDelay.toMillis(), refreshDuration.toMillis(),
TimeUnit.MILLISECONDS);
}

Expand All @@ -117,30 +113,18 @@ public static Duration parseRefreshDuration(ConfigurationSource conf) {
return Duration.ofMillis(refreshDurationInMs);
}

public static Duration parseRefreshCheckDuration(ConfigurationSource conf) {
long refreshCheckInMs = conf.getTimeDuration(
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION,
OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION_DEFAULT,
TimeUnit.MILLISECONDS);
return Duration.ofMillis(refreshCheckInMs);
}

private synchronized void checkAndRefresh(Duration refreshDuration,
Instant initialInvocation) {
private synchronized void checkAndRefresh() {
String current = cache.get();
Instant nextRefresh = initialInvocation.plus(refreshDuration);
if (nextRefresh.isBefore(Instant.now())) {
try {
String newTopology = scmBlockLocationProtocol.getNetworkTopology();
if (!newTopology.equals(current)) {
cache.set(newTopology);
LOG.info("Updated network topology schema file fetched from " +
"SCM: {}.", newTopology);
}
} catch (IOException e) {
throw new UncheckedIOException(
"Error fetching updated network topology schema file from SCM", e);
try {
String newTopology = scmBlockLocationProtocol.getNetworkTopology();
if (!newTopology.equals(current)) {
cache.set(newTopology);
LOG.info("Updated network topology schema file fetched from " +
"SCM: {}.", newTopology);
}
} catch (IOException e) {
throw new UncheckedIOException(
"Error fetching updated network topology schema file from SCM", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.io.IOException;
import java.util.UUID;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION;

/**
Expand All @@ -52,7 +51,6 @@ public static void init() throws Exception {
String scmId = UUID.randomUUID().toString();
String omId = UUID.randomUUID().toString();
conf.set(OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_REFRESH_DURATION, "15s");
conf.set(OZONE_SCM_NETWORK_TOPOLOGY_SCHEMA_FILE_CHECK_DURATION, "2s");
cluster = MiniOzoneCluster.newBuilder(conf)
.setClusterId(clusterId)
.setScmId(scmId)
Expand Down

0 comments on commit e2334d0

Please sign in to comment.