-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use file-based discovery not MockUncasedHostsProvider #33554
Changes from 3 commits
57a24ad
721a179
ca8407a
924768f
4adf965
82a5329
edf1feb
13b6046
2947a7a
31c1d7d
24a91aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -705,6 +705,8 @@ public Node start() throws NodeValidationException { | |
assert localNodeFactory.getNode() != null; | ||
assert transportService.getLocalNode().equals(localNodeFactory.getNode()) | ||
: "transportService has a different local node than the factory provided"; | ||
onTransportServiceStarted(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
final MetaData onDiskMetadata; | ||
try { | ||
// we load the global state here (the persistent part of the cluster state stored on disk) to | ||
|
@@ -781,6 +783,10 @@ public void onTimeout(TimeValue timeout) { | |
return this; | ||
} | ||
|
||
// For notifying tests that discovery can be configured | ||
protected void onTransportServiceStarted() { | ||
} | ||
|
||
private Node stop() { | ||
if (!lifecycle.moveToStopped()) { | ||
return this; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.elasticsearch.discovery.zen; | ||
|
||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; | ||
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.settings.Settings.Builder; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.junit.Before; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; | ||
import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; | ||
import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.LIMIT_LOCAL_PORTS_COUNT; | ||
import static org.elasticsearch.transport.TcpTransport.PORT; | ||
|
||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, numClientNodes = 0) | ||
public class SettingsBasedHostProviderIT extends ESIntegTestCase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we were effectively testing the settings-based host provider via all the other integ tests, but not after this change, I thought it prudent to add this. |
||
|
||
private Consumer<Builder> configureDiscovery; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this feels a little hacky to me. Can't you explicitly pass the extra settings to the nodes when you're starting them up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This came about due to a need to remove a setting from the builder, but that's no longer necessary. |
||
|
||
@Before | ||
public void setDefaultDiscoveryConfiguration() { | ||
configureDiscovery = b -> { | ||
}; | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal)); | ||
|
||
// super.nodeSettings enables file-based discovery, but here we disable it again so we can test the static list: | ||
if (randomBoolean()) { | ||
builder.putList(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()); | ||
} else { | ||
builder.remove(DISCOVERY_HOSTS_PROVIDER_SETTING.getKey()); | ||
} | ||
|
||
builder.remove(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey()); | ||
|
||
configureDiscovery.accept(builder); | ||
return builder.build(); | ||
} | ||
|
||
public void testClusterFormsWithSingleSeedHostInSettings() { | ||
final String seedNodeName = internalCluster().startNode(); | ||
final NodesInfoResponse nodesInfoResponse | ||
= client(seedNodeName).admin().cluster().nodesInfo(new NodesInfoRequest("_local")).actionGet(); | ||
final String seedNodeAddress = nodesInfoResponse.getNodes().get(0).getTransport().getAddress().publishAddress().toString(); | ||
configureDiscovery = b -> b.putList(DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING.getKey(), seedNodeAddress); | ||
logger.info("--> using seed node address {}", seedNodeAddress); | ||
|
||
int extraNodes = randomIntBetween(1, 5); | ||
internalCluster().startNodes(extraNodes); | ||
|
||
ensureStableCluster(extraNodes + 1); | ||
} | ||
|
||
public void testClusterFormsByScanningPorts() { | ||
final String seedNodeName = internalCluster().startNode(); | ||
final NodesInfoResponse nodesInfoResponse | ||
= client(seedNodeName).admin().cluster().nodesInfo(new NodesInfoRequest("_local")).actionGet(); | ||
final int seedNodePort = nodesInfoResponse.getNodes().get(0).getTransport().getAddress().publishAddress().getPort(); | ||
final int minPort = randomIntBetween(seedNodePort - LIMIT_LOCAL_PORTS_COUNT + 1, seedNodePort - 1); | ||
final String portSpec = minPort + "-" + seedNodePort; | ||
|
||
logger.info("--> using port specification [{}]", portSpec); | ||
|
||
configureDiscovery = b -> b.put(PORT.getKey(), portSpec); | ||
|
||
internalCluster().startNode(); | ||
ensureStableCluster(2); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can avoid adding these changes here in Node (and MockNode), but instead after initializing the node (but before starting it), call
node.injector().getInstance(TransportService.class)
to get theTransportService
and then register a lifecycle listener on that (addLifecycleListener
) which implementsafterStart
.