2010-02-08 15:30:06 +02:00
/ *
2014-01-06 22:48:02 +01:00
* 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
2010-02-08 15:30:06 +02:00
*
* 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 .
* /
2010-04-09 00:54:54 +03:00
package org.elasticsearch.node ;
2010-02-08 15:30:06 +02:00
2016-08-09 13:34:23 -04:00
import org.apache.logging.log4j.Logger ;
2016-05-24 16:55:55 -04:00
import org.apache.lucene.util.Constants ;
2016-01-29 16:18:21 +01:00
import org.apache.lucene.util.IOUtils ;
2017-01-13 16:12:27 +01:00
import org.apache.lucene.util.SetOnce ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.Build ;
2015-11-26 09:50:41 +01:00
import org.elasticsearch.ElasticsearchException ;
2016-02-24 14:10:55 -08:00
import org.elasticsearch.ElasticsearchTimeoutException ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.Version ;
import org.elasticsearch.action.ActionModule ;
2016-06-29 14:55:31 -04:00
import org.elasticsearch.action.GenericAction ;
2017-07-17 11:04:51 -06:00
import org.elasticsearch.action.search.SearchExecutionStatsCollector ;
2016-11-23 22:18:50 +01:00
import org.elasticsearch.action.search.SearchPhaseController ;
import org.elasticsearch.action.search.SearchTransportService ;
2016-06-29 14:55:31 -04:00
import org.elasticsearch.action.support.TransportAction ;
2016-10-06 16:04:45 -04:00
import org.elasticsearch.action.update.UpdateHelper ;
2016-12-12 17:35:00 +01:00
import org.elasticsearch.bootstrap.BootstrapCheck ;
2017-09-13 22:14:17 +02:00
import org.elasticsearch.bootstrap.BootstrapContext ;
2010-02-08 15:30:06 +02:00
import org.elasticsearch.client.Client ;
2016-06-20 11:53:07 +02:00
import org.elasticsearch.client.node.NodeClient ;
2017-07-05 22:18:23 +02:00
import org.elasticsearch.cluster.ClusterInfo ;
2016-11-10 15:52:17 -08:00
import org.elasticsearch.cluster.ClusterInfoService ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.cluster.ClusterModule ;
2016-02-24 14:10:55 -08:00
import org.elasticsearch.cluster.ClusterState ;
import org.elasticsearch.cluster.ClusterStateObserver ;
2016-11-10 15:52:17 -08:00
import org.elasticsearch.cluster.InternalClusterInfoService ;
2016-02-27 18:48:42 +01:00
import org.elasticsearch.cluster.NodeConnectionsService ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.cluster.action.index.MappingUpdatedAction ;
2017-05-03 12:51:41 -04:00
import org.elasticsearch.cluster.metadata.IndexMetaData ;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData ;
2016-08-11 13:36:05 -04:00
import org.elasticsearch.cluster.metadata.MetaData ;
2016-10-06 16:04:45 -04:00
import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService ;
2017-06-22 14:55:28 -04:00
import org.elasticsearch.cluster.metadata.TemplateUpgradeService ;
2016-01-25 15:05:00 +01:00
import org.elasticsearch.cluster.node.DiscoveryNode ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.cluster.routing.RoutingService ;
2017-07-05 22:18:23 +02:00
import org.elasticsearch.cluster.routing.allocation.DiskThresholdMonitor ;
2016-03-17 22:42:20 +01:00
import org.elasticsearch.cluster.service.ClusterService ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.StopWatch ;
import org.elasticsearch.common.component.Lifecycle ;
import org.elasticsearch.common.component.LifecycleComponent ;
2016-09-19 22:10:47 +02:00
import org.elasticsearch.common.inject.Binder ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.inject.Injector ;
2016-06-29 14:55:31 -04:00
import org.elasticsearch.common.inject.Key ;
2015-08-21 01:28:41 -07:00
import org.elasticsearch.common.inject.Module ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.inject.ModulesBuilder ;
2016-09-19 22:10:47 +02:00
import org.elasticsearch.common.inject.util.Providers ;
2016-01-04 16:00:34 -05:00
import org.elasticsearch.common.io.stream.NamedWriteableRegistry ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.lease.Releasables ;
2016-04-15 14:43:04 -06:00
import org.elasticsearch.common.logging.DeprecationLogger ;
2018-01-15 09:59:01 -07:00
import org.elasticsearch.common.logging.ServerLoggers ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.logging.Loggers ;
2015-12-11 17:36:08 -08:00
import org.elasticsearch.common.network.NetworkAddress ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.network.NetworkModule ;
2015-11-26 09:50:41 +01:00
import org.elasticsearch.common.network.NetworkService ;
2015-12-09 09:57:39 +01:00
import org.elasticsearch.common.settings.ClusterSettings ;
2016-01-25 15:05:00 +01:00
import org.elasticsearch.common.settings.Setting ;
2016-03-04 16:53:22 +01:00
import org.elasticsearch.common.settings.Setting.Property ;
2010-06-15 16:51:38 +03:00
import org.elasticsearch.common.settings.Settings ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.common.settings.SettingsModule ;
2015-12-11 17:36:08 -08:00
import org.elasticsearch.common.transport.BoundTransportAddress ;
import org.elasticsearch.common.transport.TransportAddress ;
2016-02-24 14:10:55 -08:00
import org.elasticsearch.common.unit.TimeValue ;
2016-06-01 09:43:11 +02:00
import org.elasticsearch.common.util.BigArrays ;
2017-12-08 10:39:30 -07:00
import org.elasticsearch.common.util.PageCacheRecycler ;
2016-12-20 11:05:24 -05:00
import org.elasticsearch.common.xcontent.NamedXContentRegistry ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.discovery.Discovery ;
import org.elasticsearch.discovery.DiscoveryModule ;
2016-02-24 14:10:55 -08:00
import org.elasticsearch.discovery.DiscoverySettings ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.env.Environment ;
import org.elasticsearch.env.NodeEnvironment ;
Async fetch of shard started and store during allocation
Today, when a primary shard is not allocated we go to all the nodes to find where it is allocated (listing its started state). When we allocate a replica shard, we head to all the nodes and list its store to allocate the replica on a node that holds the closest matching index files to the primary.
Those two operations today execute synchronously within the GatewayAllocator, which means they execute in a sync manner within the cluster update thread. For large clusters, or environments with very slow disk, those operations will stall the cluster update thread, making it seem like its stuck.
Worse, if the FS is really slow, we timeout after 30s the operation (to not stall the cluster update thread completely). This means that we will have another run for the primary shard if we didn't find one, or we won't find the best node to place a shard since it might have timed out (listing stores need to list all files and read the checksum at the end of each file).
On top of that, this sync operation happen one shard at a time, so its effectively compounding the problem in a serial manner the more shards we have and the slower FS is...
This change moves to perform both listing the shard started states and the shard stores to an async manner. During the allocation by the GatewayAllocator, if data needs to be fetched from a node, it is done in an async fashion, with the response triggering a reroute to make sure the results will be taken into account. Also, if there are on going operations happening, the relevant shard data will not be taken into account until all the ongoing listing operations are done executing.
The execution of listing shard states and stores has been moved to their own respective thread pools (scaling, so will go down to 0 when not needed anymore, unbounded queue, since we don't want to timeout, just let it execute based on how fast the local FS is). This is needed sine we are going to blast nodes with a lot of requests and we need to make sure there is no thread explosion.
This change also improves the handling of shard failures coming from a specific node. Today, those nodes were ignored from allocation only for the single reroute round. Now, since fetching is async, we need to keep those failures around at least until a single successful fetch without the node is done, to make sure not to repeat allocating to the failed node all the time.
Note, if before the indication of slow allocation was high pending tasks since the allocator was waiting for responses, not the pending tasks will be much smaller. In order to still indicate that the cluster is in the middle of fetching shard data, 2 attributes were added to the cluster health API, indicating the number of ongoing fetches of both started shards and shard store.
closes #9502
closes #11101
2015-05-11 01:19:13 +02:00
import org.elasticsearch.gateway.GatewayAllocator ;
2017-09-13 22:14:17 +02:00
import org.elasticsearch.gateway.GatewayMetaState ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.gateway.GatewayModule ;
import org.elasticsearch.gateway.GatewayService ;
2016-08-19 00:27:37 -07:00
import org.elasticsearch.gateway.MetaStateService ;
2015-12-11 17:36:08 -08:00
import org.elasticsearch.http.HttpServerTransport ;
2016-06-24 16:37:23 -04:00
import org.elasticsearch.index.analysis.AnalysisRegistry ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.indices.IndicesModule ;
import org.elasticsearch.indices.IndicesService ;
2015-10-28 22:19:44 +01:00
import org.elasticsearch.indices.analysis.AnalysisModule ;
2016-06-16 15:52:58 +02:00
import org.elasticsearch.indices.breaker.CircuitBreakerService ;
import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService ;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.indices.cluster.IndicesClusterStateService ;
2016-10-06 16:04:45 -04:00
import org.elasticsearch.indices.recovery.PeerRecoverySourceService ;
import org.elasticsearch.indices.recovery.PeerRecoveryTargetService ;
import org.elasticsearch.indices.recovery.RecoverySettings ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.indices.store.IndicesStore ;
2016-06-30 01:49:22 -07:00
import org.elasticsearch.ingest.IngestService ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.monitor.MonitorService ;
import org.elasticsearch.monitor.jvm.JvmInfo ;
2016-06-27 17:33:01 -04:00
import org.elasticsearch.plugins.ActionPlugin ;
2016-06-24 16:37:23 -04:00
import org.elasticsearch.plugins.AnalysisPlugin ;
2016-08-17 15:48:12 -07:00
import org.elasticsearch.plugins.ClusterPlugin ;
2016-07-21 11:35:29 +02:00
import org.elasticsearch.plugins.DiscoveryPlugin ;
2016-06-30 01:49:22 -07:00
import org.elasticsearch.plugins.IngestPlugin ;
2016-06-27 17:33:01 -04:00
import org.elasticsearch.plugins.MapperPlugin ;
2016-09-27 20:13:12 -04:00
import org.elasticsearch.plugins.MetaDataUpgrader ;
2016-09-19 22:10:47 +02:00
import org.elasticsearch.plugins.NetworkPlugin ;
2015-08-22 00:21:13 -07:00
import org.elasticsearch.plugins.Plugin ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.plugins.PluginsService ;
2016-07-07 17:56:12 -07:00
import org.elasticsearch.plugins.RepositoryPlugin ;
2016-06-16 09:35:13 +02:00
import org.elasticsearch.plugins.ScriptPlugin ;
2016-07-03 14:41:47 -04:00
import org.elasticsearch.plugins.SearchPlugin ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.repositories.RepositoriesModule ;
2017-01-16 21:06:08 +01:00
import org.elasticsearch.rest.RestController ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.script.ScriptModule ;
import org.elasticsearch.script.ScriptService ;
import org.elasticsearch.search.SearchModule ;
import org.elasticsearch.search.SearchService ;
2016-09-12 22:42:55 +02:00
import org.elasticsearch.search.fetch.FetchPhase ;
2015-06-23 18:01:32 -04:00
import org.elasticsearch.snapshots.SnapshotShardsService ;
2015-07-22 12:11:10 +02:00
import org.elasticsearch.snapshots.SnapshotsService ;
2016-08-12 16:46:02 -04:00
import org.elasticsearch.tasks.TaskResultsService ;
2016-06-06 22:09:12 -04:00
import org.elasticsearch.threadpool.ExecutorBuilder ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.threadpool.ThreadPool ;
2016-09-19 22:10:47 +02:00
import org.elasticsearch.transport.Transport ;
import org.elasticsearch.transport.TransportInterceptor ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.transport.TransportService ;
2017-06-02 08:46:38 +01:00
import org.elasticsearch.usage.UsageService ;
2015-02-24 11:07:24 +01:00
import org.elasticsearch.watcher.ResourceWatcherService ;
2015-12-11 17:36:08 -08:00
import java.io.BufferedWriter ;
2016-01-29 16:18:21 +01:00
import java.io.Closeable ;
2015-02-24 11:07:24 +01:00
import java.io.IOException ;
2017-09-13 22:14:17 +02:00
import java.io.UncheckedIOException ;
2015-12-11 18:20:09 -08:00
import java.net.InetAddress ;
2015-12-11 17:36:08 -08:00
import java.net.InetSocketAddress ;
import java.nio.charset.Charset ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.StandardCopyOption ;
2016-01-29 16:18:21 +01:00
import java.util.ArrayList ;
2015-02-24 11:07:24 +01:00
import java.util.Arrays ;
2015-08-22 00:21:13 -07:00
import java.util.Collection ;
import java.util.Collections ;
2016-01-29 16:18:21 +01:00
import java.util.List ;
2016-06-29 14:55:31 -04:00
import java.util.Map ;
Add ability to associate an ID with tasks (#27764)
Adds support for capturing the X-Opaque-Id header from a REST request and storing it's value in the tasks that this request started. It works for all user-initiated tasks (not only search).
Closes #23250
Usage:
```
$ curl -H "X-Opaque-Id: imotov" -H "foo:bar" "localhost:9200/_tasks?pretty&group_by=parents"
{
"tasks" : {
"7qrTVbiDQKiZfubUP7DPkg:6998" : {
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6998,
"type" : "transport",
"action" : "cluster:monitor/tasks/lists",
"start_time_in_millis" : 1513029940042,
"running_time_in_nanos" : 266794,
"cancellable" : false,
"headers" : {
"X-Opaque-Id" : "imotov"
},
"children" : [
{
"node" : "V-PuCjPhRp2ryuEsNw6V1g",
"id" : 6088,
"type" : "netty",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 67785,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
},
{
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6999,
"type" : "direct",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 98754,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
}
]
}
}
}
```
2018-01-12 15:34:17 -05:00
import java.util.Set ;
2016-02-24 14:10:55 -08:00
import java.util.concurrent.CountDownLatch ;
2015-02-24 11:07:24 +01:00
import java.util.concurrent.TimeUnit ;
2016-09-19 22:10:47 +02:00
import java.util.function.Consumer ;
2016-08-02 15:56:25 -07:00
import java.util.function.Function ;
2016-08-11 13:36:05 -04:00
import java.util.function.UnaryOperator ;
2016-07-11 13:07:22 -07:00
import java.util.stream.Collectors ;
2016-08-02 15:56:25 -07:00
import java.util.stream.Stream ;
2015-02-24 11:07:24 +01:00
2016-12-20 11:05:24 -05:00
import static java.util.stream.Collectors.toList ;
2010-02-08 15:30:06 +02:00
/ * *
2010-04-09 00:54:54 +03:00
* A node represent a node within a cluster ( < tt > cluster . name < / tt > ) . The { @link # client ( ) } can be used
2010-02-13 20:03:37 +02:00
* in order to use a { @link Client } to perform actions / operations against the cluster .
2010-02-08 15:30:06 +02:00
* /
2016-01-29 16:18:21 +01:00
public class Node implements Closeable {
2015-02-24 11:07:24 +01:00
2016-06-16 15:52:58 +02:00
2017-04-27 00:59:54 -07:00
public static final Setting < Boolean > WRITE_PORTS_FILE_SETTING =
2016-03-04 16:53:22 +01:00
Setting . boolSetting ( " node.portsfile " , false , Property . NodeScope ) ;
public static final Setting < Boolean > NODE_DATA_SETTING = Setting . boolSetting ( " node.data " , true , Property . NodeScope ) ;
2016-02-28 00:40:00 +01:00
public static final Setting < Boolean > NODE_MASTER_SETTING =
2016-03-04 16:53:22 +01:00
Setting . boolSetting ( " node.master " , true , Property . NodeScope ) ;
2016-02-28 00:40:00 +01:00
public static final Setting < Boolean > NODE_INGEST_SETTING =
2016-03-04 16:53:22 +01:00
Setting . boolSetting ( " node.ingest " , true , Property . NodeScope ) ;
Persistent Node Ids (#19140)
Node IDs are currently randomly generated during node startup. That means they change every time the node is restarted. While this doesn't matter for ES proper, it makes it hard for external services to track nodes. Another, more minor, side effect is that indexing the output of, say, the node stats API results in creating new fields due to node ID being used as keys.
The first approach I considered was to use the node's published address as the base for the id. We already [treat nodes with the same address as the same](https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java#L387) so this is a simple change (see [here](https://github.com/elastic/elasticsearch/compare/master...bleskes:node_persistent_id_based_on_address)). While this is simple and it works for probably most cases, it is not perfect. For example, if after a node restart, the node is not able to bind to the same port (because it's not yet freed by the OS), it will cause the node to still change identity. Also in environments where the host IP can change due to a host restart, identity will not be the same.
Due to those limitation, I opted to go with a different approach where the node id will be persisted in the node's data folder. This has the upside of connecting the id to the nodes data. It also means that the host can be adapted in any way (replace network cards, attach storage to a new VM). I
It does however also have downsides - we now run the risk of two nodes having the same id, if someone copies clones a data folder from one node to another. To mitigate this I changed the semantics of the protection against multiple nodes with the same address to be stricter - it will now reject the incoming join if a node exists with the same id but a different address. Note that if the existing node doesn't respond to pings (i.e., it's not alive) it will be removed and the new node will be accepted when it tries another join.
Last, and most importantly, this change requires that *all* nodes persist data to disk. This is a change from current behavior where only data & master nodes store local files. This is the main reason for marking this PR as breaking.
Other less important notes:
- DummyTransportAddress is removed as we need a unique network address per node. Use `LocalTransportAddress.buildUnique()` instead.
- I renamed `node.add_lid_to_custom_path` to `node.add_lock_id_to_custom_path` to avoid confusion with the node ID which is now part of the `NodeEnvironment` logic.
- I removed the `version` paramater from `MetaDataStateFormat#write` , it wasn't really used and was just in the way :)
- TribeNodes are special in the sense that they do start multiple sub-nodes (previously known as client nodes). Those sub-nodes do not store local files but derive their ID from the parent node id, so they are generated consistently.
2016-07-04 21:09:25 +02:00
/ * *
* controls whether the node is allowed to persist things like metadata to disk
* Note that this does not control whether the node stores actual indices ( see
* { @link # NODE_DATA_SETTING } ) . However , if this is false , { @link # NODE_DATA_SETTING }
* and { @link # NODE_MASTER_SETTING } must also be false .
*
* /
public static final Setting < Boolean > NODE_LOCAL_STORAGE_SETTING = Setting . boolSetting ( " node.local_storage " , true , Property . NodeScope ) ;
2016-03-04 16:53:22 +01:00
public static final Setting < String > NODE_NAME_SETTING = Setting . simpleString ( " node.name " , Property . NodeScope ) ;
2017-09-30 14:27:21 +02:00
public static final Setting . AffixSetting < String > NODE_ATTRIBUTES = Setting . prefixKeySetting ( " node.attr. " , ( key ) - >
new Setting < > ( key , " " , ( value ) - > {
if ( value . length ( ) > 0
& & ( Character . isWhitespace ( value . charAt ( 0 ) ) | | Character . isWhitespace ( value . charAt ( value . length ( ) - 1 ) ) ) ) {
throw new IllegalArgumentException ( key + " cannot have leading or trailing whitespace " +
" [ " + value + " ] " ) ;
Allow comma delimited array settings to have a space after each entry (#22591)
Previously, certain settings that could take multiple comma delimited
values would pick up incorrect values for all entries but the first if
each comma separated value was followed by a whitespace character. For
example, the multi-value "A,B,C" would be correctly parsed as
["A", "B", "C"] but the multi-value "A, B, C" would be incorrectly parsed
as ["A", " B", " C"].
This commit allows a comma separated list to have whitespace characters
after each entry. The specific settings that were affected by this are:
cluster.routing.allocation.awareness.attributes
index.routing.allocation.require.*
index.routing.allocation.include.*
index.routing.allocation.exclude.*
cluster.routing.allocation.require.*
cluster.routing.allocation.include.*
cluster.routing.allocation.exclude.*
http.cors.allow-methods
http.cors.allow-headers
For the allocation filtering related settings, this commit also provides
validation of each specified entry if the filtering is done by _ip,
_host_ip, or _publish_ip, to ensure that each entry is a valid IP
address.
Closes #22297
2017-01-17 08:51:04 -06:00
}
2017-09-30 14:27:21 +02:00
return value ;
} , Property . NodeScope ) ) ;
2016-06-16 15:52:58 +02:00
public static final Setting < String > BREAKER_TYPE_KEY = new Setting < > ( " indices.breaker.type " , " hierarchy " , ( s ) - > {
switch ( s ) {
case " hierarchy " :
case " none " :
return s ;
default :
throw new IllegalArgumentException ( " indices.breaker.type must be one of [hierarchy, none] but was: " + s ) ;
}
} , Setting . Property . NodeScope ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
/ * *
* Adds a default node name to the given setting , if it doesn ' t already exist
* @return the given setting if node name is already set , or a new copy with a default node name set .
* /
public static final Settings addNodeNameIfNeeded ( Settings settings , final String nodeId ) {
if ( NODE_NAME_SETTING . exists ( settings ) ) {
return settings ;
}
return Settings . builder ( ) . put ( settings ) . put ( NODE_NAME_SETTING . getKey ( ) , nodeId . substring ( 0 , 7 ) ) . build ( ) ;
}
2016-01-26 10:30:14 +01:00
2015-02-24 11:07:24 +01:00
private static final String CLIENT_TYPE = " node " ;
private final Lifecycle lifecycle = new Lifecycle ( ) ;
private final Injector injector ;
private final Settings settings ;
private final Environment environment ;
2016-06-28 16:38:56 +02:00
private final NodeEnvironment nodeEnvironment ;
2015-02-24 11:07:24 +01:00
private final PluginsService pluginsService ;
2016-06-29 14:55:31 -04:00
private final NodeClient client ;
2016-07-11 13:07:22 -07:00
private final Collection < LifecycleComponent > pluginLifecycleComponents ;
2017-01-13 16:12:27 +01:00
private final LocalNodeFactory localNodeFactory ;
2017-07-05 22:18:23 +02:00
private final NodeService nodeService ;
2015-02-24 11:07:24 +01:00
2015-08-22 00:21:13 -07:00
/ * *
* Constructs a node with the given settings .
*
* @param preparedSettings Base settings to configure the node with
* /
2015-09-08 10:16:25 -07:00
public Node ( Settings preparedSettings ) {
2017-11-19 22:33:17 -06:00
this ( InternalSettingsPreparer . prepareEnvironment ( preparedSettings ) ) ;
2015-02-24 11:07:24 +01:00
}
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
public Node ( Environment environment ) {
this ( environment , Collections . emptyList ( ) ) ;
}
protected Node ( final Environment environment , Collection < Class < ? extends Plugin > > classpathPlugins ) {
2016-06-16 15:52:58 +02:00
final List < Closeable > resourcesToClose = new ArrayList < > ( ) ; // register everything we need to release in the case of an error
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
boolean success = false ;
{
// use temp logger just to say we are starting. we can't use it later on because the node name might not be set
2016-08-09 13:34:23 -04:00
Logger logger = Loggers . getLogger ( Node . class , NODE_NAME_SETTING . get ( environment . settings ( ) ) ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
logger . info ( " initializing ... " ) ;
2015-02-24 11:07:24 +01:00
}
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
try {
Settings tmpSettings = Settings . builder ( ) . put ( environment . settings ( ) )
. put ( Client . CLIENT_TYPE_SETTING_S . getKey ( ) , CLIENT_TYPE ) . build ( ) ;
// create the node environment as soon as possible, to recover the node id and enable logging
try {
nodeEnvironment = new NodeEnvironment ( tmpSettings , environment ) ;
resourcesToClose . add ( nodeEnvironment ) ;
} catch ( IOException ex ) {
2017-04-28 14:48:52 +10:00
throw new IllegalStateException ( " Failed to create node environment " , ex ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
}
final boolean hadPredefinedNodeName = NODE_NAME_SETTING . exists ( tmpSettings ) ;
2018-01-15 09:59:01 -07:00
Logger logger = ServerLoggers . getLogger ( Node . class , tmpSettings ) ;
2016-11-19 06:27:25 -05:00
final String nodeId = nodeEnvironment . nodeId ( ) ;
tmpSettings = addNodeNameIfNeeded ( tmpSettings , nodeId ) ;
// this must be captured after the node name is possibly added to the settings
final String nodeName = NODE_NAME_SETTING . get ( tmpSettings ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
if ( hadPredefinedNodeName = = false ) {
2016-11-19 06:27:25 -05:00
logger . info ( " node name [{}] derived from node ID [{}]; set [{}] to override " , nodeName , nodeId , NODE_NAME_SETTING . getKey ( ) ) ;
} else {
logger . info ( " node name [{}], node ID [{}] " , nodeName , nodeId ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
}
final JvmInfo jvmInfo = JvmInfo . jvmInfo ( ) ;
logger . info (
" version[{}], pid[{}], build[{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}] " ,
2017-07-31 11:45:06 +09:00
Version . displayVersion ( Version . CURRENT , Build . CURRENT . isSnapshot ( ) ) ,
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
jvmInfo . pid ( ) ,
Build . CURRENT . shortHash ( ) ,
Build . CURRENT . date ( ) ,
Constants . OS_NAME ,
Constants . OS_VERSION ,
Constants . OS_ARCH ,
Constants . JVM_VENDOR ,
Constants . JVM_NAME ,
Constants . JAVA_VERSION ,
Constants . JVM_VERSION ) ;
2017-05-02 21:33:24 -04:00
logger . info ( " JVM arguments {} " , Arrays . toString ( jvmInfo . getInputArguments ( ) ) ) ;
2016-09-27 20:13:12 -04:00
warnIfPreRelease ( Version . CURRENT , Build . CURRENT . isSnapshot ( ) , logger ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
if ( logger . isDebugEnabled ( ) ) {
logger . debug ( " using config [{}], data [{}], logs [{}], plugins [{}] " ,
environment . configFile ( ) , Arrays . toString ( environment . dataFiles ( ) ) , environment . logsFile ( ) , environment . pluginsFile ( ) ) ;
}
2015-02-24 11:07:24 +01:00
2017-06-26 15:18:29 -04:00
this . pluginsService = new PluginsService ( tmpSettings , environment . configFile ( ) , environment . modulesFile ( ) , environment . pluginsFile ( ) , classpathPlugins ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
this . settings = pluginsService . updatedSettings ( ) ;
2017-01-13 16:12:27 +01:00
localNodeFactory = new LocalNodeFactory ( settings , nodeEnvironment . nodeId ( ) ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
// create the environment based on the finalized (processed) view of the settings
// this is just to makes sure that people get the same settings, no matter where they ask them from
2017-06-26 15:18:29 -04:00
this . environment = new Environment ( this . settings , environment . configFile ( ) ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
Environment . assertEquivalent ( environment , this . environment ) ;
final List < ExecutorBuilder < ? > > executorBuilders = pluginsService . getExecutorBuilders ( settings ) ;
2015-02-24 11:07:24 +01:00
2016-06-16 15:52:58 +02:00
final ThreadPool threadPool = new ThreadPool ( settings , executorBuilders . toArray ( new ExecutorBuilder [ 0 ] ) ) ;
resourcesToClose . add ( ( ) - > ThreadPool . terminate ( threadPool , 10 , TimeUnit . SECONDS ) ) ;
2016-04-15 20:58:00 -04:00
// adds the context to the DeprecationLogger so that it does not need to be injected everywhere
DeprecationLogger . setThreadContext ( threadPool . getThreadContext ( ) ) ;
resourcesToClose . add ( ( ) - > DeprecationLogger . removeThreadContext ( threadPool . getThreadContext ( ) ) ) ;
2017-05-01 03:26:51 +02:00
final List < Setting < ? > > additionalSettings = new ArrayList < > ( pluginsService . getPluginSettings ( ) ) ;
final List < String > additionalSettingsFilter = new ArrayList < > ( pluginsService . getPluginSettingsFilter ( ) ) ;
2016-06-16 15:52:58 +02:00
for ( final ExecutorBuilder < ? > builder : threadPool . builders ( ) ) {
additionalSettings . addAll ( builder . getRegisteredSettings ( ) ) ;
}
2016-11-10 15:52:17 -08:00
client = new NodeClient ( settings , threadPool ) ;
2016-06-21 11:53:19 -04:00
final ResourceWatcherService resourceWatcherService = new ResourceWatcherService ( settings , threadPool ) ;
2017-05-22 13:11:15 -07:00
final ScriptModule scriptModule = new ScriptModule ( settings , pluginsService . filterPlugins ( ScriptPlugin . class ) ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
AnalysisModule analysisModule = new AnalysisModule ( this . environment , pluginsService . filterPlugins ( AnalysisPlugin . class ) ) ;
2016-06-16 15:52:58 +02:00
// this is as early as we can validate settings at this point. we already pass them to ScriptModule as well as ThreadPool
// so we might be late here already
final SettingsModule settingsModule = new SettingsModule ( this . settings , additionalSettings , additionalSettingsFilter ) ;
Circuit break the number of inline scripts compiled per minute
When compiling many dynamically changing scripts, parameterized
scripts (<https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-using.html#prefer-params>)
should be preferred. This enforces a limit to the number of scripts that
can be compiled within a minute. A new dynamic setting is added -
`script.max_compilations_per_minute`, which defaults to 15.
If more dynamic scripts are sent, a user will get the following
exception:
```json
{
"error" : {
"root_cause" : [
{
"type" : "circuit_breaking_exception",
"reason" : "[script] Too many dynamic script compilations within one minute, max: [15/min]; please use on-disk, indexed, or scripts with parameters instead",
"bytes_wanted" : 0,
"bytes_limit" : 0
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "i",
"node" : "a5V1eXcZRYiIk8lecjZ4Jw",
"reason" : {
"type" : "general_script_exception",
"reason" : "Failed to compile inline script [\"aaaaaaaaaaaaaaaa\"] using lang [painless]",
"caused_by" : {
"type" : "circuit_breaking_exception",
"reason" : "[script] Too many dynamic script compilations within one minute, max: [15/min]; please use on-disk, indexed, or scripts with parameters instead",
"bytes_wanted" : 0,
"bytes_limit" : 0
}
}
}
],
"caused_by" : {
"type" : "general_script_exception",
"reason" : "Failed to compile inline script [\"aaaaaaaaaaaaaaaa\"] using lang [painless]",
"caused_by" : {
"type" : "circuit_breaking_exception",
"reason" : "[script] Too many dynamic script compilations within one minute, max: [15/min]; please use on-disk, indexed, or scripts with parameters instead",
"bytes_wanted" : 0,
"bytes_limit" : 0
}
}
},
"status" : 500
}
```
This also fixes a bug in `ScriptService` where requests being executed
concurrently on a single node could cause a script to be compiled
multiple times (many in the case of a powerful node with many shards)
due to no synchronization between checking the cache and compiling the
script. There is now synchronization so that a script being compiled
will only be compiled once regardless of the number of concurrent
searches on a node.
Relates to #19396
2016-07-26 13:36:29 -06:00
scriptModule . registerClusterSettingsListeners ( settingsModule . getClusterSettings ( ) ) ;
2016-06-20 11:28:14 +02:00
resourcesToClose . add ( resourceWatcherService ) ;
2017-07-02 10:16:50 +02:00
final NetworkService networkService = new NetworkService (
2016-07-27 13:35:58 +02:00
getCustomNameResolvers ( pluginsService . filterPlugins ( DiscoveryPlugin . class ) ) ) ;
2017-08-11 09:51:49 +02:00
List < ClusterPlugin > clusterPlugins = pluginsService . filterPlugins ( ClusterPlugin . class ) ;
final ClusterService clusterService = new ClusterService ( settings , settingsModule . getClusterSettings ( ) , threadPool ,
ClusterModule . getClusterStateCustomSuppliers ( clusterPlugins ) ) ;
2016-12-15 17:06:25 +01:00
clusterService . addListener ( scriptModule . getScriptService ( ) ) ;
2016-06-17 17:07:19 +02:00
resourcesToClose . add ( clusterService ) ;
2017-07-10 13:07:50 -07:00
final IngestService ingestService = new IngestService ( settings , threadPool , this . environment ,
2016-08-30 09:34:06 -04:00
scriptModule . getScriptService ( ) , analysisModule . getAnalysisRegistry ( ) , pluginsService . filterPlugins ( IngestPlugin . class ) ) ;
2017-07-05 22:18:23 +02:00
final DiskThresholdMonitor listener = new DiskThresholdMonitor ( settings , clusterService : : state ,
clusterService . getClusterSettings ( ) , client ) ;
final ClusterInfoService clusterInfoService = newClusterInfoService ( settings , clusterService , threadPool , client ,
listener : : onNewInfo ) ;
2017-06-02 08:46:38 +01:00
final UsageService usageService = new UsageService ( settings ) ;
2016-06-30 01:49:22 -07:00
2015-02-24 11:07:24 +01:00
ModulesBuilder modules = new ModulesBuilder ( ) ;
2015-08-23 11:08:36 -07:00
// plugin modules must be added here, before others or we can get crazy injection errors...
2016-07-11 17:05:32 -07:00
for ( Module pluginModule : pluginsService . createGuiceModules ( ) ) {
2015-08-23 11:08:36 -07:00
modules . add ( pluginModule ) ;
}
Expose disk usage estimates in nodes stats
This exposes the least and most used disk usage estimates within the "fs" nodes
stats output:
```json
GET /_nodes/stats/fs?pretty&human
{
"nodes" : {
"34fPVU0uQ_-wWitDzDXX_g" : {
"fs" : {
"timestamp" : 1481238723550,
"total" : {
"total" : "396.1gb",
"total_in_bytes" : 425343254528,
"free" : "140.6gb",
"free_in_bytes" : 151068725248,
"available" : "120.5gb",
"available_in_bytes" : 129438912512
},
"least_usage_estimate" : {
"path" : "/home/hinmanm/es/elasticsearch/distribution/build/cluster/run node0/elasticsearch-6.0.0-alpha1-SNAPSHOT/data/nodes/0",
"total" : "396.1gb",
"total_in_bytes" : 425343254528,
"available" : "120.5gb",
"available_in_bytes" : 129438633984,
"used_disk_percent" : 69.56842912023208
},
"most_usage_estimate" : {
"path" : "/home/hinmanm/es/elasticsearch/distribution/build/cluster/run node0/elasticsearch-6.0.0-alpha1-SNAPSHOT/data/nodes/0",
"total" : "396.1gb",
"total_in_bytes" : 425343254528,
"available" : "120.5gb",
"available_in_bytes" : 129438633984,
"used_disk_percent" : 69.56842912023208
},
"data" : [{...}],
"io_stats" : {...}
}
}
}
}
```
Resolves #8686
Resolves #22081
2017-01-19 13:26:33 -07:00
final MonitorService monitorService = new MonitorService ( settings , nodeEnvironment , threadPool , clusterInfoService ) ;
2017-08-11 09:51:49 +02:00
ClusterModule clusterModule = new ClusterModule ( settings , clusterService , clusterPlugins , clusterInfoService ) ;
2016-06-27 17:33:01 -04:00
modules . add ( clusterModule ) ;
2016-08-02 15:56:25 -07:00
IndicesModule indicesModule = new IndicesModule ( pluginsService . filterPlugins ( MapperPlugin . class ) ) ;
modules . add ( indicesModule ) ;
2017-01-16 21:06:08 +01:00
2017-02-09 18:06:10 +01:00
SearchModule searchModule = new SearchModule ( settings , false , pluginsService . filterPlugins ( SearchPlugin . class ) ) ;
2016-06-16 15:52:58 +02:00
CircuitBreakerService circuitBreakerService = createCircuitBreakerService ( settingsModule . getSettings ( ) ,
settingsModule . getClusterSettings ( ) ) ;
resourcesToClose . add ( circuitBreakerService ) ;
2017-01-16 21:06:08 +01:00
modules . add ( new GatewayModule ( ) ) ;
2017-12-08 10:39:30 -07:00
PageCacheRecycler pageCacheRecycler = createPageCacheRecycler ( settings ) ;
BigArrays bigArrays = createBigArrays ( pageCacheRecycler , circuitBreakerService ) ;
2016-06-20 13:18:19 +02:00
resourcesToClose . add ( bigArrays ) ;
2016-06-16 15:52:58 +02:00
modules . add ( settingsModule ) ;
2016-08-02 15:56:25 -07:00
List < NamedWriteableRegistry . Entry > namedWriteables = Stream . of (
2016-09-19 22:10:47 +02:00
NetworkModule . getNamedWriteables ( ) . stream ( ) ,
2016-08-02 15:56:25 -07:00
indicesModule . getNamedWriteables ( ) . stream ( ) ,
searchModule . getNamedWriteables ( ) . stream ( ) ,
pluginsService . filterPlugins ( Plugin . class ) . stream ( )
2016-12-27 22:31:34 -05:00
. flatMap ( p - > p . getNamedWriteables ( ) . stream ( ) ) ,
ClusterModule . getNamedWriteables ( ) . stream ( ) )
2016-08-02 15:56:25 -07:00
. flatMap ( Function . identity ( ) ) . collect ( Collectors . toList ( ) ) ;
final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry ( namedWriteables ) ;
2016-12-20 11:05:24 -05:00
NamedXContentRegistry xContentRegistry = new NamedXContentRegistry ( Stream . of (
2017-01-09 12:26:57 -05:00
NetworkModule . getNamedXContents ( ) . stream ( ) ,
2016-12-27 22:31:34 -05:00
searchModule . getNamedXContents ( ) . stream ( ) ,
pluginsService . filterPlugins ( Plugin . class ) . stream ( )
. flatMap ( p - > p . getNamedXContent ( ) . stream ( ) ) ,
ClusterModule . getNamedXWriteables ( ) . stream ( ) )
. flatMap ( Function . identity ( ) ) . collect ( toList ( ) ) ) ;
modules . add ( new RepositoriesModule ( this . environment , pluginsService . filterPlugins ( RepositoryPlugin . class ) , xContentRegistry ) ) ;
final MetaStateService metaStateService = new MetaStateService ( settings , nodeEnvironment , xContentRegistry ) ;
2016-12-20 11:05:24 -05:00
final IndicesService indicesService = new IndicesService ( settings , pluginsService , nodeEnvironment , xContentRegistry ,
2017-05-09 15:08:11 -04:00
analysisModule . getAnalysisRegistry ( ) ,
2016-08-19 00:27:37 -07:00
clusterModule . getIndexNameExpressionResolver ( ) , indicesModule . getMapperRegistry ( ) , namedWriteableRegistry ,
2016-10-07 13:51:08 -04:00
threadPool , settingsModule . getIndexScopedSettings ( ) , circuitBreakerService , bigArrays , scriptModule . getScriptService ( ) ,
2017-07-26 10:20:40 +02:00
client , metaStateService ) ;
2016-09-19 22:10:47 +02:00
2016-07-11 23:16:23 -07:00
Collection < Object > pluginComponents = pluginsService . filterPlugins ( Plugin . class ) . stream ( )
2016-08-03 00:32:47 -07:00
. flatMap ( p - > p . createComponents ( client , clusterService , threadPool , resourceWatcherService ,
2017-07-28 11:23:50 +02:00
scriptModule . getScriptService ( ) , xContentRegistry , environment , nodeEnvironment ,
namedWriteableRegistry ) . stream ( ) )
2016-07-11 23:16:23 -07:00
. collect ( Collectors . toList ( ) ) ;
2017-09-20 10:30:21 +02:00
ActionModule actionModule = new ActionModule ( false , settings , clusterModule . getIndexNameExpressionResolver ( ) ,
settingsModule . getIndexScopedSettings ( ) , settingsModule . getClusterSettings ( ) , settingsModule . getSettingsFilter ( ) ,
threadPool , pluginsService . filterPlugins ( ActionPlugin . class ) , client , circuitBreakerService , usageService ) ;
modules . add ( actionModule ) ;
2017-01-16 21:06:08 +01:00
final RestController restController = actionModule . getRestController ( ) ;
2016-12-20 11:05:24 -05:00
final NetworkModule networkModule = new NetworkModule ( settings , false , pluginsService . filterPlugins ( NetworkPlugin . class ) ,
2017-12-08 10:39:30 -07:00
threadPool , bigArrays , pageCacheRecycler , circuitBreakerService , namedWriteableRegistry , xContentRegistry ,
networkService , restController ) ;
2017-05-03 12:51:41 -04:00
Collection < UnaryOperator < Map < String , MetaData . Custom > > > customMetaDataUpgraders =
pluginsService . filterPlugins ( Plugin . class ) . stream ( )
. map ( Plugin : : getCustomMetaDataUpgrader )
. collect ( Collectors . toList ( ) ) ;
Collection < UnaryOperator < Map < String , IndexTemplateMetaData > > > indexTemplateMetaDataUpgraders =
pluginsService . filterPlugins ( Plugin . class ) . stream ( )
. map ( Plugin : : getIndexTemplateMetaDataUpgrader )
. collect ( Collectors . toList ( ) ) ;
Collection < UnaryOperator < IndexMetaData > > indexMetaDataUpgraders = pluginsService . filterPlugins ( Plugin . class ) . stream ( )
. map ( Plugin : : getIndexMetaDataUpgrader ) . collect ( Collectors . toList ( ) ) ;
final MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader ( customMetaDataUpgraders , indexTemplateMetaDataUpgraders ) ;
2017-09-20 12:51:58 +02:00
final MetaDataIndexUpgradeService metaDataIndexUpgradeService = new MetaDataIndexUpgradeService ( settings , xContentRegistry ,
indicesModule . getMapperRegistry ( ) , settingsModule . getIndexScopedSettings ( ) , indexMetaDataUpgraders ) ;
final GatewayMetaState gatewayMetaState = new GatewayMetaState ( settings , nodeEnvironment , metaStateService ,
metaDataIndexUpgradeService , metaDataUpgrader ) ;
2017-06-22 14:55:28 -04:00
new TemplateUpgradeService ( settings , client , clusterService , threadPool , indexTemplateMetaDataUpgraders ) ;
2016-09-19 22:10:47 +02:00
final Transport transport = networkModule . getTransportSupplier ( ) . get ( ) ;
Add ability to associate an ID with tasks (#27764)
Adds support for capturing the X-Opaque-Id header from a REST request and storing it's value in the tasks that this request started. It works for all user-initiated tasks (not only search).
Closes #23250
Usage:
```
$ curl -H "X-Opaque-Id: imotov" -H "foo:bar" "localhost:9200/_tasks?pretty&group_by=parents"
{
"tasks" : {
"7qrTVbiDQKiZfubUP7DPkg:6998" : {
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6998,
"type" : "transport",
"action" : "cluster:monitor/tasks/lists",
"start_time_in_millis" : 1513029940042,
"running_time_in_nanos" : 266794,
"cancellable" : false,
"headers" : {
"X-Opaque-Id" : "imotov"
},
"children" : [
{
"node" : "V-PuCjPhRp2ryuEsNw6V1g",
"id" : 6088,
"type" : "netty",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 67785,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
},
{
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6999,
"type" : "direct",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 98754,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
}
]
}
}
}
```
2018-01-12 15:34:17 -05:00
Set < String > taskHeaders = Stream . concat (
pluginsService . filterPlugins ( ActionPlugin . class ) . stream ( ) . flatMap ( p - > p . getTaskHeaders ( ) . stream ( ) ) ,
Stream . of ( " X-Opaque-Id " )
) . collect ( Collectors . toSet ( ) ) ;
2016-09-19 22:10:47 +02:00
final TransportService transportService = newTransportService ( settings , transport , threadPool ,
Add ability to associate an ID with tasks (#27764)
Adds support for capturing the X-Opaque-Id header from a REST request and storing it's value in the tasks that this request started. It works for all user-initiated tasks (not only search).
Closes #23250
Usage:
```
$ curl -H "X-Opaque-Id: imotov" -H "foo:bar" "localhost:9200/_tasks?pretty&group_by=parents"
{
"tasks" : {
"7qrTVbiDQKiZfubUP7DPkg:6998" : {
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6998,
"type" : "transport",
"action" : "cluster:monitor/tasks/lists",
"start_time_in_millis" : 1513029940042,
"running_time_in_nanos" : 266794,
"cancellable" : false,
"headers" : {
"X-Opaque-Id" : "imotov"
},
"children" : [
{
"node" : "V-PuCjPhRp2ryuEsNw6V1g",
"id" : 6088,
"type" : "netty",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 67785,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
},
{
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6999,
"type" : "direct",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 98754,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
}
]
}
}
}
```
2018-01-12 15:34:17 -05:00
networkModule . getTransportInterceptor ( ) , localNodeFactory , settingsModule . getClusterSettings ( ) , taskHeaders ) ;
2017-07-17 11:04:51 -06:00
final ResponseCollectorService responseCollectorService = new ResponseCollectorService ( this . settings , clusterService ) ;
final SearchTransportService searchTransportService = new SearchTransportService ( settings , transportService ,
SearchExecutionStatsCollector . makeWrapper ( responseCollectorService ) ) ;
2016-09-19 22:10:47 +02:00
final Consumer < Binder > httpBind ;
2017-01-16 21:06:08 +01:00
final HttpServerTransport httpServerTransport ;
2016-09-19 22:10:47 +02:00
if ( networkModule . isHttpEnabled ( ) ) {
2017-01-16 21:06:08 +01:00
httpServerTransport = networkModule . getHttpServerTransportSupplier ( ) . get ( ) ;
2016-09-19 22:10:47 +02:00
httpBind = b - > {
b . bind ( HttpServerTransport . class ) . toInstance ( httpServerTransport ) ;
} ;
} else {
httpBind = b - > {
2017-01-16 21:06:08 +01:00
b . bind ( HttpServerTransport . class ) . toProvider ( Providers . of ( null ) ) ;
2016-09-19 22:10:47 +02:00
} ;
2017-01-16 21:06:08 +01:00
httpServerTransport = null ;
2016-09-19 22:10:47 +02:00
}
2017-04-28 09:34:31 +02:00
final DiscoveryModule discoveryModule = new DiscoveryModule ( this . settings , threadPool , transportService , namedWriteableRegistry ,
networkService , clusterService . getMasterService ( ) , clusterService . getClusterApplierService ( ) ,
2017-05-05 08:39:18 +02:00
clusterService . getClusterSettings ( ) , pluginsService . filterPlugins ( DiscoveryPlugin . class ) ,
clusterModule . getAllocationService ( ) ) ;
2017-07-05 22:18:23 +02:00
this . nodeService = new NodeService ( settings , threadPool , monitorService , discoveryModule . getDiscovery ( ) ,
2017-01-16 21:06:08 +01:00
transportService , indicesService , pluginsService , circuitBreakerService , scriptModule . getScriptService ( ) ,
Expose adaptive replica selection stats in /_nodes/stats API
This exposes the collected metrics we store for ARS in the nodes stats, as well
as the computed rank of nodes. Each node exposes its perspective about the
cluster.
Here's an example output (with `?human`):
```json
...
"adaptive_selection" : {
"_k6v1-wERxyUd5ke6s-D0g" : {
"outgoing_searches" : 0,
"avg_queue_size" : 0,
"avg_service_time" : "7.8ms",
"avg_service_time_ns" : 7896963,
"avg_response_time" : "9ms",
"avg_response_time_ns" : 9095598,
"rank" : "9.1"
},
"VJiCUFoiTpySGmO00eWmtQ" : {
"outgoing_searches" : 0,
"avg_queue_size" : 0,
"avg_service_time" : "1.3ms",
"avg_service_time_ns" : 1330240,
"avg_response_time" : "4.5ms",
"avg_response_time_ns" : 4524154,
"rank" : "4.5"
},
"DHNGTdzyT9iiaCpEUsIAKA" : {
"outgoing_searches" : 0,
"avg_queue_size" : 0,
"avg_service_time" : "2.1ms",
"avg_service_time_ns" : 2113164,
"avg_response_time" : "6.3ms",
"avg_response_time_ns" : 6375810,
"rank" : "6.4"
}
}
...
```
2017-10-18 06:57:30 -06:00
httpServerTransport , ingestService , clusterService , settingsModule . getSettingsFilter ( ) , responseCollectorService ,
searchTransportService ) ;
2017-12-06 09:15:28 +01:00
final SearchService searchService = newSearchService ( clusterService , indicesService ,
threadPool , scriptModule . getScriptService ( ) , bigArrays , searchModule . getFetchPhase ( ) ,
responseCollectorService ) ;
2016-06-20 11:28:14 +02:00
modules . add ( b - > {
2017-07-05 22:18:23 +02:00
b . bind ( Node . class ) . toInstance ( this ) ;
2017-01-16 21:06:08 +01:00
b . bind ( NodeService . class ) . toInstance ( nodeService ) ;
2016-12-20 11:05:24 -05:00
b . bind ( NamedXContentRegistry . class ) . toInstance ( xContentRegistry ) ;
2016-06-20 11:53:07 +02:00
b . bind ( PluginsService . class ) . toInstance ( pluginsService ) ;
2016-06-29 14:55:31 -04:00
b . bind ( Client . class ) . toInstance ( client ) ;
2016-06-29 15:35:55 -07:00
b . bind ( NodeClient . class ) . toInstance ( client ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
b . bind ( Environment . class ) . toInstance ( this . environment ) ;
2016-06-20 11:28:14 +02:00
b . bind ( ThreadPool . class ) . toInstance ( threadPool ) ;
b . bind ( NodeEnvironment . class ) . toInstance ( nodeEnvironment ) ;
b . bind ( ResourceWatcherService . class ) . toInstance ( resourceWatcherService ) ;
b . bind ( CircuitBreakerService . class ) . toInstance ( circuitBreakerService ) ;
2016-06-20 13:18:19 +02:00
b . bind ( BigArrays . class ) . toInstance ( bigArrays ) ;
2016-06-21 11:53:19 -04:00
b . bind ( ScriptService . class ) . toInstance ( scriptModule . getScriptService ( ) ) ;
2016-06-24 16:37:23 -04:00
b . bind ( AnalysisRegistry . class ) . toInstance ( analysisModule . getAnalysisRegistry ( ) ) ;
2016-06-30 01:49:22 -07:00
b . bind ( IngestService . class ) . toInstance ( ingestService ) ;
2017-07-05 22:18:23 +02:00
b . bind ( UsageService . class ) . toInstance ( usageService ) ;
2016-08-02 15:56:25 -07:00
b . bind ( NamedWriteableRegistry . class ) . toInstance ( namedWriteableRegistry ) ;
2016-08-19 00:27:37 -07:00
b . bind ( MetaDataUpgrader . class ) . toInstance ( metaDataUpgrader ) ;
b . bind ( MetaStateService . class ) . toInstance ( metaStateService ) ;
b . bind ( IndicesService . class ) . toInstance ( indicesService ) ;
2017-12-06 09:15:28 +01:00
b . bind ( SearchService . class ) . toInstance ( searchService ) ;
2017-04-11 09:24:40 +02:00
b . bind ( SearchTransportService . class ) . toInstance ( searchTransportService ) ;
2017-12-06 09:15:28 +01:00
b . bind ( SearchPhaseController . class ) . toInstance ( new SearchPhaseController ( settings ,
searchService : : createReduceContext ) ) ;
2016-09-19 22:10:47 +02:00
b . bind ( Transport . class ) . toInstance ( transport ) ;
b . bind ( TransportService . class ) . toInstance ( transportService ) ;
b . bind ( NetworkService . class ) . toInstance ( networkService ) ;
2016-10-06 16:04:45 -04:00
b . bind ( UpdateHelper . class ) . toInstance ( new UpdateHelper ( settings , scriptModule . getScriptService ( ) ) ) ;
2017-09-20 12:51:58 +02:00
b . bind ( MetaDataIndexUpgradeService . class ) . toInstance ( metaDataIndexUpgradeService ) ;
2016-11-10 15:52:17 -08:00
b . bind ( ClusterInfoService . class ) . toInstance ( clusterInfoService ) ;
2017-09-20 12:51:58 +02:00
b . bind ( GatewayMetaState . class ) . toInstance ( gatewayMetaState ) ;
2016-11-08 12:52:10 -08:00
b . bind ( Discovery . class ) . toInstance ( discoveryModule . getDiscovery ( ) ) ;
2016-10-06 16:04:45 -04:00
{
RecoverySettings recoverySettings = new RecoverySettings ( settings , settingsModule . getClusterSettings ( ) ) ;
processRecoverySettings ( settingsModule . getClusterSettings ( ) , recoverySettings ) ;
b . bind ( PeerRecoverySourceService . class ) . toInstance ( new PeerRecoverySourceService ( settings , transportService ,
2017-07-14 13:52:53 +02:00
indicesService , recoverySettings ) ) ;
2016-10-06 16:04:45 -04:00
b . bind ( PeerRecoveryTargetService . class ) . toInstance ( new PeerRecoveryTargetService ( settings , threadPool ,
transportService , recoverySettings , clusterService ) ) ;
}
2016-09-19 22:10:47 +02:00
httpBind . accept ( b ) ;
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
pluginComponents . stream ( ) . forEach ( p - > b . bind ( ( Class ) p . getClass ( ) ) . toInstance ( p ) ) ;
2016-06-20 11:28:14 +02:00
}
) ;
2015-02-24 11:07:24 +01:00
injector = modules . createInjector ( ) ;
2016-04-15 20:58:00 -04:00
2017-05-05 08:39:18 +02:00
// TODO hack around circular dependencies problems in AllocationService
clusterModule . getAllocationService ( ) . setGatewayAllocator ( injector . getInstance ( GatewayAllocator . class ) ) ;
2016-07-11 14:16:23 -07:00
List < LifecycleComponent > pluginLifecycleComponents = pluginComponents . stream ( )
2016-07-11 13:07:22 -07:00
. filter ( p - > p instanceof LifecycleComponent )
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
. map ( p - > ( LifecycleComponent ) p ) . collect ( Collectors . toList ( ) ) ;
2016-07-11 14:16:23 -07:00
pluginLifecycleComponents . addAll ( pluginsService . getGuiceServiceClasses ( ) . stream ( )
2016-07-11 13:07:22 -07:00
. map ( injector : : getInstance ) . collect ( Collectors . toList ( ) ) ) ;
2016-07-11 14:16:23 -07:00
resourcesToClose . addAll ( pluginLifecycleComponents ) ;
this . pluginLifecycleComponents = Collections . unmodifiableList ( pluginLifecycleComponents ) ;
2017-01-10 18:26:06 -05:00
client . initialize ( injector . getInstance ( new Key < Map < GenericAction , TransportAction > > ( ) { } ) ,
( ) - > clusterService . localNode ( ) . getId ( ) ) ;
2016-04-15 20:58:00 -04:00
2017-01-20 11:48:51 -05:00
if ( NetworkModule . HTTP_ENABLED . get ( settings ) ) {
logger . debug ( " initializing HTTP handlers ... " ) ;
2017-04-11 14:40:37 +02:00
actionModule . initRestHandlers ( ( ) - > clusterService . state ( ) . nodes ( ) ) ;
2017-01-20 11:48:51 -05:00
}
Persistent Node Names (#19456)
With #19140 we started persisting the node ID across node restarts. Now that we have a "stable" anchor, we can use it to generate a stable default node name and make it easier to track nodes over a restarts. Sadly, this means we will not have those random fun Marvel characters but we feel this is the right tradeoff.
On the implementation side, this requires a bit of juggling because we now need to read the node id from disk before we can log as the node node is part of each log message. The PR move the initialization of NodeEnvironment as high up in the starting sequence as possible, with only one logging message before it to indicate we are initializing. Things look now like this:
```
[2016-07-15 19:38:39,742][INFO ][node ] [_unset_] initializing ...
[2016-07-15 19:38:39,826][INFO ][node ] [aAmiW40] node name set to [aAmiW40] by default. set the [node.name] settings to change it
[2016-07-15 19:38:39,829][INFO ][env ] [aAmiW40] using [1] data paths, mounts [[ /(/dev/disk1)]], net usable_space [5.5gb], net total_space [232.6gb], spins? [unknown], types [hfs]
[2016-07-15 19:38:39,830][INFO ][env ] [aAmiW40] heap size [1.9gb], compressed ordinary object pointers [true]
[2016-07-15 19:38:39,837][INFO ][node ] [aAmiW40] version[5.0.0-alpha5-SNAPSHOT], pid[46048], build[473d3c0/2016-07-15T17:38:06.771Z], OS[Mac OS X/10.11.5/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_51/25.51-b03]
[2016-07-15 19:38:40,980][INFO ][plugins ] [aAmiW40] modules [percolator, lang-mustache, lang-painless, reindex, aggs-matrix-stats, lang-expression, ingest-common, lang-groovy, transport-netty], plugins []
[2016-07-15 19:38:43,218][INFO ][node ] [aAmiW40] initialized
```
Needless to say, settings `node.name` explicitly still works as before.
The commit also contains some clean ups to the relationship between Environment, Settings and Plugins. The previous code suggested the path related settings could be changed after the initial Environment was changed. This did not have any effect as the security manager already locked things down.
2016-07-23 22:46:48 +02:00
logger . info ( " initialized " ) ;
2015-02-24 11:07:24 +01:00
success = true ;
2015-11-26 09:50:41 +01:00
} catch ( IOException ex ) {
throw new ElasticsearchException ( " failed to bind service " , ex ) ;
2015-02-24 11:07:24 +01:00
} finally {
if ( ! success ) {
2016-06-16 15:52:58 +02:00
IOUtils . closeWhileHandlingException ( resourcesToClose ) ;
2015-02-24 11:07:24 +01:00
}
}
}
2010-02-08 15:30:06 +02:00
2016-09-27 20:13:12 -04:00
static void warnIfPreRelease ( final Version version , final boolean isSnapshot , final Logger logger ) {
if ( ! version . isRelease ( ) | | isSnapshot ) {
logger . warn (
" version [{}] is a pre-release version of Elasticsearch and is not suitable for production " ,
2017-07-31 11:45:06 +09:00
Version . displayVersion ( version , isSnapshot ) ) ;
2016-09-27 20:13:12 -04:00
}
}
2016-09-19 22:10:47 +02:00
protected TransportService newTransportService ( Settings settings , Transport transport , ThreadPool threadPool ,
2017-01-13 16:12:27 +01:00
TransportInterceptor interceptor ,
Function < BoundTransportAddress , DiscoveryNode > localNodeFactory ,
Add ability to associate an ID with tasks (#27764)
Adds support for capturing the X-Opaque-Id header from a REST request and storing it's value in the tasks that this request started. It works for all user-initiated tasks (not only search).
Closes #23250
Usage:
```
$ curl -H "X-Opaque-Id: imotov" -H "foo:bar" "localhost:9200/_tasks?pretty&group_by=parents"
{
"tasks" : {
"7qrTVbiDQKiZfubUP7DPkg:6998" : {
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6998,
"type" : "transport",
"action" : "cluster:monitor/tasks/lists",
"start_time_in_millis" : 1513029940042,
"running_time_in_nanos" : 266794,
"cancellable" : false,
"headers" : {
"X-Opaque-Id" : "imotov"
},
"children" : [
{
"node" : "V-PuCjPhRp2ryuEsNw6V1g",
"id" : 6088,
"type" : "netty",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 67785,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
},
{
"node" : "7qrTVbiDQKiZfubUP7DPkg",
"id" : 6999,
"type" : "direct",
"action" : "cluster:monitor/tasks/lists[n]",
"start_time_in_millis" : 1513029940043,
"running_time_in_nanos" : 98754,
"cancellable" : false,
"parent_task_id" : "7qrTVbiDQKiZfubUP7DPkg:6998",
"headers" : {
"X-Opaque-Id" : "imotov"
}
}
]
}
}
}
```
2018-01-12 15:34:17 -05:00
ClusterSettings clusterSettings , Set < String > taskHeaders ) {
return new TransportService ( settings , transport , threadPool , interceptor , localNodeFactory , clusterSettings , taskHeaders ) ;
2016-10-06 16:04:45 -04:00
}
protected void processRecoverySettings ( ClusterSettings clusterSettings , RecoverySettings recoverySettings ) {
// Noop in production, overridden by tests
2016-09-16 09:47:53 +02:00
}
2010-02-13 20:03:37 +02:00
/ * *
2010-04-09 00:54:54 +03:00
* The settings that were used to create the node .
2010-02-13 20:03:37 +02:00
* /
2015-02-24 11:07:24 +01:00
public Settings settings ( ) {
return this . settings ;
}
2010-02-08 15:30:06 +02:00
2010-02-13 20:03:37 +02:00
/ * *
* A client that can be used to execute actions ( operations ) against the cluster .
* /
2015-02-24 11:07:24 +01:00
public Client client ( ) {
return client ;
}
2010-02-08 15:30:06 +02:00
2016-01-15 14:25:43 +01:00
/ * *
* Returns the environment of the node
* /
public Environment getEnvironment ( ) {
return environment ;
}
2016-06-28 16:38:56 +02:00
/ * *
* Returns the { @link NodeEnvironment } instance of this node
* /
public NodeEnvironment getNodeEnvironment ( ) {
return nodeEnvironment ;
}
2010-02-13 20:03:37 +02:00
/ * *
2010-04-09 00:54:54 +03:00
* Start the node . If the node is already started , this method is no - op .
2010-02-13 20:03:37 +02:00
* /
2016-09-08 10:56:11 -04:00
public Node start ( ) throws NodeValidationException {
2016-04-14 14:13:31 -04:00
if ( ! lifecycle . moveToStarted ( ) ) {
return this ;
}
2016-08-09 13:34:23 -04:00
Logger logger = Loggers . getLogger ( Node . class , NODE_NAME_SETTING . get ( settings ) ) ;
2015-02-24 11:07:24 +01:00
logger . info ( " starting ... " ) ;
2016-07-11 13:07:22 -07:00
pluginLifecycleComponents . forEach ( LifecycleComponent : : start ) ;
2015-02-24 11:07:24 +01:00
2015-04-21 15:30:35 +02:00
injector . getInstance ( MappingUpdatedAction . class ) . setClient ( client ) ;
2015-02-24 11:07:24 +01:00
injector . getInstance ( IndicesService . class ) . start ( ) ;
injector . getInstance ( IndicesClusterStateService . class ) . start ( ) ;
injector . getInstance ( SnapshotsService . class ) . start ( ) ;
2015-06-23 18:01:32 -04:00
injector . getInstance ( SnapshotShardsService . class ) . start ( ) ;
2015-02-24 11:07:24 +01:00
injector . getInstance ( RoutingService . class ) . start ( ) ;
injector . getInstance ( SearchService . class ) . start ( ) ;
2017-07-05 22:18:23 +02:00
nodeService . getMonitorService ( ) . start ( ) ;
Async fetch of shard started and store during allocation
Today, when a primary shard is not allocated we go to all the nodes to find where it is allocated (listing its started state). When we allocate a replica shard, we head to all the nodes and list its store to allocate the replica on a node that holds the closest matching index files to the primary.
Those two operations today execute synchronously within the GatewayAllocator, which means they execute in a sync manner within the cluster update thread. For large clusters, or environments with very slow disk, those operations will stall the cluster update thread, making it seem like its stuck.
Worse, if the FS is really slow, we timeout after 30s the operation (to not stall the cluster update thread completely). This means that we will have another run for the primary shard if we didn't find one, or we won't find the best node to place a shard since it might have timed out (listing stores need to list all files and read the checksum at the end of each file).
On top of that, this sync operation happen one shard at a time, so its effectively compounding the problem in a serial manner the more shards we have and the slower FS is...
This change moves to perform both listing the shard started states and the shard stores to an async manner. During the allocation by the GatewayAllocator, if data needs to be fetched from a node, it is done in an async fashion, with the response triggering a reroute to make sure the results will be taken into account. Also, if there are on going operations happening, the relevant shard data will not be taken into account until all the ongoing listing operations are done executing.
The execution of listing shard states and stores has been moved to their own respective thread pools (scaling, so will go down to 0 when not needed anymore, unbounded queue, since we don't want to timeout, just let it execute based on how fast the local FS is). This is needed sine we are going to blast nodes with a lot of requests and we need to make sure there is no thread explosion.
This change also improves the handling of shard failures coming from a specific node. Today, those nodes were ignored from allocation only for the single reroute round. Now, since fetching is async, we need to keep those failures around at least until a single successful fetch without the node is done, to make sure not to repeat allocating to the failed node all the time.
Note, if before the indication of slow allocation was high pending tasks since the allocator was waiting for responses, not the pending tasks will be much smaller. In order to still indicate that the cluster is in the middle of fetching shard data, 2 attributes were added to the cluster health API, indicating the number of ongoing fetches of both started shards and shard store.
closes #9502
closes #11101
2015-05-11 01:19:13 +02:00
2016-03-17 22:42:20 +01:00
final ClusterService clusterService = injector . getInstance ( ClusterService . class ) ;
Async fetch of shard started and store during allocation
Today, when a primary shard is not allocated we go to all the nodes to find where it is allocated (listing its started state). When we allocate a replica shard, we head to all the nodes and list its store to allocate the replica on a node that holds the closest matching index files to the primary.
Those two operations today execute synchronously within the GatewayAllocator, which means they execute in a sync manner within the cluster update thread. For large clusters, or environments with very slow disk, those operations will stall the cluster update thread, making it seem like its stuck.
Worse, if the FS is really slow, we timeout after 30s the operation (to not stall the cluster update thread completely). This means that we will have another run for the primary shard if we didn't find one, or we won't find the best node to place a shard since it might have timed out (listing stores need to list all files and read the checksum at the end of each file).
On top of that, this sync operation happen one shard at a time, so its effectively compounding the problem in a serial manner the more shards we have and the slower FS is...
This change moves to perform both listing the shard started states and the shard stores to an async manner. During the allocation by the GatewayAllocator, if data needs to be fetched from a node, it is done in an async fashion, with the response triggering a reroute to make sure the results will be taken into account. Also, if there are on going operations happening, the relevant shard data will not be taken into account until all the ongoing listing operations are done executing.
The execution of listing shard states and stores has been moved to their own respective thread pools (scaling, so will go down to 0 when not needed anymore, unbounded queue, since we don't want to timeout, just let it execute based on how fast the local FS is). This is needed sine we are going to blast nodes with a lot of requests and we need to make sure there is no thread explosion.
This change also improves the handling of shard failures coming from a specific node. Today, those nodes were ignored from allocation only for the single reroute round. Now, since fetching is async, we need to keep those failures around at least until a single successful fetch without the node is done, to make sure not to repeat allocating to the failed node all the time.
Note, if before the indication of slow allocation was high pending tasks since the allocator was waiting for responses, not the pending tasks will be much smaller. In order to still indicate that the cluster is in the middle of fetching shard data, 2 attributes were added to the cluster health API, indicating the number of ongoing fetches of both started shards and shard store.
closes #9502
closes #11101
2015-05-11 01:19:13 +02:00
2016-02-27 18:48:42 +01:00
final NodeConnectionsService nodeConnectionsService = injector . getInstance ( NodeConnectionsService . class ) ;
nodeConnectionsService . start ( ) ;
clusterService . setNodeConnectionsService ( nodeConnectionsService ) ;
2016-02-24 14:10:55 -08:00
2016-02-18 13:57:59 -08:00
injector . getInstance ( ResourceWatcherService . class ) . start ( ) ;
injector . getInstance ( GatewayService . class ) . start ( ) ;
2016-02-24 14:10:55 -08:00
Discovery discovery = injector . getInstance ( Discovery . class ) ;
2017-04-28 09:34:31 +02:00
clusterService . getMasterService ( ) . setClusterStatePublisher ( discovery : : publish ) ;
2016-02-24 14:10:55 -08:00
2016-02-18 13:57:59 -08:00
// Start the transport service now so the publish address will be added to the local disco node in ClusterService
TransportService transportService = injector . getInstance ( TransportService . class ) ;
2016-08-12 16:46:02 -04:00
transportService . getTaskManager ( ) . setTaskResultsService ( injector . getInstance ( TaskResultsService . class ) ) ;
2016-02-18 13:57:59 -08:00
transportService . start ( ) ;
2017-04-28 09:34:31 +02:00
assert localNodeFactory . getNode ( ) ! = null ;
assert transportService . getLocalNode ( ) . equals ( localNodeFactory . getNode ( ) )
: " transportService has a different local node than the factory provided " ;
2017-09-13 22:14:17 +02:00
final MetaData onDiskMetadata ;
try {
// we load the global state here (the persistent part of the cluster state stored on disk) to
// pass it to the bootstrap checks to allow plugins to enforce certain preconditions based on the recovered state.
if ( DiscoveryNode . isMasterNode ( settings ) | | DiscoveryNode . isDataNode ( settings ) ) {
onDiskMetadata = injector . getInstance ( GatewayMetaState . class ) . loadMetaState ( ) ;
} else {
onDiskMetadata = MetaData . EMPTY_META_DATA ;
}
assert onDiskMetadata ! = null : " metadata is null but shouldn't " ; // this is never null
} catch ( IOException e ) {
throw new UncheckedIOException ( e ) ;
}
validateNodeBeforeAcceptingRequests ( new BootstrapContext ( settings , onDiskMetadata ) , transportService . boundAddress ( ) , pluginsService
. filterPlugins ( Plugin
. class )
. stream ( )
2016-12-12 17:35:00 +01:00
. flatMap ( p - > p . getBootstrapChecks ( ) . stream ( ) ) . collect ( Collectors . toList ( ) ) ) ;
2016-04-07 09:10:46 -04:00
2016-12-15 17:06:25 +01:00
clusterService . addStateApplier ( transportService . getTaskManager ( ) ) ;
2017-04-28 09:34:31 +02:00
// start after transport service so the local disco is known
2017-05-12 14:08:14 +02:00
discovery . start ( ) ; // start before cluster service so that it can set initial state on ClusterApplierService
2016-02-24 14:10:55 -08:00
clusterService . start ( ) ;
2017-01-13 16:12:27 +01:00
assert clusterService . localNode ( ) . equals ( localNodeFactory . getNode ( ) )
: " clusterService has a different local node than the factory provided " ;
2016-02-18 13:57:59 -08:00
transportService . acceptIncomingRequests ( ) ;
2016-02-24 14:10:55 -08:00
discovery . startInitialJoin ( ) ;
2016-11-29 20:38:19 +01:00
final TimeValue initialStateTimeout = DiscoverySettings . INITIAL_STATE_TIMEOUT_SETTING . get ( settings ) ;
if ( initialStateTimeout . millis ( ) > 0 ) {
2016-02-24 14:10:55 -08:00
final ThreadPool thread = injector . getInstance ( ThreadPool . class ) ;
2016-12-20 15:16:04 +01:00
ClusterState clusterState = clusterService . state ( ) ;
ClusterStateObserver observer = new ClusterStateObserver ( clusterState , clusterService , null , logger , thread . getThreadContext ( ) ) ;
if ( clusterState . nodes ( ) . getMasterNodeId ( ) = = null ) {
2016-11-29 20:38:19 +01:00
logger . debug ( " waiting to join the cluster. timeout [{}] " , initialStateTimeout ) ;
2016-03-04 17:30:15 +01:00
final CountDownLatch latch = new CountDownLatch ( 1 ) ;
2016-02-24 14:10:55 -08:00
observer . waitForNextChange ( new ClusterStateObserver . Listener ( ) {
@Override
2016-03-04 17:30:15 +01:00
public void onNewClusterState ( ClusterState state ) { latch . countDown ( ) ; }
2016-02-24 14:10:55 -08:00
@Override
public void onClusterServiceClose ( ) {
latch . countDown ( ) ;
}
@Override
public void onTimeout ( TimeValue timeout ) {
2016-03-04 17:30:15 +01:00
logger . warn ( " timed out while waiting for initial discovery state - timeout: {} " ,
2016-11-29 20:38:19 +01:00
initialStateTimeout ) ;
2016-03-04 17:30:15 +01:00
latch . countDown ( ) ;
2016-02-24 14:10:55 -08:00
}
2016-12-15 17:06:25 +01:00
} , state - > state . nodes ( ) . getMasterNodeId ( ) ! = null , initialStateTimeout ) ;
2016-02-24 14:10:55 -08:00
2016-03-04 17:30:15 +01:00
try {
latch . await ( ) ;
} catch ( InterruptedException e ) {
throw new ElasticsearchTimeoutException ( " Interrupted while waiting for initial discovery state " ) ;
}
2016-02-24 14:10:55 -08:00
}
}
2015-02-24 11:07:24 +01:00
2016-12-20 22:23:11 +01:00
2016-07-11 20:44:57 +02:00
if ( NetworkModule . HTTP_ENABLED . get ( settings ) ) {
2017-01-16 21:06:08 +01:00
injector . getInstance ( HttpServerTransport . class ) . start ( ) ;
2015-02-24 11:07:24 +01:00
}
2016-02-24 14:10:55 -08:00
2017-04-27 00:59:54 -07:00
if ( WRITE_PORTS_FILE_SETTING . get ( settings ) ) {
2016-07-11 20:44:57 +02:00
if ( NetworkModule . HTTP_ENABLED . get ( settings ) ) {
2015-12-11 17:36:08 -08:00
HttpServerTransport http = injector . getInstance ( HttpServerTransport . class ) ;
writePortsFile ( " http " , http . boundAddress ( ) ) ;
}
TransportService transport = injector . getInstance ( TransportService . class ) ;
writePortsFile ( " transport " , transport . boundAddress ( ) ) ;
}
2015-02-24 11:07:24 +01:00
logger . info ( " started " ) ;
2017-07-28 11:23:50 +02:00
pluginsService . filterPlugins ( ClusterPlugin . class ) . forEach ( ClusterPlugin : : onNodeStarted ) ;
2015-02-24 11:07:24 +01:00
return this ;
}
2015-02-27 13:49:40 +01:00
private Node stop ( ) {
2015-02-24 11:07:24 +01:00
if ( ! lifecycle . moveToStopped ( ) ) {
return this ;
}
2016-08-09 13:34:23 -04:00
Logger logger = Loggers . getLogger ( Node . class , NODE_NAME_SETTING . get ( settings ) ) ;
2015-02-24 11:07:24 +01:00
logger . info ( " stopping ... " ) ;
injector . getInstance ( ResourceWatcherService . class ) . stop ( ) ;
2016-07-11 20:44:57 +02:00
if ( NetworkModule . HTTP_ENABLED . get ( settings ) ) {
2017-01-16 21:06:08 +01:00
injector . getInstance ( HttpServerTransport . class ) . stop ( ) ;
2015-02-24 11:07:24 +01:00
}
injector . getInstance ( SnapshotsService . class ) . stop ( ) ;
2015-06-23 18:01:32 -04:00
injector . getInstance ( SnapshotShardsService . class ) . stop ( ) ;
2015-02-24 11:07:24 +01:00
// stop any changes happening as a result of cluster state changes
injector . getInstance ( IndicesClusterStateService . class ) . stop ( ) ;
2016-11-15 13:42:26 +00:00
// close discovery early to not react to pings anymore.
// This can confuse other nodes and delay things - mostly if we're the master and we're running tests.
injector . getInstance ( Discovery . class ) . stop ( ) ;
2015-02-24 11:07:24 +01:00
// we close indices first, so operations won't be allowed on it
injector . getInstance ( RoutingService . class ) . stop ( ) ;
injector . getInstance ( ClusterService . class ) . stop ( ) ;
2016-02-27 18:48:42 +01:00
injector . getInstance ( NodeConnectionsService . class ) . stop ( ) ;
2017-07-05 22:18:23 +02:00
nodeService . getMonitorService ( ) . stop ( ) ;
2015-02-24 11:07:24 +01:00
injector . getInstance ( GatewayService . class ) . stop ( ) ;
injector . getInstance ( SearchService . class ) . stop ( ) ;
injector . getInstance ( TransportService . class ) . stop ( ) ;
2016-07-11 13:07:22 -07:00
pluginLifecycleComponents . forEach ( LifecycleComponent : : stop ) ;
2015-02-24 11:07:24 +01:00
// we should stop this last since it waits for resources to get released
// if we had scroll searchers etc or recovery going on we wait for to finish.
injector . getInstance ( IndicesService . class ) . stop ( ) ;
logger . info ( " stopped " ) ;
return this ;
}
// During concurrent close() calls we want to make sure that all of them return after the node has completed it's shutdown cycle.
// If not, the hook that is added in Bootstrap#setup() will be useless: close() might not be executed, in case another (for example api) call
// to close() has already set some lifecycles to stopped. In this case the process will be terminated even if the first call to close() has not finished yet.
2015-02-23 17:07:46 -05:00
@Override
2016-01-29 16:18:21 +01:00
public synchronized void close ( ) throws IOException {
2015-02-24 11:07:24 +01:00
if ( lifecycle . started ( ) ) {
stop ( ) ;
}
if ( ! lifecycle . moveToClosed ( ) ) {
return ;
}
2016-08-09 13:34:23 -04:00
Logger logger = Loggers . getLogger ( Node . class , NODE_NAME_SETTING . get ( settings ) ) ;
2015-02-24 11:07:24 +01:00
logger . info ( " closing ... " ) ;
2016-01-29 16:18:21 +01:00
List < Closeable > toClose = new ArrayList < > ( ) ;
2015-02-24 11:07:24 +01:00
StopWatch stopWatch = new StopWatch ( " node_close " ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( ( ) - > stopWatch . start ( " tribe " ) ) ;
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " node_service " ) ) ;
2017-07-05 22:18:23 +02:00
toClose . add ( nodeService ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " http " ) ) ;
2016-07-11 20:44:57 +02:00
if ( NetworkModule . HTTP_ENABLED . get ( settings ) ) {
2017-01-16 21:06:08 +01:00
toClose . add ( injector . getInstance ( HttpServerTransport . class ) ) ;
2015-02-24 11:07:24 +01:00
}
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " snapshot_service " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( SnapshotsService . class ) ) ;
toClose . add ( injector . getInstance ( SnapshotShardsService . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " client " ) ) ;
2015-02-24 11:07:24 +01:00
Releasables . close ( injector . getInstance ( Client . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " indices_cluster " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( IndicesClusterStateService . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " indices " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( IndicesService . class ) ) ;
2015-05-11 11:08:48 +02:00
// close filter/fielddata caches after indices
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( IndicesStore . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " routing " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( RoutingService . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " cluster " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( ClusterService . class ) ) ;
2016-02-27 18:48:42 +01:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " node_connections_service " ) ) ;
toClose . add ( injector . getInstance ( NodeConnectionsService . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " discovery " ) ) ;
toClose . add ( injector . getInstance ( Discovery . class ) ) ;
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " monitor " ) ) ;
2017-07-05 22:18:23 +02:00
toClose . add ( nodeService . getMonitorService ( ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " gateway " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( GatewayService . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " search " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( SearchService . class ) ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " transport " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( TransportService . class ) ) ;
2015-02-24 11:07:24 +01:00
2016-07-11 13:07:22 -07:00
for ( LifecycleComponent plugin : pluginLifecycleComponents ) {
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " plugin( " + plugin . getClass ( ) . getName ( ) + " ) " ) ) ;
toClose . add ( plugin ) ;
2015-02-24 11:07:24 +01:00
}
2016-11-18 13:04:28 -05:00
toClose . addAll ( pluginsService . filterPlugins ( Plugin . class ) ) ;
2015-02-24 11:07:24 +01:00
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " script " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( injector . getInstance ( ScriptService . class ) ) ;
2015-02-24 11:07:24 +01:00
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " thread_pool " ) ) ;
2015-02-24 11:07:24 +01:00
// TODO this should really use ThreadPool.terminate()
2016-01-29 16:18:21 +01:00
toClose . add ( ( ) - > injector . getInstance ( ThreadPool . class ) . shutdown ( ) ) ;
toClose . add ( ( ) - > {
try {
injector . getInstance ( ThreadPool . class ) . awaitTermination ( 10 , TimeUnit . SECONDS ) ;
} catch ( InterruptedException e ) {
// ignore
}
} ) ;
2016-02-24 14:10:55 -08:00
toClose . add ( ( ) - > stopWatch . stop ( ) . start ( " thread_pool_force_shutdown " ) ) ;
2016-01-29 16:18:21 +01:00
toClose . add ( ( ) - > injector . getInstance ( ThreadPool . class ) . shutdownNow ( ) ) ;
toClose . add ( ( ) - > stopWatch . stop ( ) ) ;
toClose . add ( injector . getInstance ( NodeEnvironment . class ) ) ;
2016-06-01 09:43:11 +02:00
toClose . add ( injector . getInstance ( BigArrays . class ) ) ;
2015-02-24 11:07:24 +01:00
if ( logger . isTraceEnabled ( ) ) {
logger . trace ( " Close times for each service: \ n{} " , stopWatch . prettyPrint ( ) ) ;
}
2016-01-29 16:18:21 +01:00
IOUtils . close ( toClose ) ;
2015-02-24 11:07:24 +01:00
logger . info ( " closed " ) ;
}
2011-07-14 22:39:44 +03:00
/ * *
* Returns < tt > true < / tt > if the node is closed .
* /
2015-02-24 11:07:24 +01:00
public boolean isClosed ( ) {
return lifecycle . closed ( ) ;
}
public Injector injector ( ) {
return this . injector ;
}
2015-12-11 17:36:08 -08:00
2016-04-07 09:10:46 -04:00
/ * *
* Hook for validating the node after network
* services are started but before the cluster service is started
* and before the network service starts accepting incoming network
* requests .
*
2017-09-13 22:14:17 +02:00
* @param context the bootstrap context for this node
2016-04-07 09:10:46 -04:00
* @param boundTransportAddress the network addresses the node is
* bound and publishing to
* /
@SuppressWarnings ( " unused " )
2016-09-08 10:56:11 -04:00
protected void validateNodeBeforeAcceptingRequests (
2017-09-13 22:14:17 +02:00
final BootstrapContext context ,
2016-12-12 17:35:00 +01:00
final BoundTransportAddress boundTransportAddress , List < BootstrapCheck > bootstrapChecks ) throws NodeValidationException {
2016-04-07 09:10:46 -04:00
}
2015-12-11 18:08:39 -08:00
/** Writes a file to the logs dir containing the ports for the given transport type */
2015-12-11 17:36:08 -08:00
private void writePortsFile ( String type , BoundTransportAddress boundAddress ) {
Path tmpPortsFile = environment . logsFile ( ) . resolve ( type + " .ports.tmp " ) ;
try ( BufferedWriter writer = Files . newBufferedWriter ( tmpPortsFile , Charset . forName ( " UTF-8 " ) ) ) {
for ( TransportAddress address : boundAddress . boundAddresses ( ) ) {
2015-12-11 18:20:09 -08:00
InetAddress inetAddress = InetAddress . getByName ( address . getAddress ( ) ) ;
2016-04-07 15:12:50 -04:00
writer . write ( NetworkAddress . format ( new InetSocketAddress ( inetAddress , address . getPort ( ) ) ) + " \ n " ) ;
2015-12-11 17:36:08 -08:00
}
} catch ( IOException e ) {
throw new RuntimeException ( " Failed to write ports file " , e ) ;
}
Path portsFile = environment . logsFile ( ) . resolve ( type + " .ports " ) ;
try {
Files . move ( tmpPortsFile , portsFile , StandardCopyOption . ATOMIC_MOVE ) ;
} catch ( IOException e ) {
throw new RuntimeException ( " Failed to rename ports file " , e ) ;
}
}
2016-06-16 15:52:58 +02:00
2016-08-05 13:01:20 -04:00
/ * *
* The { @link PluginsService } used to build this node ' s components .
* /
protected PluginsService getPluginsService ( ) {
return pluginsService ;
}
2016-06-16 15:52:58 +02:00
/ * *
* Creates a new { @link CircuitBreakerService } based on the settings provided .
* @see # BREAKER_TYPE_KEY
* /
public static CircuitBreakerService createCircuitBreakerService ( Settings settings , ClusterSettings clusterSettings ) {
String type = BREAKER_TYPE_KEY . get ( settings ) ;
if ( type . equals ( " hierarchy " ) ) {
return new HierarchyCircuitBreakerService ( settings , clusterSettings ) ;
} else if ( type . equals ( " none " ) ) {
return new NoneCircuitBreakerService ( ) ;
} else {
throw new IllegalArgumentException ( " Unknown circuit breaker type [ " + type + " ] " ) ;
}
}
2016-06-20 13:18:19 +02:00
/ * *
* Creates a new { @link BigArrays } instance used for this node .
* This method can be overwritten by subclasses to change their { @link BigArrays } implementation for instance for testing
* /
2017-12-08 10:39:30 -07:00
BigArrays createBigArrays ( PageCacheRecycler pageCacheRecycler , CircuitBreakerService circuitBreakerService ) {
return new BigArrays ( pageCacheRecycler , circuitBreakerService ) ;
}
/ * *
* Creates a new { @link BigArrays } instance used for this node .
* This method can be overwritten by subclasses to change their { @link BigArrays } implementation for instance for testing
* /
PageCacheRecycler createPageCacheRecycler ( Settings settings ) {
return new PageCacheRecycler ( settings ) ;
2016-06-20 13:18:19 +02:00
}
2016-07-27 12:19:08 +02:00
2016-08-05 13:01:20 -04:00
/ * *
2016-09-12 22:42:55 +02:00
* Creates a new the SearchService . This method can be overwritten by tests to inject mock implementations .
2016-08-05 13:01:20 -04:00
* /
2016-09-12 22:42:55 +02:00
protected SearchService newSearchService ( ClusterService clusterService , IndicesService indicesService ,
ThreadPool threadPool , ScriptService scriptService , BigArrays bigArrays ,
2017-07-17 11:04:51 -06:00
FetchPhase fetchPhase , ResponseCollectorService responseCollectorService ) {
return new SearchService ( clusterService , indicesService , threadPool ,
scriptService , bigArrays , fetchPhase , responseCollectorService ) ;
2016-08-05 13:01:20 -04:00
}
2016-07-27 12:19:08 +02:00
/ * *
2016-07-27 13:35:58 +02:00
* Get Custom Name Resolvers list based on a Discovery Plugins list
2016-07-27 12:19:08 +02:00
* @param discoveryPlugins Discovery plugins list
* /
2016-07-27 13:35:58 +02:00
private List < NetworkService . CustomNameResolver > getCustomNameResolvers ( List < DiscoveryPlugin > discoveryPlugins ) {
2016-07-27 12:19:08 +02:00
List < NetworkService . CustomNameResolver > customNameResolvers = new ArrayList < > ( ) ;
for ( DiscoveryPlugin discoveryPlugin : discoveryPlugins ) {
NetworkService . CustomNameResolver customNameResolver = discoveryPlugin . getCustomNameResolver ( settings ) ;
if ( customNameResolver ! = null ) {
customNameResolvers . add ( customNameResolver ) ;
}
}
return customNameResolvers ;
}
2016-11-03 08:20:20 -07:00
2016-11-10 15:52:17 -08:00
/** Constructs a ClusterInfoService which may be mocked for tests. */
protected ClusterInfoService newClusterInfoService ( Settings settings , ClusterService clusterService ,
2017-07-05 22:18:23 +02:00
ThreadPool threadPool , NodeClient client , Consumer < ClusterInfo > listeners ) {
return new InternalClusterInfoService ( settings , clusterService , threadPool , client , listeners ) ;
2016-11-10 15:52:17 -08:00
}
2017-01-13 16:12:27 +01:00
private static class LocalNodeFactory implements Function < BoundTransportAddress , DiscoveryNode > {
private final SetOnce < DiscoveryNode > localNode = new SetOnce < > ( ) ;
private final String persistentNodeId ;
private final Settings settings ;
private LocalNodeFactory ( Settings settings , String persistentNodeId ) {
this . persistentNodeId = persistentNodeId ;
this . settings = settings ;
}
@Override
public DiscoveryNode apply ( BoundTransportAddress boundTransportAddress ) {
localNode . set ( DiscoveryNode . createLocal ( settings , boundTransportAddress . publishAddress ( ) , persistentNodeId ) ) ;
return localNode . get ( ) ;
}
DiscoveryNode getNode ( ) {
assert localNode . get ( ) ! = null ;
return localNode . get ( ) ;
}
}
2010-02-08 15:30:06 +02:00
}