-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[Zen2] Best-effort cluster formation if unconfigured #36215
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
Merged
DaveCTurner
merged 20 commits into
elastic:master
from
DaveCTurner:2018-12-04-best-effort-cluster-in-development-mode
Dec 7, 2018
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9093c75
[Zen2] Best-effort cluster formation if unconfigured
DaveCTurner 75c7fee
Nullable rather than -1
DaveCTurner e7198d7
Rename setting
DaveCTurner 774dd77
Log at INFO
DaveCTurner 7d27065
Moar rename
DaveCTurner 45528da
rename runnable
DaveCTurner 02f5b28
Rename test
DaveCTurner 5b83d89
Merge branch 'zen2' into 2018-12-04-best-effort-cluster-in-developmen…
DaveCTurner b3439e8
Merge branch 'zen2' into 2018-12-04-best-effort-cluster-in-developmen…
DaveCTurner ccc124d
better message
DaveCTurner 5cd1d06
Add bootstrap check that discovery is configured
DaveCTurner 1ea77f4
Add docs for bootstrap check
DaveCTurner b29e40a
Merge branch 'master' into 2018-12-04-best-effort-cluster-in-developm…
DaveCTurner feb9e4c
Merge branch 'master' into 2018-12-04-best-effort-cluster-in-developm…
DaveCTurner 43fdbd0
Do not start bootstrap service if already bootstrapped
DaveCTurner b911f4f
Only apply check in Zen2, and list the settings
DaveCTurner 54fffaf
All the cool checks are using String.format
DaveCTurner 4a1e99f
Add breaking changes note
DaveCTurner 6c68027
Merge branch 'master' into 2018-12-04-best-effort-cluster-in-developm…
DaveCTurner 00ef7ea
Expand TODO
DaveCTurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import org.elasticsearch.action.admin.cluster.bootstrap.GetDiscoveredNodesRequest; | ||
import org.elasticsearch.action.admin.cluster.bootstrap.GetDiscoveredNodesResponse; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.common.settings.Setting.Property; | ||
|
@@ -44,6 +45,10 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Stream; | ||
|
||
import static org.elasticsearch.discovery.DiscoveryModule.DISCOVERY_HOSTS_PROVIDER_SETTING; | ||
import static org.elasticsearch.discovery.zen.SettingsBasedHostsProvider.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING; | ||
|
||
public class ClusterBootstrapService { | ||
|
||
|
@@ -57,22 +62,82 @@ public class ClusterBootstrapService { | |
public static final Setting<List<String>> INITIAL_MASTER_NODES_SETTING = | ||
Setting.listSetting("cluster.initial_master_nodes", Collections.emptyList(), Function.identity(), Property.NodeScope); | ||
|
||
public static final Setting<TimeValue> UNCONFIGURED_BOOTSTRAP_TIMEOUT_SETTING = | ||
Setting.timeSetting("discovery.unconfigured_bootstrap_timeout", | ||
TimeValue.timeValueSeconds(3), TimeValue.timeValueMillis(1), Property.NodeScope); | ||
|
||
private final int initialMasterNodeCount; | ||
private final List<String> initialMasterNodes; | ||
@Nullable | ||
private final TimeValue unconfiguredBootstrapTimeout; | ||
private final TransportService transportService; | ||
private volatile boolean running; | ||
|
||
public ClusterBootstrapService(Settings settings, TransportService transportService) { | ||
initialMasterNodeCount = INITIAL_MASTER_NODE_COUNT_SETTING.get(settings); | ||
initialMasterNodes = INITIAL_MASTER_NODES_SETTING.get(settings); | ||
unconfiguredBootstrapTimeout = discoveryIsConfigured(settings) ? null : UNCONFIGURED_BOOTSTRAP_TIMEOUT_SETTING.get(settings); | ||
this.transportService = transportService; | ||
} | ||
|
||
public static boolean discoveryIsConfigured(Settings settings) { | ||
return Stream.of(DISCOVERY_HOSTS_PROVIDER_SETTING, DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, | ||
INITIAL_MASTER_NODE_COUNT_SETTING, INITIAL_MASTER_NODES_SETTING).anyMatch(s -> s.exists(settings)); | ||
} | ||
|
||
public void start() { | ||
assert running == false; | ||
running = true; | ||
|
||
if ((initialMasterNodeCount > 0 || initialMasterNodes.isEmpty() == false) && transportService.getLocalNode().isMasterNode()) { | ||
if (transportService.getLocalNode().isMasterNode() == false) { | ||
return; | ||
} | ||
|
||
if (unconfiguredBootstrapTimeout != null) { | ||
logger.info("no discovery configuration found, will perform best-effort cluster bootstrapping after [{}] " + | ||
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. can we avoid this message if the cluster is already bootstrapped? 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. We can avoid the whole cluster bootstrap service in that case. I pushed 43fdbd0. |
||
"unless existing master is discovered", unconfiguredBootstrapTimeout); | ||
final ThreadContext threadContext = transportService.getThreadPool().getThreadContext(); | ||
try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { | ||
threadContext.markAsSystemContext(); | ||
|
||
transportService.getThreadPool().scheduleUnlessShuttingDown(unconfiguredBootstrapTimeout, Names.SAME, new Runnable() { | ||
@Override | ||
public void run() { | ||
final GetDiscoveredNodesRequest request = new GetDiscoveredNodesRequest(); | ||
logger.trace("sending {}", request); | ||
transportService.sendRequest(transportService.getLocalNode(), GetDiscoveredNodesAction.NAME, request, | ||
new TransportResponseHandler<GetDiscoveredNodesResponse>() { | ||
@Override | ||
public void handleResponse(GetDiscoveredNodesResponse response) { | ||
logger.debug("discovered {}, starting to bootstrap", response.getNodes()); | ||
awaitBootstrap(response.getBootstrapConfiguration()); | ||
} | ||
|
||
@Override | ||
public void handleException(TransportException exp) { | ||
logger.warn("discovery attempt failed", exp); | ||
} | ||
|
||
@Override | ||
public String executor() { | ||
return Names.SAME; | ||
} | ||
|
||
@Override | ||
public GetDiscoveredNodesResponse read(StreamInput in) throws IOException { | ||
return new GetDiscoveredNodesResponse(in); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "unconfigured-discovery delayed bootstrap"; | ||
} | ||
}); | ||
|
||
} | ||
} else if (initialMasterNodeCount > 0 || initialMasterNodes.isEmpty() == false) { | ||
logger.debug("unsafely waiting for discovery of [{}] master-eligible nodes", initialMasterNodeCount); | ||
|
||
final ThreadContext threadContext = transportService.getThreadPool().getThreadContext(); | ||
|
@@ -116,7 +181,6 @@ public GetDiscoveredNodesResponse read(StreamInput in) throws IOException { | |
} | ||
|
||
public void stop() { | ||
assert running == true; | ||
running = false; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.