Skip to content

Commit cbce130

Browse files
committed
Merge branch 'master' into disable-package-distribution-integ-tests
* master: Fix index with unknown setting test Remove internal channel tracking in transports (elastic#27711) Improve error msg when a field name contains only white spaces (elastic#27709) Do not open indices with broken settings Set ACK timeout on indices service test Implement byte array reusage in `NioTransport` (elastic#27696) [TEST] Remove leftover ES temp directories before Vagrant tests (elastic#27722) Cleanup split strings by comma method Remove unused import from AliasResolveRoutingIT Add read timeouts to http module (elastic#27713) Fix routing with leading or trailing whitespace remove await fix from FullClusterRestartIT.testRecovery Add missing 's' to tmpdir name (elastic#27721) [Issue-27716]: CONTRIBUTING.md IntelliJ configurations settings are confusing. (elastic#27717) [TEST] Now actually wait for merges
2 parents 8bedef4 + 8c8b1dc commit cbce130

File tree

80 files changed

+749
-418
lines changed

Some content is hidden

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

80 files changed

+749
-418
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ Alternatively, `idea.no.launcher=true` can be set in the
119119
[`idea.properties`](https://www.jetbrains.com/help/idea/file-idea-properties.html)
120120
file which can be accessed under Help > Edit Custom Properties (this will require a
121121
restart of IDEA). For IDEA 2017.3 and above, in addition to the JVM option, you will need to go to
122-
`Run->Edit Configurations...` and change the value for the `Shorten command line` setting from
122+
`Run->Edit Configurations->...->Defaults->JUnit` and change the value for the `Shorten command line` setting from
123123
`user-local default: none` to `classpath file`. You may also need to [remove `ant-javafx.jar` from your
124124
classpath](https://github.com/elastic/elasticsearch/issues/14348) if that is
125125
reported as a source of jar hell.
126126

127+
To run an instance of elasticsearch from the source code run `gradle run`
128+
127129
The Elasticsearch codebase makes heavy use of Java `assert`s and the
128130
test runner requires that assertions be enabled within the JVM. This
129131
can be accomplished by passing the flag `-ea` to the JVM on startup.

Vagrantfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,9 @@ Defaults env_keep += "BATS_ARCHIVES"
307307
SUDOERS_VARS
308308
chmod 0440 /etc/sudoers.d/elasticsearch_vars
309309
SHELL
310+
# This prevents leftovers from previous tests using the
311+
# same VM from messing up the current test
312+
config.vm.provision "clean_tmp", run: "always", type: "shell", inline: <<-SHELL
313+
rm -rf /tmp/elasticsearch*
314+
SHELL
310315
end

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@
658658
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]recovery[/\\]RelocationIT.java" checks="LineLength" />
659659
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]recovery[/\\]TruncatedRecoveryIT.java" checks="LineLength" />
660660
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]rest[/\\]BytesRestResponseTests.java" checks="LineLength" />
661-
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]routing[/\\]AliasResolveRoutingIT.java" checks="LineLength" />
662661
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]routing[/\\]AliasRoutingIT.java" checks="LineLength" />
663662
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]routing[/\\]SimpleRoutingIT.java" checks="LineLength" />
664663
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]FileScriptTests.java" checks="LineLength" />

core/src/main/java/org/elasticsearch/client/transport/TransportClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.common.transport.TransportAddress;
4444
import org.elasticsearch.common.unit.TimeValue;
4545
import org.elasticsearch.common.util.BigArrays;
46+
import org.elasticsearch.common.util.PageCacheRecycler;
4647
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4748
import org.elasticsearch.indices.breaker.CircuitBreakerService;
4849
import org.elasticsearch.node.InternalSettingsPreparer;
@@ -169,11 +170,12 @@ private static ClientTemplate buildTemplate(Settings providedSettings, Settings
169170
CircuitBreakerService circuitBreakerService = Node.createCircuitBreakerService(settingsModule.getSettings(),
170171
settingsModule.getClusterSettings());
171172
resourcesToClose.add(circuitBreakerService);
172-
BigArrays bigArrays = new BigArrays(settings, circuitBreakerService);
173+
PageCacheRecycler pageCacheRecycler = new PageCacheRecycler(settings);
174+
BigArrays bigArrays = new BigArrays(pageCacheRecycler, circuitBreakerService);
173175
resourcesToClose.add(bigArrays);
174176
modules.add(settingsModule);
175177
NetworkModule networkModule = new NetworkModule(settings, true, pluginsService.filterPlugins(NetworkPlugin.class), threadPool,
176-
bigArrays, circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService, null);
178+
bigArrays, pageCacheRecycler, circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService, null);
177179
final Transport transport = networkModule.getTransportSupplier().get();
178180
final TransportService transportService = new TransportService(settings, transport, threadPool,
179181
networkModule.getTransportInterceptor(),

core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.common.compress.CompressedXContent;
2828
import org.elasticsearch.common.io.stream.StreamInput;
2929
import org.elasticsearch.common.io.stream.StreamOutput;
30+
import org.elasticsearch.common.util.set.Sets;
3031
import org.elasticsearch.common.xcontent.ToXContent;
3132
import org.elasticsearch.common.xcontent.XContentBuilder;
3233
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -58,7 +59,7 @@ private AliasMetaData(String alias, CompressedXContent filter, String indexRouti
5859
this.indexRouting = indexRouting;
5960
this.searchRouting = searchRouting;
6061
if (searchRouting != null) {
61-
searchRoutingValues = Collections.unmodifiableSet(Strings.splitStringByCommaToSet(searchRouting));
62+
searchRoutingValues = Collections.unmodifiableSet(Sets.newHashSet(Strings.splitStringByCommaToArray(searchRouting)));
6263
} else {
6364
searchRoutingValues = emptySet();
6465
}
@@ -186,7 +187,7 @@ public AliasMetaData(StreamInput in) throws IOException {
186187
}
187188
if (in.readBoolean()) {
188189
searchRouting = in.readString();
189-
searchRoutingValues = Collections.unmodifiableSet(Strings.splitStringByCommaToSet(searchRouting));
190+
searchRoutingValues = Collections.unmodifiableSet(Sets.newHashSet(Strings.splitStringByCommaToArray(searchRouting)));
190191
} else {
191192
searchRouting = null;
192193
searchRoutingValues = emptySet();

core/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
3232
import org.elasticsearch.common.regex.Regex;
3333
import org.elasticsearch.common.settings.Settings;
34+
import org.elasticsearch.common.util.set.Sets;
3435
import org.elasticsearch.index.Index;
3536
import org.elasticsearch.index.IndexNotFoundException;
3637
import org.elasticsearch.indices.IndexClosedException;
@@ -358,6 +359,7 @@ public Map<String, Set<String>> resolveSearchRouting(ClusterState state, @Nullab
358359
resolvedExpressions = expressionResolver.resolve(context, resolvedExpressions);
359360
}
360361

362+
// TODO: it appears that this can never be true?
361363
if (isAllIndices(resolvedExpressions)) {
362364
return resolveSearchRoutingAllIndices(state.metaData(), routing);
363365
}
@@ -367,7 +369,7 @@ public Map<String, Set<String>> resolveSearchRouting(ClusterState state, @Nullab
367369
// List of indices that don't require any routing
368370
Set<String> norouting = new HashSet<>();
369371
if (routing != null) {
370-
paramRouting = Strings.splitStringByCommaToSet(routing);
372+
paramRouting = Sets.newHashSet(Strings.splitStringByCommaToArray(routing));
371373
}
372374

373375
for (String expression : resolvedExpressions) {
@@ -442,9 +444,9 @@ public Map<String, Set<String>> resolveSearchRouting(ClusterState state, @Nullab
442444
/**
443445
* Sets the same routing for all indices
444446
*/
445-
private Map<String, Set<String>> resolveSearchRoutingAllIndices(MetaData metaData, String routing) {
447+
public Map<String, Set<String>> resolveSearchRoutingAllIndices(MetaData metaData, String routing) {
446448
if (routing != null) {
447-
Set<String> r = Strings.splitStringByCommaToSet(routing);
449+
Set<String> r = Sets.newHashSet(Strings.splitStringByCommaToArray(routing));
448450
Map<String, Set<String>> routings = new HashMap<>();
449451
String[] concreteIndices = metaData.getConcreteAllIndices();
450452
for (String index : concreteIndices) {

core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexUpgradeService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public MetaDataIndexUpgradeService(Settings settings, NamedXContentRegistry xCon
8282
public IndexMetaData upgradeIndexMetaData(IndexMetaData indexMetaData, Version minimumIndexCompatibilityVersion) {
8383
// Throws an exception if there are too-old segments:
8484
if (isUpgraded(indexMetaData)) {
85-
assert indexMetaData == archiveBrokenIndexSettings(indexMetaData) : "all settings must have been upgraded before";
8685
return indexMetaData;
8786
}
8887
checkSupportedVersion(indexMetaData, minimumIndexCompatibilityVersion);

core/src/main/java/org/elasticsearch/common/Strings.java

Lines changed: 36 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.Set;
4242
import java.util.StringTokenizer;
4343
import java.util.TreeSet;
44+
import java.util.function.Supplier;
4445

4546
import static java.util.Collections.unmodifiableSet;
4647
import static org.elasticsearch.common.util.set.Sets.newHashSet;
@@ -410,62 +411,27 @@ public static String[] toStringArray(Collection<String> collection) {
410411
return collection.toArray(new String[collection.size()]);
411412
}
412413

413-
public static Set<String> splitStringByCommaToSet(final String s) {
414-
return splitStringToSet(s, ',');
415-
}
416-
417-
public static String[] splitStringByCommaToArray(final String s) {
418-
if (s == null || s.isEmpty()) return Strings.EMPTY_ARRAY;
419-
else return s.split(",");
414+
/**
415+
* Tokenize the specified string by commas to a set, trimming whitespace and ignoring empty tokens.
416+
*
417+
* @param s the string to tokenize
418+
* @return the set of tokens
419+
*/
420+
public static Set<String> tokenizeByCommaToSet(final String s) {
421+
if (s == null) return Collections.emptySet();
422+
return tokenizeToCollection(s, ",", HashSet::new);
420423
}
421424

422425
/**
423-
* A convenience method for splitting a delimited string into
424-
* a set and trimming leading and trailing whitespace from all
425-
* split strings.
426+
* Split the specified string by commas to an array.
426427
*
427428
* @param s the string to split
428-
* @param c the delimiter to split on
429-
* @return the set of split strings
430-
*/
431-
public static Set<String> splitStringToSet(final String s, final char c) {
432-
if (s == null || s.isEmpty()) {
433-
return Collections.emptySet();
434-
}
435-
final char[] chars = s.toCharArray();
436-
int count = 1;
437-
for (final char x : chars) {
438-
if (x == c) {
439-
count++;
440-
}
441-
}
442-
final Set<String> result = new HashSet<>(count);
443-
final int len = chars.length;
444-
int start = 0; // starting index in chars of the current substring.
445-
int pos = 0; // current index in chars.
446-
int end = 0; // the position of the end of the current token
447-
for (; pos < len; pos++) {
448-
if (chars[pos] == c) {
449-
int size = end - start;
450-
if (size > 0) { // only add non empty strings
451-
result.add(new String(chars, start, size));
452-
}
453-
start = pos + 1;
454-
end = start;
455-
} else if (Character.isWhitespace(chars[pos])) {
456-
if (start == pos) {
457-
// skip over preceding whitespace
458-
start++;
459-
}
460-
} else {
461-
end = pos + 1;
462-
}
463-
}
464-
int size = end - start;
465-
if (size > 0) {
466-
result.add(new String(chars, start, size));
467-
}
468-
return result;
429+
* @return the array of split values
430+
* @see String#split(String)
431+
*/
432+
public static String[] splitStringByCommaToArray(final String s) {
433+
if (s == null || s.isEmpty()) return Strings.EMPTY_ARRAY;
434+
else return s.split(",");
469435
}
470436

471437
/**
@@ -499,56 +465,43 @@ public static String[] split(String toSplit, String delimiter) {
499465
* tokens. A delimiter is always a single character; for multi-character
500466
* delimiters, consider using <code>delimitedListToStringArray</code>
501467
*
502-
* @param str the String to tokenize
468+
* @param s the String to tokenize
503469
* @param delimiters the delimiter characters, assembled as String
504470
* (each of those characters is individually considered as delimiter).
505471
* @return an array of the tokens
506472
* @see java.util.StringTokenizer
507473
* @see java.lang.String#trim()
508474
* @see #delimitedListToStringArray
509475
*/
510-
public static String[] tokenizeToStringArray(String str, String delimiters) {
511-
return tokenizeToStringArray(str, delimiters, true, true);
476+
public static String[] tokenizeToStringArray(final String s, final String delimiters) {
477+
return toStringArray(tokenizeToCollection(s, delimiters, ArrayList::new));
512478
}
513479

514480
/**
515-
* Tokenize the given String into a String array via a StringTokenizer.
516-
* <p>The given delimiters string is supposed to consist of any number of
517-
* delimiter characters. Each of those characters can be used to separate
518-
* tokens. A delimiter is always a single character; for multi-character
519-
* delimiters, consider using <code>delimitedListToStringArray</code>
481+
* Tokenizes the specified string to a collection using the specified delimiters as the token delimiters. This method trims whitespace
482+
* from tokens and ignores empty tokens.
520483
*
521-
* @param str the String to tokenize
522-
* @param delimiters the delimiter characters, assembled as String
523-
* (each of those characters is individually considered as delimiter)
524-
* @param trimTokens trim the tokens via String's <code>trim</code>
525-
* @param ignoreEmptyTokens omit empty tokens from the result array
526-
* (only applies to tokens that are empty after trimming; StringTokenizer
527-
* will not consider subsequent delimiters as token in the first place).
528-
* @return an array of the tokens (<code>null</code> if the input String
529-
* was <code>null</code>)
484+
* @param s the string to tokenize.
485+
* @param delimiters the token delimiters
486+
* @param supplier a collection supplier
487+
* @param <T> the type of the collection
488+
* @return the tokens
530489
* @see java.util.StringTokenizer
531-
* @see java.lang.String#trim()
532-
* @see #delimitedListToStringArray
533490
*/
534-
public static String[] tokenizeToStringArray(
535-
String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) {
536-
537-
if (str == null) {
491+
private static <T extends Collection<String>> T tokenizeToCollection(
492+
final String s, final String delimiters, final Supplier<T> supplier) {
493+
if (s == null) {
538494
return null;
539495
}
540-
StringTokenizer st = new StringTokenizer(str, delimiters);
541-
List<String> tokens = new ArrayList<>();
542-
while (st.hasMoreTokens()) {
543-
String token = st.nextToken();
544-
if (trimTokens) {
545-
token = token.trim();
546-
}
547-
if (!ignoreEmptyTokens || token.length() > 0) {
496+
final StringTokenizer tokenizer = new StringTokenizer(s, delimiters);
497+
final T tokens = supplier.get();
498+
while (tokenizer.hasMoreTokens()) {
499+
final String token = tokenizer.nextToken().trim();
500+
if (token.length() > 0) {
548501
tokens.add(token);
549502
}
550503
}
551-
return toStringArray(tokens);
504+
return tokens;
552505
}
553506

554507
/**

core/src/main/java/org/elasticsearch/common/network/NetworkModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.elasticsearch.common.settings.Setting.Property;
3535
import org.elasticsearch.common.settings.Settings;
3636
import org.elasticsearch.common.util.BigArrays;
37+
import org.elasticsearch.common.util.PageCacheRecycler;
3738
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3839
import org.elasticsearch.common.xcontent.XContentParser;
3940
import org.elasticsearch.http.HttpServerTransport;
@@ -107,6 +108,7 @@ public final class NetworkModule {
107108
*/
108109
public NetworkModule(Settings settings, boolean transportClient, List<NetworkPlugin> plugins, ThreadPool threadPool,
109110
BigArrays bigArrays,
111+
PageCacheRecycler pageCacheRecycler,
110112
CircuitBreakerService circuitBreakerService,
111113
NamedWriteableRegistry namedWriteableRegistry,
112114
NamedXContentRegistry xContentRegistry,
@@ -121,9 +123,9 @@ public NetworkModule(Settings settings, boolean transportClient, List<NetworkPlu
121123
registerHttpTransport(entry.getKey(), entry.getValue());
122124
}
123125
}
124-
Map<String, Supplier<Transport>> httpTransportFactory = plugin.getTransports(settings, threadPool, bigArrays,
126+
Map<String, Supplier<Transport>> transportFactory = plugin.getTransports(settings, threadPool, bigArrays, pageCacheRecycler,
125127
circuitBreakerService, namedWriteableRegistry, networkService);
126-
for (Map.Entry<String, Supplier<Transport>> entry : httpTransportFactory.entrySet()) {
128+
for (Map.Entry<String, Supplier<Transport>> entry : transportFactory.entrySet()) {
127129
registerTransport(entry.getKey(), entry.getValue());
128130
}
129131
List<TransportInterceptor> transportInterceptors = plugin.getTransportInterceptors(namedWriteableRegistry,

core/src/main/java/org/elasticsearch/common/settings/AbstractScopedSettings.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,41 @@ public synchronized <T> void addSettingsUpdateConsumer(Setting<T> setting, Consu
264264
}
265265

266266
/**
267-
* Validates that all given settings are registered and valid
268-
* @param settings the settings to validate
269-
* @param validateDependencies if <code>true</code> settings dependencies are validated as well.
267+
* Validates that all settings are registered and valid.
268+
*
269+
* @param settings the settings to validate
270+
* @param validateDependencies true if dependent settings should be validated
270271
* @see Setting#getSettingsDependencies(String)
271272
*/
272-
public final void validate(Settings settings, boolean validateDependencies) {
273-
List<RuntimeException> exceptions = new ArrayList<>();
274-
for (String key : settings.keySet()) { // settings iterate in deterministic fashion
273+
public final void validate(final Settings settings, final boolean validateDependencies) {
274+
validate(settings, validateDependencies, false, false);
275+
}
276+
277+
/**
278+
* Validates that all settings are registered and valid.
279+
*
280+
* @param settings the settings
281+
* @param validateDependencies true if dependent settings should be validated
282+
* @param ignorePrivateSettings true if private settings should be ignored during validation
283+
* @param ignoreArchivedSettings true if archived settings should be ignored during validation
284+
* @see Setting#getSettingsDependencies(String)
285+
*/
286+
public final void validate(
287+
final Settings settings,
288+
final boolean validateDependencies,
289+
final boolean ignorePrivateSettings,
290+
final boolean ignoreArchivedSettings) {
291+
final List<RuntimeException> exceptions = new ArrayList<>();
292+
for (final String key : settings.keySet()) { // settings iterate in deterministic fashion
293+
if (isPrivateSetting(key) && ignorePrivateSettings) {
294+
continue;
295+
}
296+
if (key.startsWith(ARCHIVED_SETTINGS_PREFIX) && ignoreArchivedSettings) {
297+
continue;
298+
}
275299
try {
276300
validate(key, settings, validateDependencies);
277-
} catch (RuntimeException ex) {
301+
} catch (final RuntimeException ex) {
278302
exceptions.add(ex);
279303
}
280304
}

core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
169169

170170
)));
171171

172-
public static final IndexScopedSettings DEFAULT_SCOPED_SETTINGS = new IndexScopedSettings(Settings.EMPTY,
173-
BUILT_IN_INDEX_SETTINGS);
172+
public static final IndexScopedSettings DEFAULT_SCOPED_SETTINGS = new IndexScopedSettings(Settings.EMPTY, BUILT_IN_INDEX_SETTINGS);
174173

175174
public IndexScopedSettings(Settings settings, Set<Setting<?>> settingsSet) {
176175
super(settings, settingsSet, Property.IndexScope);

0 commit comments

Comments
 (0)