-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Function as though max_local_storage_nodes defaults to 1 in prod mode #19748
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -81,9 +81,6 @@ | |
| * A component that holds all data paths for a single node. | ||
| */ | ||
| public final class NodeEnvironment implements Closeable { | ||
|
|
||
| private final ESLogger logger; | ||
|
|
||
| public static class NodePath { | ||
| /* ${data.paths}/nodes/{node.id} */ | ||
| public final Path path; | ||
|
|
@@ -138,21 +135,20 @@ public String toString() { | |
| } | ||
| } | ||
|
|
||
| private final NodePath[] nodePaths; | ||
| private final Path sharedDataPath; | ||
| private final Lock[] locks; | ||
|
|
||
| private final int nodeLockId; | ||
| private final AtomicBoolean closed = new AtomicBoolean(false); | ||
| private final Map<ShardId, InternalShardLock> shardLocks = new HashMap<>(); | ||
|
|
||
| private final NodeMetaData nodeMetaData; | ||
|
|
||
| /** | ||
| * Maximum number of data nodes that should run in an environment. | ||
| * Maximum number of data nodes that can run in an environment. {@code 0} is a special value for this setting meaning "use the default | ||
| * based on the number of allowed local storage nodes". | ||
| */ | ||
| public static final Setting<Integer> MAX_LOCAL_STORAGE_NODES_SETTING = Setting.intSetting("node.max_local_storage_nodes", 0, 0, | ||
| Property.NodeScope); | ||
| /** | ||
| * Default for {@link MAX_LOCAL_STORAGE_NODES_SETTING} to use when not in production mode. | ||
| */ | ||
| public static final Setting<Integer> MAX_LOCAL_STORAGE_NODES_SETTING = Setting.intSetting("node.max_local_storage_nodes", 50, 1, | ||
| Property.NodeScope); | ||
| public static final int MAX_LOCAL_STORAGE_NODES_NON_PRODUCTION_DEFAULT = 50; | ||
| /** | ||
| * Default for {@link MAX_LOCAL_STORAGE_NODES_SETTING} to use when in production mode. | ||
| */ | ||
| public static final int MAX_LOCAL_STORAGE_NODES_PRODUCTION_DEFAULT = 1; | ||
|
|
||
| /** | ||
| * If true automatically append node lock id to custom data paths. | ||
|
|
@@ -179,6 +175,21 @@ public String toString() { | |
| public static final String INDICES_FOLDER = "indices"; | ||
| public static final String NODE_LOCK_FILENAME = "node.lock"; | ||
|
|
||
| private final ESLogger logger; | ||
| private final NodePath[] nodePaths; | ||
| private final Path sharedDataPath; | ||
| private final Lock[] locks; | ||
|
|
||
| /** | ||
| * The lock number we were able to take. This is <strong>usually</strong> the number of Elasticsearch nodes sharing data directories | ||
| * with this node. | ||
| */ | ||
| private final int nodeLockId; | ||
| private final AtomicBoolean closed = new AtomicBoolean(false); | ||
| private final Map<ShardId, InternalShardLock> shardLocks = new HashMap<>(); | ||
|
|
||
| private final NodeMetaData nodeMetaData; | ||
|
|
||
| public NodeEnvironment(Settings settings, Environment environment) throws IOException { | ||
|
|
||
| if (!DiscoveryNode.nodeRequiresLocalStorage(settings)) { | ||
|
|
@@ -201,7 +212,11 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce | |
| sharedDataPath = environment.sharedDataFile(); | ||
| int nodeLockId = -1; | ||
| IOException lastException = null; | ||
| int maxLocalStorageNodes = MAX_LOCAL_STORAGE_NODES_SETTING.get(settings); | ||
| /* | ||
| * Try and acquire a lock as though we were in non-production mode regardless of what we will bind. If we find out later we are | ||
| * in production mode we'll fail to startup fully and if we aren't in production mode we'll log a nice little warning. | ||
| */ | ||
| int maxLocalStorageNodes = getMaxLocalStorageNodes(settings, false); | ||
| for (int possibleLockId = 0; possibleLockId < maxLocalStorageNodes; possibleLockId++) { | ||
| for (int dirIndex = 0; dirIndex < environment.dataFiles().length; dirIndex++) { | ||
| Path dataDirWithClusterName = environment.dataWithClusterFiles()[dirIndex]; | ||
|
|
@@ -419,6 +434,28 @@ private static String toString(Collection<String> items) { | |
| return b.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * The lock number we were able to take. This is <strong>usually</strong> the number of Elasticsearch nodes sharing data directories | ||
| * with this node. | ||
| */ | ||
| public int getNodeLockId() { | ||
| return nodeLockId; | ||
| } | ||
|
|
||
| /** | ||
| * Get the maximum number of local storage nodes allowed. | ||
| * @param settings the settings object from which to read the settings | ||
| * @param productionMode whether or not we are running in production mode | ||
| */ | ||
| public static int getMaxLocalStorageNodes(Settings settings, boolean productionMode) { | ||
| int maxLocalStorageNodes = MAX_LOCAL_STORAGE_NODES_SETTING.get(settings); | ||
|
Member
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. It's very confusing to shadow the class variable
Member
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. I also opened #19752 for future work on this
Member
Author
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. I don't think there is a class variable named that though?
Member
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.
Member
Author
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. The confusing part is that I had it as a class variable at some point when I was working on it! |
||
| if (maxLocalStorageNodes == 0) { | ||
| maxLocalStorageNodes = productionMode ? MAX_LOCAL_STORAGE_NODES_PRODUCTION_DEFAULT | ||
| : MAX_LOCAL_STORAGE_NODES_NON_PRODUCTION_DEFAULT; | ||
| } | ||
| return maxLocalStorageNodes; | ||
| } | ||
|
|
||
| /** | ||
| * Deletes a shard data directory iff the shards locks were successfully acquired. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ scope (e.g. `_local_,_site_` for all loopback and private network addresses) | |
| or by explicit interface names, hostnames, or addresses. | ||
|
|
||
| The `netty.epollBugWorkaround` settings is removed. This settings allow people to enable | ||
| a netty work around for https://github.com/netty/netty/issues/327[a high CPU usage issue] with early JVM versions. | ||
| a netty work around for https://github.com/netty/netty/issues/327[a high CPU usage issue] with early JVM versions. | ||
|
Member
Author
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. Atom ate this trailing space. I regret nothing!
Member
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. +1 |
||
| This bug was http://bugs.java.com/view_bug.do?bug_id=6403933[fixed in Java 7]. Since Elasticsearch 5.0 requires Java 8 the settings is removed. Note that if the workaround needs to be reintroduced you can still set the `org.jboss.netty.epollBugWorkaround` system property to control Netty directly. | ||
|
|
||
| ==== Forbid changing of thread pool types | ||
|
|
@@ -259,6 +259,15 @@ a fallback realtime setting for the get and mget APIs when realtime | |
| wasn't specified. Now if the parameter isn't specified we always | ||
| default to true. | ||
|
|
||
| ==== `node.max_local_storage_nodes` defaults to 1 in production mode | ||
|
|
||
| If you don't explicitly set `node.max_local_storage_nodes` and you start | ||
| multiple Elasticsearch processes in the same source directories then | ||
| Elasticsearch will log warning if it hasn't bound to any non-local addresses. | ||
| If it *has* bound to any non-local addresses then it'll refuse to start, | ||
| with the message | ||
| `there are already [1] Elasticsearch processes running with this data directory`. | ||
|
|
||
| === Script settings | ||
|
|
||
| ==== Indexed script settings | ||
|
|
||

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 moved these down below the constants. I thought I was going to add more members so I wanted to fix the order. I didn't end up adding more members but I still like having the members in a sensible order.