Remove pluggability of ElectMasterService (#21031)

This change makes the ElectMasterService local to ZenDiscovery, no
longer created by guice, and thus also removes the ability for plugins
to customize. This extension point is no longer used by anything.
This commit is contained in:
Ryan Ernst 2016-10-19 15:04:58 -07:00 committed by GitHub
parent f825988589
commit e7655bbf80
9 changed files with 11 additions and 60 deletions

View File

@ -328,7 +328,6 @@ public final class ClusterSettings extends AbstractScopedSettings {
NodeEnvironment.NODE_ID_SEED_SETTING,
DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING,
DiscoveryModule.DISCOVERY_TYPE_SETTING,
DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING,
FaultDetection.PING_RETRIES_SETTING,
FaultDetection.PING_TIMEOUT_SETTING,
FaultDetection.REGISTER_CONNECTION_LISTENER_SETTING,

View File

@ -47,20 +47,16 @@ public class DiscoveryModule extends AbstractModule {
public static final Setting<String> DISCOVERY_TYPE_SETTING =
new Setting<>("discovery.type", "zen", Function.identity(),
Property.NodeScope);
public static final Setting<String> ZEN_MASTER_SERVICE_TYPE_SETTING =
new Setting<>("discovery.zen.masterservice.type", "zen", Function.identity(), Property.NodeScope);
private final Settings settings;
private final Map<String, List<Class<? extends UnicastHostsProvider>>> unicastHostProviders = new HashMap<>();
private final ExtensionPoint.ClassSet<ZenPing> zenPings = new ExtensionPoint.ClassSet<>("zen_ping", ZenPing.class);
private final Map<String, Class<? extends Discovery>> discoveryTypes = new HashMap<>();
private final Map<String, Class<? extends ElectMasterService>> masterServiceType = new HashMap<>();
public DiscoveryModule(Settings settings) {
this.settings = settings;
addDiscoveryType("none", NoneDiscovery.class);
addDiscoveryType("zen", ZenDiscovery.class);
addElectMasterService("zen", ElectMasterService.class);
}
/**
@ -88,16 +84,6 @@ public class DiscoveryModule extends AbstractModule {
discoveryTypes.put(type, clazz);
}
/**
* Adds a custom zen master service type.
*/
public void addElectMasterService(String type, Class<? extends ElectMasterService> masterService) {
if (masterServiceType.containsKey(type)) {
throw new IllegalArgumentException("master service type [" + type + "] is already registered");
}
this.masterServiceType.put(type, masterService);
}
public void addZenPing(Class<? extends ZenPing> clazz) {
zenPings.registerExtension(clazz);
}
@ -111,16 +97,6 @@ public class DiscoveryModule extends AbstractModule {
}
if (discoveryType.equals("none") == false) {
String masterServiceTypeKey = ZEN_MASTER_SERVICE_TYPE_SETTING.get(settings);
final Class<? extends ElectMasterService> masterService = masterServiceType.get(masterServiceTypeKey);
if (masterService == null) {
throw new IllegalArgumentException("Unknown master service type [" + masterServiceTypeKey + "]");
}
if (masterService == ElectMasterService.class) {
bind(ElectMasterService.class).asEagerSingleton();
} else {
bind(ElectMasterService.class).to(masterService).asEagerSingleton();
}
bind(ZenPingService.class).asEagerSingleton();
Multibinder<UnicastHostsProvider> unicastHostsProviderMultibinder = Multibinder.newSetBinder(binder(), UnicastHostsProvider.class);
for (Class<? extends UnicastHostsProvider> unicastHostProvider :

View File

@ -98,7 +98,6 @@ public class ElectMasterService extends AbstractComponent {
}
}
@Inject
public ElectMasterService(Settings settings) {
super(settings);
this.minimumMasterNodes = DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.get(settings);
@ -175,7 +174,7 @@ public class ElectMasterService extends AbstractComponent {
* Returns the given nodes sorted by likelihood of being elected as master, most likely first.
* Non-master nodes are not removed but are rather put in the end
*/
public List<DiscoveryNode> sortByMasterLikelihood(Iterable<DiscoveryNode> nodes) {
public static List<DiscoveryNode> sortByMasterLikelihood(Iterable<DiscoveryNode> nodes) {
ArrayList<DiscoveryNode> sortedNodes = CollectionUtils.iterableAsArrayList(nodes);
CollectionUtil.introSort(sortedNodes, ElectMasterService::compareNodes);
return sortedNodes;

View File

@ -147,14 +147,14 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
@Inject
public ZenDiscovery(Settings settings, ThreadPool threadPool,
TransportService transportService, final ClusterService clusterService, ClusterSettings clusterSettings,
ZenPingService pingService, ElectMasterService electMasterService) {
ZenPingService pingService) {
super(settings);
this.clusterService = clusterService;
this.clusterName = clusterService.getClusterName();
this.transportService = transportService;
this.discoverySettings = new DiscoverySettings(settings, clusterSettings);
this.pingService = pingService;
this.electMaster = electMasterService;
this.electMaster = new ElectMasterService(settings);
this.pingTimeout = PING_TIMEOUT_SETTING.get(settings);
this.joinTimeout = JOIN_TIMEOUT_SETTING.get(settings);

View File

@ -103,7 +103,6 @@ public class UnicastZenPing extends AbstractLifecycleComponent implements ZenPin
private final ThreadPool threadPool;
private final TransportService transportService;
private final ClusterName clusterName;
private final ElectMasterService electMasterService;
private final int concurrentConnects;
@ -132,12 +131,11 @@ public class UnicastZenPing extends AbstractLifecycleComponent implements ZenPin
@Inject
public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService transportService,
ElectMasterService electMasterService, @Nullable Set<UnicastHostsProvider> unicastHostsProviders) {
@Nullable Set<UnicastHostsProvider> unicastHostsProviders) {
super(settings);
this.threadPool = threadPool;
this.transportService = transportService;
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
this.electMasterService = electMasterService;
if (unicastHostsProviders != null) {
for (UnicastHostsProvider unicastHostsProvider : unicastHostsProviders) {
@ -361,7 +359,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implements ZenPin
}
// sort the nodes by likelihood of being an active master
List<DiscoveryNode> sortedNodesToPing = electMasterService.sortByMasterLikelihood(nodesToPingSet);
List<DiscoveryNode> sortedNodesToPing = ElectMasterService.sortByMasterLikelihood(nodesToPingSet);
// new add the unicast targets first
List<DiscoveryNode> nodesToPing = CollectionUtils.arrayAsArrayList(configuredTargetNodes);

View File

@ -33,21 +33,6 @@ public class DiscoveryModuleTests extends ModuleTestCase {
}
}
public void testRegisterMasterElectionService() {
Settings settings = Settings.builder().put(DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING.getKey(), "custom").build();
DiscoveryModule module = new DiscoveryModule(settings);
module.addElectMasterService("custom", DummyMasterElectionService.class);
assertBinding(module, ElectMasterService.class, DummyMasterElectionService.class);
assertBinding(module, Discovery.class, ZenDiscovery.class);
}
public void testLoadUnregisteredMasterElectionService() {
Settings settings = Settings.builder().put(DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING.getKey(), "foobar").build();
DiscoveryModule module = new DiscoveryModule(settings);
module.addElectMasterService("custom", DummyMasterElectionService.class);
assertBindingFailure(module, "Unknown master service type [foobar]");
}
public void testRegisterDefaults() {
Settings settings = Settings.EMPTY;
DiscoveryModule module = new DiscoveryModule(settings);
@ -60,6 +45,4 @@ public class DiscoveryModuleTests extends ModuleTestCase {
module.addDiscoveryType("custom", NoopDiscovery.class);
assertBinding(module, Discovery.class, NoopDiscovery.class);
}
}

View File

@ -76,7 +76,7 @@ public class ElectMasterServiceTests extends ESTestCase {
public void testSortByMasterLikelihood() {
List<DiscoveryNode> nodes = generateRandomNodes();
List<DiscoveryNode> sortedNodes = electMasterService().sortByMasterLikelihood(nodes);
List<DiscoveryNode> sortedNodes = ElectMasterService.sortByMasterLikelihood(nodes);
assertEquals(nodes.size(), sortedNodes.size());
DiscoveryNode prevNode = sortedNodes.get(0);
for (int i = 1; i < sortedNodes.size(); i++) {

View File

@ -218,9 +218,7 @@ public class ZenDiscoveryUnitTests extends ESTestCase {
private ZenDiscovery buildZenDiscovery(Settings settings, TransportService service, ClusterService clusterService, ThreadPool threadPool) {
ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
ZenPingService zenPingService = new ZenPingService(settings, Collections.emptySet());
ElectMasterService electMasterService = new ElectMasterService(settings);
ZenDiscovery zenDiscovery = new ZenDiscovery(settings, threadPool, service, clusterService,
clusterSettings, zenPingService, electMasterService);
ZenDiscovery zenDiscovery = new ZenDiscovery(settings, threadPool, service, clusterService, clusterSettings, zenPingService);
zenDiscovery.start();
return zenDiscovery;
}

View File

@ -72,7 +72,6 @@ public class UnicastZenPingTests extends ESTestCase {
ThreadPool threadPool = new TestThreadPool(getClass().getName());
NetworkService networkService = new NetworkService(settings, Collections.emptyList());
ElectMasterService electMasterService = new ElectMasterService(settings);
NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", Version.CURRENT);
NetworkHandle handleB = startServices(settings, threadPool, networkService, "UZP_B", Version.CURRENT);
@ -94,7 +93,7 @@ public class UnicastZenPingTests extends ESTestCase {
.build();
Settings hostsSettingsMismatch = Settings.builder().put(hostsSettings).put(settingsMismatch).build();
UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, handleA.transportService, electMasterService, null);
UnicastZenPing zenPingA = new UnicastZenPing(hostsSettings, threadPool, handleA.transportService, null);
zenPingA.setPingContextProvider(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {
@ -108,7 +107,7 @@ public class UnicastZenPingTests extends ESTestCase {
});
zenPingA.start();
UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, handleB.transportService, electMasterService, null);
UnicastZenPing zenPingB = new UnicastZenPing(hostsSettings, threadPool, handleB.transportService, null);
zenPingB.setPingContextProvider(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {
@ -122,8 +121,7 @@ public class UnicastZenPingTests extends ESTestCase {
});
zenPingB.start();
UnicastZenPing zenPingC = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleC.transportService, electMasterService,
null) {
UnicastZenPing zenPingC = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleC.transportService, null) {
@Override
protected Version getVersion() {
return versionD;
@ -142,7 +140,7 @@ public class UnicastZenPingTests extends ESTestCase {
});
zenPingC.start();
UnicastZenPing zenPingD = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleD.transportService, electMasterService, null);
UnicastZenPing zenPingD = new UnicastZenPing(hostsSettingsMismatch, threadPool, handleD.transportService, null);
zenPingD.setPingContextProvider(new PingContextProvider() {
@Override
public DiscoveryNodes nodes() {