Skip to content

Commit 2b8827d

Browse files
committed
[CORE] Remove component settings from AbstractComponent
Today we have two ways of getting a setting, either with the full settings key or with only the last part of the key where the prefix is implicit depending on the package the class is in via component settings. this is trappy as well as confusing for users and can break easily if a class is moved to a new package since the prefix then implicitly changes. This commit removes the component settings from the codebase.
1 parent e221dc2 commit 2b8827d

File tree

59 files changed

+222
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+222
-375
lines changed

src/main/java/org/elasticsearch/action/admin/cluster/node/restart/TransportNodesRestartAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public TransportNodesRestartAction(Settings settings, ClusterName clusterName, T
6161
Node node, ActionFilters actionFilters) {
6262
super(settings, NodesRestartAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters);
6363
this.node = node;
64-
disabled = componentSettings.getAsBoolean("disabled", false);
64+
disabled = this.settings.getAsBoolean("admin.cluster.node.restart.disabled", false);
6565
}
6666

6767
@Override

src/main/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdownAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public TransportNodesShutdownAction(Settings settings, TransportService transpor
6262
super(settings, NodesShutdownAction.NAME, transportService, clusterService, threadPool, actionFilters);
6363
this.node = node;
6464
this.clusterName = clusterName;
65-
this.disabled = settings.getAsBoolean("action.disable_shutdown", componentSettings.getAsBoolean("disabled", false));
66-
this.delay = componentSettings.getAsTime("delay", TimeValue.timeValueMillis(200));
65+
this.disabled = settings.getAsBoolean("action.disable_shutdown", this.settings.getAsBoolean("action.admin.cluster.node.shutdown.disabled", false));
66+
this.delay = this.settings.getAsTime("action.admin.cluster.node.shutdown.delay", TimeValue.timeValueMillis(200));
6767

6868
this.transportService.registerHandler(SHUTDOWN_NODE_ACTION_NAME, new NodeShutdownRequestHandler());
6969
}

src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public TransportBulkAction(Settings settings, ThreadPool threadPool, TransportSe
8686
this.createIndexAction = createIndexAction;
8787

8888
this.autoCreateIndex = new AutoCreateIndex(settings);
89-
this.allowIdGeneration = componentSettings.getAsBoolean("action.allow_id_generation", true);
89+
this.allowIdGeneration = this.settings.getAsBoolean("action.bulk.action.allow_id_generation", true);
9090
}
9191

9292
@Override

src/main/java/org/elasticsearch/action/search/TransportSearchAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public TransportSearchAction(Settings settings, ThreadPool threadPool,
6969
this.scanAction = scanAction;
7070
this.countAction = countAction;
7171

72-
this.optimizeSingleShard = componentSettings.getAsBoolean("optimize_single_shard", true);
72+
this.optimizeSingleShard = this.settings.getAsBoolean("action.search.optimize_single_shard", true);
7373

7474

7575
}

src/main/java/org/elasticsearch/cache/recycler/PageCacheRecycler.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
/** A recycler of fixed-size pages. */
3939
public class PageCacheRecycler extends AbstractComponent {
4040

41-
public static final String TYPE = "page.type";
42-
public static final String LIMIT_HEAP = "page.limit.heap";
43-
public static final String LIMIT_PER_THREAD = "page.limit.per_thread";
44-
public static final String WEIGHT = "page.weight";
41+
public static final String TYPE = "recycler.page.type";
42+
public static final String LIMIT_HEAP = "recycler.page.limit.heap";
43+
public static final String WEIGHT = "recycler.page.weight";
4544

4645
private final Recycler<byte[]> bytePage;
4746
private final Recycler<int[]> intPage;
@@ -79,8 +78,8 @@ private static int maxCount(long limit, long pageSize, double weight, double tot
7978
@Inject
8079
public PageCacheRecycler(Settings settings, ThreadPool threadPool) {
8180
super(settings);
82-
final Type type = Type.parse(componentSettings.get(TYPE));
83-
final long limit = componentSettings.getAsMemory(LIMIT_HEAP, "10%").bytes();
81+
final Type type = Type.parse(settings.get(TYPE));
82+
final long limit = settings.getAsMemory(LIMIT_HEAP, "10%").bytes();
8483
final int availableProcessors = EsExecutors.boundedNumberOfProcessors(settings);
8584
final int searchThreadPoolSize = maximumSearchThreadPoolSize(threadPool, settings);
8685

@@ -97,11 +96,11 @@ public PageCacheRecycler(Settings settings, ThreadPool threadPool) {
9796
// to direct ByteBuffers or sun.misc.Unsafe on a byte[] but this would have other issues
9897
// that would need to be addressed such as garbage collection of native memory or safety
9998
// of Unsafe writes.
100-
final double bytesWeight = componentSettings.getAsDouble(WEIGHT + ".bytes", 1d);
101-
final double intsWeight = componentSettings.getAsDouble(WEIGHT + ".ints", 1d);
102-
final double longsWeight = componentSettings.getAsDouble(WEIGHT + ".longs", 1d);
99+
final double bytesWeight = settings.getAsDouble(WEIGHT + ".bytes", 1d);
100+
final double intsWeight = settings.getAsDouble(WEIGHT + ".ints", 1d);
101+
final double longsWeight = settings.getAsDouble(WEIGHT + ".longs", 1d);
103102
// object pages are less useful to us so we give them a lower weight by default
104-
final double objectsWeight = componentSettings.getAsDouble(WEIGHT + ".objects", 0.1d);
103+
final double objectsWeight = settings.getAsDouble(WEIGHT + ".objects", 0.1d);
105104

106105
final double totalWeight = bytesWeight + intsWeight + longsWeight + objectsWeight;
107106

src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ public TransportClientNodesService(Settings settings, ClusterName clusterName, T
104104
this.minCompatibilityVersion = version.minimumCompatibilityVersion();
105105
this.headers = headers;
106106

107-
this.nodesSamplerInterval = componentSettings.getAsTime("nodes_sampler_interval", timeValueSeconds(5));
108-
this.pingTimeout = componentSettings.getAsTime("ping_timeout", timeValueSeconds(5)).millis();
109-
this.ignoreClusterName = componentSettings.getAsBoolean("ignore_cluster_name", false);
107+
this.nodesSamplerInterval = this.settings.getAsTime("client.transport.nodes_sampler_interval", timeValueSeconds(5));
108+
this.pingTimeout = this.settings.getAsTime("client.transport.ping_timeout", timeValueSeconds(5)).millis();
109+
this.ignoreClusterName = this.settings.getAsBoolean("client.transport.ignore_cluster_name", false);
110110

111111
if (logger.isDebugEnabled()) {
112112
logger.debug("node_sampler_interval[" + nodesSamplerInterval + "]");
113113
}
114114

115-
if (componentSettings.getAsBoolean("sniff", false)) {
115+
if (this.settings.getAsBoolean("client.transport.sniff", false)) {
116116
this.nodesSampler = new SniffNodesSampler();
117117
} else {
118118
this.nodesSampler = new SimpleNodeSampler();

src/main/java/org/elasticsearch/cluster/routing/RoutingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public RoutingService(Settings settings, ThreadPool threadPool, ClusterService c
7070
this.threadPool = threadPool;
7171
this.clusterService = clusterService;
7272
this.allocationService = allocationService;
73-
this.schedule = componentSettings.getAsTime("schedule", timeValueSeconds(10));
73+
this.schedule = settings.getAsTime("cluster.routing.schedule", timeValueSeconds(10));
7474
clusterService.addFirst(this);
7575
}
7676

src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public InternalClusterService(Settings settings, DiscoveryService discoveryServi
117117

118118
this.nodeSettingsService.setClusterService(this);
119119

120-
this.reconnectInterval = componentSettings.getAsTime("reconnect_interval", TimeValue.timeValueSeconds(10));
120+
this.reconnectInterval = this.settings.getAsTime("cluster.service.reconnect_interval", TimeValue.timeValueSeconds(10));
121121

122122
localNodeMasterListeners = new LocalNodeMasterListeners(threadPool);
123123

src/main/java/org/elasticsearch/common/blobstore/fs/FsBlobStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public FsBlobStore(Settings settings, Path path) throws IOException {
4949
super(settings);
5050
this.path = path;
5151
Files.createDirectories(path);
52-
this.bufferSizeInBytes = (int) settings.getAsBytesSize("buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).bytes();
52+
this.bufferSizeInBytes = (int) settings.getAsBytesSize("repositories.fs.buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).bytes();
5353
}
5454

5555
@Override

src/main/java/org/elasticsearch/common/blobstore/url/URLBlobStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class URLBlobStore extends AbstractComponent implements BlobStore {
5757
public URLBlobStore(Settings settings, URL path) {
5858
super(settings);
5959
this.path = path;
60-
this.bufferSizeInBytes = (int) settings.getAsBytesSize("buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).bytes();
60+
this.bufferSizeInBytes = (int) settings.getAsBytesSize("repositories.uri.buffer_size", new ByteSizeValue(100, ByteSizeUnit.KB)).bytes();
6161
}
6262

6363
/**

src/main/java/org/elasticsearch/common/component/AbstractComponent.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,26 @@
2626
/**
2727
*
2828
*/
29-
public class AbstractComponent {
29+
public abstract class AbstractComponent {
3030

3131
protected final ESLogger logger;
3232

3333
protected final Settings settings;
3434

35-
protected final Settings componentSettings;
36-
3735
public AbstractComponent(Settings settings) {
3836
this.logger = Loggers.getLogger(getClass(), settings);
3937
this.settings = settings;
40-
this.componentSettings = settings.getComponentSettings(getClass());
41-
}
42-
43-
public AbstractComponent(Settings settings, String prefixSettings) {
44-
this.logger = Loggers.getLogger(getClass(), settings);
45-
this.settings = settings;
46-
this.componentSettings = settings.getComponentSettings(prefixSettings, getClass());
4738
}
4839

4940
public AbstractComponent(Settings settings, Class customClass) {
5041
this.logger = Loggers.getLogger(customClass, settings);
5142
this.settings = settings;
52-
this.componentSettings = settings.getComponentSettings(customClass);
53-
}
54-
55-
public AbstractComponent(Settings settings, String prefixSettings, Class customClass) {
56-
this.logger = Loggers.getLogger(customClass, settings);
57-
this.settings = settings;
58-
this.componentSettings = settings.getComponentSettings(prefixSettings, customClass);
59-
}
60-
61-
public AbstractComponent(Settings settings, Class loggerClass, Class componentClass) {
62-
this.logger = Loggers.getLogger(loggerClass, settings);
63-
this.settings = settings;
64-
this.componentSettings = settings.getComponentSettings(componentClass);
65-
}
66-
67-
public AbstractComponent(Settings settings, String prefixSettings, Class loggerClass, Class componentClass) {
68-
this.logger = Loggers.getLogger(loggerClass, settings);
69-
this.settings = settings;
70-
this.componentSettings = settings.getComponentSettings(prefixSettings, componentClass);
7143
}
7244

73-
public String nodeName() {
45+
/**
46+
* Returns the nodes name from the settings or the empty string if not set.
47+
*/
48+
public final String nodeName() {
7449
return settings.get("name", "");
7550
}
7651
}

src/main/java/org/elasticsearch/common/component/AbstractLifecycleComponent.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,6 @@ protected AbstractLifecycleComponent(Settings settings, Class customClass) {
4242
super(settings, customClass);
4343
}
4444

45-
protected AbstractLifecycleComponent(Settings settings, Class loggerClass, Class componentClass) {
46-
super(settings, loggerClass, componentClass);
47-
}
48-
49-
protected AbstractLifecycleComponent(Settings settings, String prefixSettings) {
50-
super(settings, prefixSettings);
51-
}
52-
53-
protected AbstractLifecycleComponent(Settings settings, String prefixSettings, Class customClass) {
54-
super(settings, prefixSettings, customClass);
55-
}
56-
57-
protected AbstractLifecycleComponent(Settings settings, String prefixSettings, Class loggerClass, Class componentClass) {
58-
super(settings, prefixSettings, loggerClass, componentClass);
59-
}
60-
6145
@Override
6246
public Lifecycle.State lifecycleState() {
6347
return this.lifecycle.state();

src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,6 @@ private Object convertMapsToArrays(Map<String, Object> map) {
188188
return map;
189189
}
190190

191-
192-
@Override
193-
public Settings getComponentSettings(Class component) {
194-
if (component.getName().startsWith("org.elasticsearch")) {
195-
return getComponentSettings("org.elasticsearch", component);
196-
}
197-
// not starting with org.elasticsearch, just remove the first package part (probably org/net/com)
198-
return getComponentSettings(component.getName().substring(0, component.getName().indexOf('.')), component);
199-
}
200-
201-
@Override
202-
public Settings getComponentSettings(String prefix, Class component) {
203-
String type = component.getName();
204-
if (!type.startsWith(prefix)) {
205-
throw new SettingsException("Component [" + type + "] does not start with prefix [" + prefix + "]");
206-
}
207-
String settingPrefix = type.substring(prefix.length() + 1); // 1 for the '.'
208-
settingPrefix = settingPrefix.substring(0, settingPrefix.length() - component.getSimpleName().length()); // remove the simple class name (keep the dot)
209-
return getByPrefix(settingPrefix);
210-
}
211-
212191
@Override
213192
public Settings getByPrefix(String prefix) {
214193
Builder builder = new Builder();

src/main/java/org/elasticsearch/common/settings/Settings.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@
4141
*/
4242
public interface Settings extends ToXContent {
4343

44-
/**
45-
* Component settings for a specific component. Returns all the settings for the given class, where the
46-
* FQN of the class is used, without the <tt>org.elasticsearch<tt> prefix. If there is no <tt>org.elasticsearch</tt>
47-
* prefix, then the prefix used is the first part of the package name (<tt>org</tt> / <tt>com</tt> / ...)
48-
*/
49-
Settings getComponentSettings(Class component);
50-
51-
/**
52-
* Component settings for a specific component. Returns all the settings for the given class, where the
53-
* FQN of the class is used, without provided prefix.
54-
*/
55-
Settings getComponentSettings(String prefix, Class component);
56-
5744
/**
5845
* A settings that are filtered (and key is removed) with the specified prefix.
5946
*/

src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.cluster.metadata.IndexMetaData;
3232
import org.elasticsearch.cluster.metadata.MetaData;
3333
import org.elasticsearch.cluster.node.DiscoveryNode;
34-
import org.elasticsearch.cluster.node.DiscoveryNodeService;
3534
import org.elasticsearch.cluster.node.DiscoveryNodes;
3635
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3736
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
@@ -103,7 +102,6 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
103102
private final ClusterService clusterService;
104103
private AllocationService allocationService;
105104
private final ClusterName clusterName;
106-
private final DiscoveryNodeService discoveryNodeService;
107105
private final DiscoverySettings discoverySettings;
108106
private final ZenPingService pingService;
109107
private final MasterFaultDetection masterFD;
@@ -150,20 +148,17 @@ public class ZenDiscovery extends AbstractLifecycleComponent<Discovery> implemen
150148
@Inject
151149
public ZenDiscovery(Settings settings, ClusterName clusterName, ThreadPool threadPool,
152150
TransportService transportService, final ClusterService clusterService, NodeSettingsService nodeSettingsService,
153-
DiscoveryNodeService discoveryNodeService, ZenPingService pingService, ElectMasterService electMasterService,
151+
ZenPingService pingService, ElectMasterService electMasterService,
154152
DiscoverySettings discoverySettings, @ClusterDynamicSettings DynamicSettings dynamicSettings) {
155153
super(settings);
156154
this.clusterName = clusterName;
157155
this.clusterService = clusterService;
158156
this.transportService = transportService;
159-
this.discoveryNodeService = discoveryNodeService;
160157
this.discoverySettings = discoverySettings;
161158
this.pingService = pingService;
162159
this.electMaster = electMasterService;
163-
164-
// keep using componentSettings for BWC, in case this class gets extended.
165-
TimeValue pingTimeout = componentSettings.getAsTime("initial_ping_timeout", timeValueSeconds(3));
166-
pingTimeout = componentSettings.getAsTime("ping_timeout", pingTimeout);
160+
TimeValue pingTimeout = this.settings.getAsTime("discovery.zen.initial_ping_timeout", timeValueSeconds(3));
161+
pingTimeout = this.settings.getAsTime("discovery.zen.ping_timeout", pingTimeout);
167162
pingTimeout = settings.getAsTime("discovery.zen.ping_timeout", pingTimeout);
168163
this.pingTimeout = settings.getAsTime(SETTING_PING_TIMEOUT, pingTimeout);
169164

src/main/java/org/elasticsearch/discovery/zen/ping/ZenPingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public ZenPingService(Settings settings, ThreadPool threadPool, TransportService
5555
Version version, ElectMasterService electMasterService, @Nullable Set<UnicastHostsProvider> unicastHostsProviders) {
5656
super(settings);
5757
ImmutableList.Builder<ZenPing> zenPingsBuilder = ImmutableList.builder();
58-
if (componentSettings.getAsBoolean("multicast.enabled", true)) {
58+
if (this.settings.getAsBoolean("discovery.zen.ping.multicast.enabled", true)) {
5959
zenPingsBuilder.add(new MulticastZenPing(settings, threadPool, transportService, clusterName, networkService, version));
6060
}
6161
// always add the unicast hosts, so it will be able to receive unicast requests even when working in multicast

src/main/java/org/elasticsearch/discovery/zen/ping/multicast/MulticastZenPing.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public MulticastZenPing(Settings settings, ThreadPool threadPool, TransportServi
9797
this.networkService = networkService;
9898
this.version = version;
9999

100-
this.address = componentSettings.get("address");
101-
this.port = componentSettings.getAsInt("port", 54328);
102-
this.group = componentSettings.get("group", "224.2.2.4");
103-
this.bufferSize = componentSettings.getAsInt("buffer_size", 2048);
104-
this.ttl = componentSettings.getAsInt("ttl", 3);
100+
this.address = this.settings.get("discovery.zen.ping.multicast.address");
101+
this.port = this.settings.getAsInt("discovery.zen.ping.multicast.port", 54328);
102+
this.group = this.settings.get("discovery.zen.ping.multicast.group", "224.2.2.4");
103+
this.bufferSize = this.settings.getAsInt("discovery.zen.ping.multicast.buffer_size", 2048);
104+
this.ttl = this.settings.getAsInt("discovery.zen.ping.multicast.ttl", 3);
105105

106-
this.pingEnabled = componentSettings.getAsBoolean("ping.enabled", true);
106+
this.pingEnabled = this.settings.getAsBoolean("discovery.zen.ping.multicast.ping.enabled", true);
107107

108108
logger.debug("using group [{}], with port [{}], ttl [{}], and address [{}]", group, port, ttl, address);
109109

@@ -123,7 +123,7 @@ protected void doStart() throws ElasticsearchException {
123123
try {
124124
// we know OSX has bugs in the JVM when creating multiple instances of multicast sockets
125125
// causing for "socket close" exceptions when receive and/or crashes
126-
boolean shared = componentSettings.getAsBoolean("shared", Constants.MAC_OS_X);
126+
boolean shared = settings.getAsBoolean("discovery.zen.ping.multicast.shared", Constants.MAC_OS_X);
127127
multicastChannel = MulticastChannel.getChannel(nodeName(), shared,
128128
new MulticastChannel.Config(port, group, bufferSize, ttl, networkService.resolvePublishHostAddress(address)),
129129
new Receiver());

src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public UnicastZenPing(Settings settings, ThreadPool threadPool, TransportService
112112
}
113113
}
114114

115-
this.concurrentConnects = componentSettings.getAsInt("concurrent_connects", 10);
116-
String[] hostArr = componentSettings.getAsArray("hosts");
115+
this.concurrentConnects = this.settings.getAsInt("discovery.zen.ping.unicast.concurrent_connects", 10);
116+
String[] hostArr = this.settings.getAsArray("discovery.zen.ping.unicast.hosts");
117117
// trim the hosts
118118
for (int i = 0; i < hostArr.length; i++) {
119119
hostArr[i] = hostArr[i].trim();

src/main/java/org/elasticsearch/gateway/GatewayAllocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public GatewayAllocator(Settings settings,
8080
this.listGatewayStartedShards = listGatewayStartedShards;
8181
this.listShardStoreMetaData = listShardStoreMetaData;
8282

83-
this.listTimeout = componentSettings.getAsTime("list_timeout", settings.getAsTime("gateway.local.list_timeout", TimeValue.timeValueSeconds(30)));
84-
this.initialShards = componentSettings.get("initial_shards", settings.get("gateway.local.initial_shards", "quorum"));
83+
this.listTimeout = settings.getAsTime("gateway.list_timeout", settings.getAsTime("gateway.local.list_timeout", TimeValue.timeValueSeconds(30)));
84+
this.initialShards = settings.get("gateway.initial_shards", settings.get("gateway.local.initial_shards", "quorum"));
8585

8686
logger.debug("using initial_shards [{}], list_timeout [{}]", initialShards, listTimeout);
8787
}

0 commit comments

Comments
 (0)