Skip to content

Commit

Permalink
[#1048] fix(coord): ExcludeNodes does not take effect when the coordi…
Browse files Browse the repository at this point in the history
…nator restarts. (#1049)

### What changes were proposed in this pull request?

Make updateExcludeNodes no delay first time.

### Why are the changes needed?

Fix: #1048.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

UT.

Co-authored-by: leixianming <leixianming@didiglobal.com>
  • Loading branch information
leixm and leixianming committed Jul 28, 2023
1 parent a5ba479 commit 57c35ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public SimpleClusterManager(CoordinatorConf conf, Configuration hadoopConf) thro
ThreadUtils.getDaemonSingleThreadScheduledExecutor("UpdateExcludeNodes");
checkNodesExecutorService.scheduleAtFixedRate(
() -> updateExcludeNodes(excludeNodesPath),
updateNodesInterval,
0,
updateNodesInterval,
TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.stream.Collectors;

import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Uninterruptibles;
import org.apache.commons.collections.CollectionUtils;
import org.apache.hadoop.conf.Configuration;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -487,6 +488,32 @@ public void updateExcludeNodesTest() throws Exception {
}
}

@Test
public void excludeNodesNoDelayTest() throws Exception {
String excludeNodesFolder =
(new File(ClassLoader.getSystemResource("empty").getFile())).getParent();
String excludeNodesPath = excludeNodesFolder + "/excludeNodes";
CoordinatorConf ssc = new CoordinatorConf();
ssc.setString(
CoordinatorConf.COORDINATOR_EXCLUDE_NODES_FILE_PATH,
URI.create(excludeNodesPath).toString());
ssc.setLong(CoordinatorConf.COORDINATOR_EXCLUDE_NODES_CHECK_INTERVAL, 5000);

final Set<String> nodes = Sets.newHashSet("node1-1999", "node2-1999");
writeExcludeHosts(excludeNodesPath, nodes);

try (SimpleClusterManager scm = new SimpleClusterManager(ssc, new Configuration())) {
// waiting for excludeNode file parse.
Uninterruptibles.sleepUninterruptibly(20, TimeUnit.MILLISECONDS);
scm.add(new ServerNode("node1-1999", "ip", 0, 100L, 50L, 20, 10, testTags));
scm.add(new ServerNode("node2-1999", "ip", 0, 100L, 50L, 20, 10, testTags));
scm.add(new ServerNode("node3-1999", "ip", 0, 100L, 50L, 20, 10, testTags));
scm.add(new ServerNode("node4-1999", "ip", 0, 100L, 50L, 20, 10, testTags));
assertEquals(4, scm.getNodesNum());
assertEquals(2, scm.getExcludeNodes().size());
}
}

private void writeExcludeHosts(String path, Set<String> values) throws Exception {
try (PrintWriter pw = new PrintWriter(new FileWriter(path))) {
// have empty line as value
Expand Down

0 comments on commit 57c35ad

Please sign in to comment.