diff --git a/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java b/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java index 92552f27d..e12167d29 100644 --- a/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java +++ b/src/main/java/org/opensearch/ad/AnomalyDetectorPlugin.java @@ -41,7 +41,7 @@ import org.opensearch.ad.cluster.ADClusterEventListener; import org.opensearch.ad.cluster.ADDataMigrator; import org.opensearch.ad.cluster.HashRing; -import org.opensearch.ad.cluster.MasterEventListener; +import org.opensearch.ad.cluster.LeadEventListener; import org.opensearch.ad.constant.CommonName; import org.opensearch.ad.dataprocessor.IntegerSensitiveSingleFeatureLinearUniformInterpolator; import org.opensearch.ad.dataprocessor.Interpolator; @@ -731,7 +731,7 @@ public PooledObject wrap(LinkedBuffer obj) { new ADClusterEventListener(clusterService, hashRing), adCircuitBreakerService, adStats, - new MasterEventListener(clusterService, threadPool, client, getClock(), clientUtil, nodeFilter), + new LeadEventListener(clusterService, threadPool, client, getClock(), clientUtil, nodeFilter), nodeFilter, multiEntityResultHandler, checkpoint, diff --git a/src/main/java/org/opensearch/ad/cluster/HashRing.java b/src/main/java/org/opensearch/ad/cluster/HashRing.java index d2fad598d..5995f636a 100644 --- a/src/main/java/org/opensearch/ad/cluster/HashRing.java +++ b/src/main/java/org/opensearch/ad/cluster/HashRing.java @@ -130,7 +130,7 @@ public boolean isHashRingInited() { } /** - * Build AD version based circles with discovery node delta change. Listen to master event in + * Build AD version based circles with discovery node delta change. Listen to lead event in * {@link ADClusterEventListener#clusterChanged(ClusterChangedEvent)}. * Will remove the removed nodes from cache and send request to newly added nodes to get their * plugin information; then add new nodes to AD version hash ring. diff --git a/src/main/java/org/opensearch/ad/cluster/MasterEventListener.java b/src/main/java/org/opensearch/ad/cluster/LeadEventListener.java similarity index 97% rename from src/main/java/org/opensearch/ad/cluster/MasterEventListener.java rename to src/main/java/org/opensearch/ad/cluster/LeadEventListener.java index 541538093..467c48e7a 100644 --- a/src/main/java/org/opensearch/ad/cluster/MasterEventListener.java +++ b/src/main/java/org/opensearch/ad/cluster/LeadEventListener.java @@ -28,7 +28,7 @@ import com.google.common.annotations.VisibleForTesting; -public class MasterEventListener implements LocalNodeMasterListener { +public class LeadEventListener implements LocalNodeMasterListener { private Cancellable checkpointIndexRetentionCron; private Cancellable hourlyCron; @@ -39,7 +39,7 @@ public class MasterEventListener implements LocalNodeMasterListener { private ClientUtil clientUtil; private DiscoveryNodeFilterer nodeFilter; - public MasterEventListener( + public LeadEventListener( ClusterService clusterService, ThreadPool threadPool, Client client, diff --git a/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java b/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java index 18cf3ff2e..b7d925f8d 100644 --- a/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java +++ b/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java @@ -687,7 +687,7 @@ public void onMaster() { .scheduleWithFixedDelay(() -> rolloverAndDeleteHistoryIndex(), historyRolloverPeriod, executorName()); } catch (Exception e) { // This should be run on cluster startup - logger.error("Error rollover AD result indices. " + "Can't rollover AD result until master node is restarted.", e); + logger.error("Error rollover AD result indices. " + "Can't rollover AD result until lead node is restarted.", e); } } diff --git a/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java b/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java index 4f609439c..5a5a6a027 100644 --- a/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java +++ b/src/main/java/org/opensearch/ad/settings/AnomalyDetectorSettings.java @@ -87,8 +87,8 @@ private AnomalyDetectorSettings() {} ); // Opensearch-only setting. Doesn't plan to use the value of the legacy setting - // AD_RESULT_HISTORY_MAX_DOCS as that's too low. If the master node uses opendistro code, - // it uses the legacy setting. If the master node uses opensearch code, it uses the new setting. + // AD_RESULT_HISTORY_MAX_DOCS as that's too low. If the lead node uses opendistro code, + // it uses the legacy setting. If the lead node uses opensearch code, it uses the new setting. public static final Setting AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD = Setting .longSetting( "plugins.anomaly_detection.ad_result_history_max_docs_per_shard", diff --git a/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java b/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java index 15785b611..17e611485 100644 --- a/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java +++ b/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java @@ -40,7 +40,7 @@ import org.opensearch.gateway.GatewayService; public class ADClusterEventListenerTests extends AbstractADTest { - private final String masterNodeId = "masterNode"; + private final String leadNodeId = "leadNode"; private final String dataNode1Id = "dataNode1"; private final String clusterName = "multi-node-cluster"; @@ -49,7 +49,7 @@ public class ADClusterEventListenerTests extends AbstractADTest { private HashRing hashRing; private ClusterState oldClusterState; private ClusterState newClusterState; - private DiscoveryNode masterNode; + private DiscoveryNode leadNode; private DiscoveryNode dataNode1; @BeforeClass @@ -70,15 +70,15 @@ public void setUp() throws Exception { clusterService = createClusterService(threadPool); hashRing = mock(HashRing.class); - masterNode = new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + leadNode = new DiscoveryNode(leadNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); dataNode1 = new DiscoveryNode(dataNode1Id, buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT); oldClusterState = ClusterState .builder(new ClusterName(clusterName)) - .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(masterNodeId).add(masterNode)) + .nodes(new DiscoveryNodes.Builder().masterNodeId(leadNodeId).localNodeId(leadNodeId).add(leadNode)) .build(); newClusterState = ClusterState .builder(new ClusterName(clusterName)) - .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)) + .nodes(new DiscoveryNodes.Builder().masterNodeId(leadNodeId).localNodeId(dataNode1Id).add(leadNode).add(dataNode1)) .build(); listener = new ADClusterEventListener(clusterService, hashRing); @@ -107,7 +107,7 @@ public void testIsWarmNode() { ClusterState warmNodeClusterState = ClusterState .builder(new ClusterName(clusterName)) - .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)) + .nodes(new DiscoveryNodes.Builder().masterNodeId(leadNodeId).localNodeId(dataNode1Id).add(leadNode).add(dataNode1)) .blocks(ClusterBlocks.builder().addGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) .build(); listener.clusterChanged(new ClusterChangedEvent("foo", warmNodeClusterState, oldClusterState)); @@ -117,7 +117,7 @@ public void testIsWarmNode() { public void testNotRecovered() { ClusterState blockedClusterState = ClusterState .builder(new ClusterName(clusterName)) - .nodes(new DiscoveryNodes.Builder().masterNodeId(masterNodeId).localNodeId(dataNode1Id).add(masterNode).add(dataNode1)) + .nodes(new DiscoveryNodes.Builder().masterNodeId(leadNodeId).localNodeId(dataNode1Id).add(leadNode).add(dataNode1)) .blocks(ClusterBlocks.builder().addGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) .build(); listener.clusterChanged(new ClusterChangedEvent("foo", blockedClusterState, oldClusterState)); @@ -151,7 +151,7 @@ public void testNodeAdded() { return null; }).when(hashRing).buildCircles(any(), any()); - doAnswer(invocation -> Optional.of(masterNode)).when(hashRing).getOwningNodeWithSameLocalAdVersionForRealtimeAD(any(String.class)); + doAnswer(invocation -> Optional.of(leadNode)).when(hashRing).getOwningNodeWithSameLocalAdVersionForRealtimeAD(any(String.class)); listener.clusterChanged(new ClusterChangedEvent("foo", newClusterState, oldClusterState)); assertTrue(testAppender.containsMessage(ADClusterEventListener.NODE_CHANGED_MSG)); @@ -163,9 +163,9 @@ public void testNodeRemoved() { .builder(new ClusterName(clusterName)) .nodes( new DiscoveryNodes.Builder() - .masterNodeId(masterNodeId) + .masterNodeId(leadNodeId) .localNodeId(dataNode1Id) - .add(new DiscoveryNode(masterNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)) + .add(new DiscoveryNode(leadNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)) .add(dataNode1) .add(new DiscoveryNode("dataNode2", buildNewFakeTransportAddress(), emptyMap(), BUILT_IN_ROLES, Version.CURRENT)) ) diff --git a/src/test/java/org/opensearch/ad/cluster/MasterEventListenerTests.java b/src/test/java/org/opensearch/ad/cluster/LeadEventListenerTests.java similarity index 78% rename from src/test/java/org/opensearch/ad/cluster/MasterEventListenerTests.java rename to src/test/java/org/opensearch/ad/cluster/LeadEventListenerTests.java index 86a88e62c..1c1dec8b0 100644 --- a/src/test/java/org/opensearch/ad/cluster/MasterEventListenerTests.java +++ b/src/test/java/org/opensearch/ad/cluster/LeadEventListenerTests.java @@ -37,14 +37,14 @@ import org.opensearch.threadpool.Scheduler.Cancellable; import org.opensearch.threadpool.ThreadPool; -public class MasterEventListenerTests extends AbstractADTest { +public class LeadEventListenerTests extends AbstractADTest { private ClusterService clusterService; private ThreadPool threadPool; private Client client; private Clock clock; private Cancellable hourlyCancellable; private Cancellable checkpointIndexRetentionCancellable; - private MasterEventListener masterService; + private LeadEventListener leadService; private ClientUtil clientUtil; private DiscoveryNodeFilterer nodeFilter; @@ -67,18 +67,18 @@ public void setUp() throws Exception { ignoredAttributes.put(CommonName.BOX_TYPE_KEY, CommonName.WARM_BOX_TYPE); nodeFilter = new DiscoveryNodeFilterer(clusterService); - masterService = new MasterEventListener(clusterService, threadPool, client, clock, clientUtil, nodeFilter); + leadService = new LeadEventListener(clusterService, threadPool, client, clock, clientUtil, nodeFilter); } public void testOnOffMaster() { - masterService.onMaster(); + leadService.onMaster(); assertThat(hourlyCancellable, is(notNullValue())); assertThat(checkpointIndexRetentionCancellable, is(notNullValue())); - assertTrue(!masterService.getHourlyCron().isCancelled()); - assertTrue(!masterService.getCheckpointIndexRetentionCron().isCancelled()); - masterService.offMaster(); - assertThat(masterService.getCheckpointIndexRetentionCron(), is(nullValue())); - assertThat(masterService.getHourlyCron(), is(nullValue())); + assertTrue(!leadService.getHourlyCron().isCancelled()); + assertTrue(!leadService.getCheckpointIndexRetentionCron().isCancelled()); + leadService.offMaster(); + assertThat(leadService.getCheckpointIndexRetentionCron(), is(nullValue())); + assertThat(leadService.getHourlyCron(), is(nullValue())); } public void testBeforeStop() { @@ -100,11 +100,11 @@ public void testBeforeStop() { return null; }).when(clusterService).addLifecycleListener(any()); - masterService.onMaster(); - assertThat(masterService.getCheckpointIndexRetentionCron(), is(nullValue())); - assertThat(masterService.getHourlyCron(), is(nullValue())); - masterService.offMaster(); - assertThat(masterService.getCheckpointIndexRetentionCron(), is(nullValue())); - assertThat(masterService.getHourlyCron(), is(nullValue())); + leadService.onMaster(); + assertThat(leadService.getCheckpointIndexRetentionCron(), is(nullValue())); + assertThat(leadService.getHourlyCron(), is(nullValue())); + leadService.offMaster(); + assertThat(leadService.getCheckpointIndexRetentionCron(), is(nullValue())); + assertThat(leadService.getHourlyCron(), is(nullValue())); } } diff --git a/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java b/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java index cdf2ffeef..34cced0e5 100644 --- a/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java +++ b/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java @@ -12,8 +12,8 @@ package test.org.opensearch.ad.util; import static org.mockito.Mockito.mock; +import static org.opensearch.cluster.node.DiscoveryNodeRole.CLUSTER_MANAGER_ROLE; import static org.opensearch.cluster.node.DiscoveryNodeRole.DATA_ROLE; -import static org.opensearch.cluster.node.DiscoveryNodeRole.MASTER_ROLE; import java.net.InetAddress; import java.util.ArrayList; @@ -31,20 +31,20 @@ public class ClusterCreation { /** - * Creates a cluster state where local node and master node can be specified + * Creates a cluster state where local node and lead node can be specified * * @param localNode node in allNodes that is the local node - * @param masterNode node in allNodes that is the master node. Can be null if no master exists + * @param leadNode node in allNodes that is the lead node. Can be null if no lead exists * @param allNodes all nodes in the cluster * @return cluster state */ - public static ClusterState state(ClusterName name, DiscoveryNode localNode, DiscoveryNode masterNode, List allNodes) { + public static ClusterState state(ClusterName name, DiscoveryNode localNode, DiscoveryNode leadNode, List allNodes) { DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder(); for (DiscoveryNode node : allNodes) { discoBuilder.add(node); } - if (masterNode != null) { - discoBuilder.masterNodeId(masterNode.getId()); + if (leadNode != null) { + discoBuilder.masterNodeId(leadNode.getId()); } discoBuilder.localNodeId(localNode.getId()); @@ -70,21 +70,21 @@ public static ImmutableOpenMap createDataNodes(int numDat } /** - * Create a cluster state with 1 master node and a few data nodes + * Create a cluster state with 1 lead node and a few data nodes * @param numDataNodes the number of data nodes * @return the cluster state */ public static ClusterState state(int numDataNodes) { - DiscoveryNode masterNode = new DiscoveryNode( + DiscoveryNode leadNode = new DiscoveryNode( "foo0", "foo0", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - Collections.singleton(MASTER_ROLE), + Collections.singleton(CLUSTER_MANAGER_ROLE), Version.CURRENT ); List allNodes = new ArrayList<>(); - allNodes.add(masterNode); + allNodes.add(leadNode); for (int i = 1; i <= numDataNodes - 1; i++) { allNodes .add( @@ -98,6 +98,6 @@ public static ClusterState state(int numDataNodes) { ) ); } - return state(new ClusterName("test"), masterNode, masterNode, allNodes); + return state(new ClusterName("test"), leadNode, leadNode, allNodes); } } diff --git a/src/test/java/test/org/opensearch/ad/util/FakeNode.java b/src/test/java/test/org/opensearch/ad/util/FakeNode.java index 96b181628..b55a0f620 100644 --- a/src/test/java/test/org/opensearch/ad/util/FakeNode.java +++ b/src/test/java/test/org/opensearch/ad/util/FakeNode.java @@ -141,13 +141,13 @@ public DiscoveryNode discoveryNode() { public static void connectNodes(FakeNode... nodes) { List discoveryNodes = new ArrayList(nodes.length); - DiscoveryNode master = nodes[0].discoveryNode(); + DiscoveryNode lead = nodes[0].discoveryNode(); for (int i = 0; i < nodes.length; i++) { discoveryNodes.add(nodes[i].discoveryNode()); } for (FakeNode node : nodes) { - setState(node.clusterService, ClusterCreation.state(new ClusterName("test"), node.discoveryNode(), master, discoveryNodes)); + setState(node.clusterService, ClusterCreation.state(new ClusterName("test"), node.discoveryNode(), lead, discoveryNodes)); } for (FakeNode nodeA : nodes) { for (FakeNode nodeB : nodes) {