Skip to content

Commit

Permalink
Deprecate public class names with master terminology (#3871)
Browse files Browse the repository at this point in the history
- Add back the usage of old names for some classes for backwards compatibility. Those public classes were renamed from "master" to "cluster manager" In PR #3619 / commit a7e113a.
 - Add a unit test to validate the backwards compatibility of interface `LocalNodeMasterListener` remains.
 - Revert the renaming of class `MasterService`, `FakeThreadPoolMasterService`, `BlockMasterServiceOnMaster` and `BusyMasterServiceDisruption`, as well as instance variable names of class `MasterService`. 
 Because I couldn't solve the compatibility problem of a public method `public ClusterManagerService getMasterService()` (#3871 (comment))

**List of classes that renamed in previous PR:**
In this PR, the usages of the old names should all be restored.
`sever` directory:
interface LocalNodeMasterListener -> LocalNodeClusterManagerListener
final class MasterNodeChangePredicate -> ClusterManagerNodeChangePredicate
NotMasterException -> NotClusterManagerException
NoMasterBlockService -> NoClusterManagerBlockService
UnsafeBootstrapMasterCommand - UnsafeBootstrapClusterManagerCommand
MasterNotDiscoveredException -> ClusterManagerNotDiscoveredException
RestMasterAction -> RestClusterManagerAction

**List of classes that not renamed:**
`sever` directory:
MasterService
`test/framework` directory:
FakeThreadPoolMasterService
BlockMasterServiceOnMaster
BusyMasterServiceDisruption

Signed-off-by: Tianli Feng <[email protected]>
  • Loading branch information
Tianli Feng authored Jul 14, 2022
1 parent e724b2e commit 0e96a87
Show file tree
Hide file tree
Showing 35 changed files with 628 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.test.OpenSearchIntegTestCase;
import org.opensearch.test.disruption.BlockClusterManagerServiceOnClusterManager;
import org.opensearch.test.disruption.BlockMasterServiceOnMaster;
import org.opensearch.test.disruption.IntermittentLongGCDisruption;
import org.opensearch.test.disruption.NetworkDisruption;
import org.opensearch.test.disruption.NetworkDisruption.TwoPartitions;
Expand Down Expand Up @@ -308,7 +308,7 @@ public void testMappingTimeout() throws Exception {
.setTransientSettings(Settings.builder().put("indices.mapping.dynamic_timeout", "1ms"))
);

ServiceDisruptionScheme disruption = new BlockClusterManagerServiceOnClusterManager(random());
ServiceDisruptionScheme disruption = new BlockMasterServiceOnMaster(random());
setDisruptionScheme(disruption);

disruption.startDisrupting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
import org.opensearch.test.OpenSearchIntegTestCase.Scope;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.TestCustomMetadata;
import org.opensearch.test.disruption.BusyClusterManagerServiceDisruption;
import org.opensearch.test.disruption.BusyMasterServiceDisruption;
import org.opensearch.test.disruption.ServiceDisruptionScheme;
import org.opensearch.test.rest.FakeRestRequest;
import org.opensearch.test.transport.MockTransportService;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ public void testDataNodeRestartWithBusyClusterManagerDuringSnapshot() throws Exc

final String dataNode = blockNodeWithIndex("test-repo", "test-idx");
logger.info("--> snapshot");
ServiceDisruptionScheme disruption = new BusyClusterManagerServiceDisruption(random(), Priority.HIGH);
ServiceDisruptionScheme disruption = new BusyMasterServiceDisruption(random(), Priority.HIGH);
setDisruptionScheme(disruption);
client(internalCluster().getMasterName()).admin()
.cluster()
Expand Down
13 changes: 8 additions & 5 deletions server/src/main/java/org/opensearch/OpenSearchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch;

import org.opensearch.action.support.replication.ReplicationOperation;
import org.opensearch.cluster.NotClusterManagerException;
import org.opensearch.cluster.action.shard.ShardStateAction;
import org.opensearch.common.CheckedFunction;
import org.opensearch.common.Nullable;
Expand All @@ -47,7 +46,6 @@
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentParseException;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.discovery.ClusterManagerNotDiscoveredException;
import org.opensearch.index.Index;
import org.opensearch.index.shard.ShardId;
import org.opensearch.rest.RestStatus;
Expand Down Expand Up @@ -791,8 +789,8 @@ private enum OpenSearchExceptionHandle {
UNKNOWN_VERSION_ADDED
),
CLUSTER_MANAGER_NOT_DISCOVERED_EXCEPTION(
ClusterManagerNotDiscoveredException.class,
ClusterManagerNotDiscoveredException::new,
org.opensearch.discovery.ClusterManagerNotDiscoveredException.class,
org.opensearch.discovery.ClusterManagerNotDiscoveredException::new,
3,
UNKNOWN_VERSION_ADDED
),
Expand Down Expand Up @@ -1501,7 +1499,12 @@ private enum OpenSearchExceptionHandle {
143,
UNKNOWN_VERSION_ADDED
),
NOT_CLUSTER_MANAGER_EXCEPTION(NotClusterManagerException.class, NotClusterManagerException::new, 144, UNKNOWN_VERSION_ADDED),
NOT_CLUSTER_MANAGER_EXCEPTION(
org.opensearch.cluster.NotClusterManagerException.class,
org.opensearch.cluster.NotClusterManagerException::new,
144,
UNKNOWN_VERSION_ADDED
),
STATUS_EXCEPTION(
org.opensearch.OpenSearchStatusException.class,
org.opensearch.OpenSearchStatusException::new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ public void onNoLongerMaster(String source) {
"stopped being cluster-manager while waiting for events with priority [{}]. retrying.",
request.waitForEvents()
);
// TransportClusterManagerNodeAction implements the retry logic, which is triggered by passing a
// NotClusterManagerException
// TransportClusterManagerNodeAction implements the retry logic,
// which is triggered by passing a NotClusterManagerException
listener.onFailure(new NotClusterManagerException("no longer cluster-manager. source: [" + source + "]"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

package org.opensearch.cluster;

import org.opensearch.cluster.service.ClusterManagerService;
import org.opensearch.cluster.service.MasterService;

import java.util.List;

Expand All @@ -49,7 +49,7 @@ public interface ClusterStateTaskListener {

/**
* called when the task was rejected because the local node is no longer cluster-manager.
* Used only for tasks submitted to {@link ClusterManagerService}.
* Used only for tasks submitted to {@link MasterService}.
*/
default void onNoLongerMaster(String source) {
onFailure(source, new NotClusterManagerException("no longer cluster-manager. source: [" + source + "]"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.cluster;

/**
* Enables listening to cluster-manager changes events of the local node (when the local node becomes the cluster-manager, and when the local
* node cease being a cluster-manager).
*
* @opensearch.internal
* @deprecated As of 2.2, because supporting inclusive language, replaced by {@link LocalNodeClusterManagerListener}
*/
@Deprecated
public interface LocalNodeMasterListener extends LocalNodeClusterManagerListener {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.cluster;

import java.util.function.Predicate;

/**
* Utility class to build a predicate that accepts cluster state changes
*
* @opensearch.internal
* @deprecated As of 2.2, because supporting inclusive language, replaced by {@link ClusterManagerNodeChangePredicate}
*/
@Deprecated
public final class MasterNodeChangePredicate {

private MasterNodeChangePredicate() {

}

public static Predicate<ClusterState> build(ClusterState currentState) {
return ClusterManagerNodeChangePredicate.build(currentState);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

package org.opensearch.cluster;

import org.opensearch.common.io.stream.StreamInput;

import java.io.IOException;

/**
* Thrown when a node join request or a cluster-manager ping reaches a node which is not
* currently acting as a cluster-manager or when a cluster state update task is to be executed
* on a node that is no longer cluster-manager.
*
* @opensearch.internal
* @deprecated As of 2.2, because supporting inclusive language, replaced by {@link NotClusterManagerException}
*/
@Deprecated
public class NotMasterException extends NotClusterManagerException {

public NotMasterException(String msg) {
super(msg);
}

public NotMasterException(StreamInput in) throws IOException {
super(in);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import org.opensearch.cluster.routing.allocation.AllocationService;
import org.opensearch.cluster.service.ClusterApplier;
import org.opensearch.cluster.service.ClusterApplier.ClusterApplyListener;
import org.opensearch.cluster.service.ClusterManagerService;
import org.opensearch.cluster.service.MasterService;
import org.opensearch.common.Booleans;
import org.opensearch.common.Nullable;
import org.opensearch.common.Priority;
Expand Down Expand Up @@ -141,7 +141,7 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery
private final boolean singleNodeDiscovery;
private final ElectionStrategy electionStrategy;
private final TransportService transportService;
private final ClusterManagerService clusterManagerService;
private final MasterService masterService;
private final AllocationService allocationService;
private final JoinHelper joinHelper;
private final NodeRemovalClusterStateTaskExecutor nodeRemovalExecutor;
Expand Down Expand Up @@ -191,7 +191,7 @@ public Coordinator(
TransportService transportService,
NamedWriteableRegistry namedWriteableRegistry,
AllocationService allocationService,
ClusterManagerService clusterManagerService,
MasterService masterService,
Supplier<CoordinationState.PersistedState> persistedStateSupplier,
SeedHostsProvider seedHostsProvider,
ClusterApplier clusterApplier,
Expand All @@ -203,15 +203,15 @@ public Coordinator(
) {
this.settings = settings;
this.transportService = transportService;
this.clusterManagerService = clusterManagerService;
this.masterService = masterService;
this.allocationService = allocationService;
this.onJoinValidators = JoinTaskExecutor.addBuiltInJoinValidators(onJoinValidators);
this.singleNodeDiscovery = DiscoveryModule.isSingleNodeDiscovery(settings);
this.electionStrategy = electionStrategy;
this.joinHelper = new JoinHelper(
settings,
allocationService,
clusterManagerService,
masterService,
transportService,
this::getCurrentTerm,
this::getStateForClusterManagerService,
Expand Down Expand Up @@ -260,7 +260,7 @@ public Coordinator(
);
this.nodeRemovalExecutor = new NodeRemovalClusterStateTaskExecutor(allocationService, logger);
this.clusterApplier = clusterApplier;
clusterManagerService.setClusterStateSupplier(this::getStateForClusterManagerService);
masterService.setClusterStateSupplier(this::getStateForClusterManagerService);
this.reconfigurator = new Reconfigurator(settings, clusterSettings);
this.clusterBootstrapService = new ClusterBootstrapService(
settings,
Expand Down Expand Up @@ -310,7 +310,7 @@ private void onLeaderFailure(Exception e) {
private void removeNode(DiscoveryNode discoveryNode, String reason) {
synchronized (mutex) {
if (mode == Mode.LEADER) {
clusterManagerService.submitStateUpdateTask(
masterService.submitStateUpdateTask(
"node-left",
new NodeRemovalClusterStateTaskExecutor.Task(discoveryNode, reason),
ClusterStateTaskConfig.build(Priority.IMMEDIATE),
Expand Down Expand Up @@ -756,7 +756,7 @@ void becomeFollower(String method, DiscoveryNode leaderNode) {
}

private void cleanClusterManagerService() {
clusterManagerService.submitStateUpdateTask("clean-up after stepping down as cluster-manager", new LocalClusterUpdateTask() {
masterService.submitStateUpdateTask("clean-up after stepping down as cluster-manager", new LocalClusterUpdateTask() {
@Override
public void onFailure(String source, Exception e) {
// ignore
Expand Down Expand Up @@ -1126,7 +1126,7 @@ private void scheduleReconfigurationIfNeeded() {
final ClusterState state = getLastAcceptedState();
if (improveConfiguration(state) != state && reconfigurationTaskScheduled.compareAndSet(false, true)) {
logger.trace("scheduling reconfiguration");
clusterManagerService.submitStateUpdateTask("reconfigure", new ClusterStateUpdateTask(Priority.URGENT) {
masterService.submitStateUpdateTask("reconfigure", new ClusterStateUpdateTask(Priority.URGENT) {
@Override
public ClusterState execute(ClusterState currentState) {
reconfigurationTaskScheduled.set(false);
Expand Down
Loading

0 comments on commit 0e96a87

Please sign in to comment.