Skip to content

Commit cdf80a8

Browse files
committed
Merge branch 'xdcr' into engine-factory-provider
* xdcr: Maybe die before trying to log cause Log cause when a write and flush fails Die if write listener fails due to fatal error RecoveryIT.testHistoryUUIDIsGenerated should reduce unassigned shards delay instead of ensure green. Replace group map settings with affix setting (#26819) Fix references to vm.max_map_count in Docker docs Add more instructions about jar hell (#26837) Forbid negative values for index.unassigned.node_left.delayed_timeout (#26828) Nitpicking typos in comments (#26831) MetaData Builder doesn't properly prevent an alias with the same name as an index (#26804)
2 parents 6e2f3ec + 5869a74 commit cdf80a8

File tree

29 files changed

+366
-146
lines changed

29 files changed

+366
-146
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ then `File->New Project From Existing Sources`. Point to the root of
106106
the source directory, select
107107
`Import project from external model->Gradle`, enable
108108
`Use auto-import`. Additionally, in order to run tests directly from
109-
IDEA 2017.2 and above it is required to disable IDEA run launcher,
110-
which can be achieved by adding `-Didea.no.launcher=true`
111-
[JVM option](https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties)
109+
IDEA 2017.2 and above it is required to disable IDEA run launcher to avoid
110+
finding yourself in "jar hell", which can be achieved by adding the
111+
`-Didea.no.launcher=true` [JVM
112+
option](https://intellij-support.jetbrains.com/hc/en-us/articles/206544869-Configuring-JVM-options-and-platform-properties)
113+
or by adding `idea.no.launcher=true` to the
114+
`idea.properties`[https://www.jetbrains.com/help/idea/file-idea-properties.html]
115+
file which can be accessed under Help > Edit Custom Properties within IDEA. You
116+
may also need to [remove `ant-javafx.jar` from your
117+
classpath][https://github.com/elastic/elasticsearch/issues/14348] if that is
118+
reported as a source of jar hell.
112119

113120
The Elasticsearch codebase makes heavy use of Java `assert`s and the
114121
test runner requires that assertions be enabled within the JVM. This

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,18 @@ static Setting<Integer> buildNumberOfShardsSetting() {
240240
public static final String INDEX_ROUTING_REQUIRE_GROUP_PREFIX = "index.routing.allocation.require";
241241
public static final String INDEX_ROUTING_INCLUDE_GROUP_PREFIX = "index.routing.allocation.include";
242242
public static final String INDEX_ROUTING_EXCLUDE_GROUP_PREFIX = "index.routing.allocation.exclude";
243-
public static final Setting<Settings> INDEX_ROUTING_REQUIRE_GROUP_SETTING =
244-
Setting.groupSetting(INDEX_ROUTING_REQUIRE_GROUP_PREFIX + ".", IP_VALIDATOR, Property.Dynamic, Property.IndexScope);
245-
public static final Setting<Settings> INDEX_ROUTING_INCLUDE_GROUP_SETTING =
246-
Setting.groupSetting(INDEX_ROUTING_INCLUDE_GROUP_PREFIX + ".", IP_VALIDATOR, Property.Dynamic, Property.IndexScope);
247-
public static final Setting<Settings> INDEX_ROUTING_EXCLUDE_GROUP_SETTING =
248-
Setting.groupSetting(INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + ".", IP_VALIDATOR, Property.Dynamic, Property.IndexScope);
249-
public static final Setting<Settings> INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING =
250-
Setting.groupSetting("index.routing.allocation.initial_recovery."); // this is only setable internally not a registered setting!!
243+
public static final Setting.AffixSetting<String> INDEX_ROUTING_REQUIRE_GROUP_SETTING =
244+
Setting.prefixKeySetting(INDEX_ROUTING_REQUIRE_GROUP_PREFIX + ".", (key) ->
245+
Setting.simpleString(key, (value, map) -> IP_VALIDATOR.accept(key, value), Property.Dynamic, Property.IndexScope));
246+
public static final Setting.AffixSetting<String> INDEX_ROUTING_INCLUDE_GROUP_SETTING =
247+
Setting.prefixKeySetting(INDEX_ROUTING_INCLUDE_GROUP_PREFIX + ".", (key) ->
248+
Setting.simpleString(key, (value, map) -> IP_VALIDATOR.accept(key, value), Property.Dynamic, Property.IndexScope));
249+
public static final Setting.AffixSetting<String> INDEX_ROUTING_EXCLUDE_GROUP_SETTING =
250+
Setting.prefixKeySetting(INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + ".", (key) ->
251+
Setting.simpleString(key, (value, map) -> IP_VALIDATOR.accept(key, value), Property.Dynamic, Property.IndexScope));
252+
public static final Setting.AffixSetting<String> INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING =
253+
Setting.prefixKeySetting("index.routing.allocation.initial_recovery.", key -> Setting.simpleString(key));
254+
// this is only setable internally not a registered setting!!
251255

252256
/**
253257
* The number of active shard copies to check for before proceeding with a write operation.
@@ -1012,28 +1016,28 @@ public IndexMetaData build() {
10121016
filledInSyncAllocationIds.put(i, Collections.emptySet());
10131017
}
10141018
}
1015-
final Map<String, String> requireMap = INDEX_ROUTING_REQUIRE_GROUP_SETTING.get(settings).getAsMap();
1019+
final Map<String, String> requireMap = INDEX_ROUTING_REQUIRE_GROUP_SETTING.getAsMap(settings);
10161020
final DiscoveryNodeFilters requireFilters;
10171021
if (requireMap.isEmpty()) {
10181022
requireFilters = null;
10191023
} else {
10201024
requireFilters = DiscoveryNodeFilters.buildFromKeyValue(AND, requireMap);
10211025
}
1022-
Map<String, String> includeMap = INDEX_ROUTING_INCLUDE_GROUP_SETTING.get(settings).getAsMap();
1026+
Map<String, String> includeMap = INDEX_ROUTING_INCLUDE_GROUP_SETTING.getAsMap(settings);
10231027
final DiscoveryNodeFilters includeFilters;
10241028
if (includeMap.isEmpty()) {
10251029
includeFilters = null;
10261030
} else {
10271031
includeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, includeMap);
10281032
}
1029-
Map<String, String> excludeMap = INDEX_ROUTING_EXCLUDE_GROUP_SETTING.get(settings).getAsMap();
1033+
Map<String, String> excludeMap = INDEX_ROUTING_EXCLUDE_GROUP_SETTING.getAsMap(settings);
10301034
final DiscoveryNodeFilters excludeFilters;
10311035
if (excludeMap.isEmpty()) {
10321036
excludeFilters = null;
10331037
} else {
10341038
excludeFilters = DiscoveryNodeFilters.buildFromKeyValue(OR, excludeMap);
10351039
}
1036-
Map<String, String> initialRecoveryMap = INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING.get(settings).getAsMap();
1040+
Map<String, String> initialRecoveryMap = INDEX_ROUTING_INITIAL_RECOVERY_GROUP_SETTING.getAsMap(settings);
10371041
final DiscoveryNodeFilters initialRecoveryFilters;
10381042
if (initialRecoveryMap.isEmpty()) {
10391043
initialRecoveryFilters = null;

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

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.carrotsearch.hppc.ObjectHashSet;
2323
import com.carrotsearch.hppc.cursors.ObjectCursor;
2424
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
25-
2625
import org.apache.logging.log4j.Logger;
2726
import org.apache.lucene.util.CollectionUtil;
2827
import org.elasticsearch.cluster.Diff;
@@ -33,6 +32,7 @@
3332
import org.elasticsearch.cluster.block.ClusterBlock;
3433
import org.elasticsearch.cluster.block.ClusterBlockLevel;
3534
import org.elasticsearch.common.Nullable;
35+
import org.elasticsearch.common.Strings;
3636
import org.elasticsearch.common.UUIDs;
3737
import org.elasticsearch.common.collect.HppcMaps;
3838
import org.elasticsearch.common.collect.ImmutableOpenMap;
@@ -62,9 +62,11 @@
6262
import java.util.Comparator;
6363
import java.util.EnumSet;
6464
import java.util.HashMap;
65+
import java.util.HashSet;
6566
import java.util.Iterator;
6667
import java.util.List;
6768
import java.util.Map;
69+
import java.util.Set;
6870
import java.util.SortedMap;
6971
import java.util.TreeMap;
7072

@@ -914,55 +916,70 @@ public MetaData build() {
914916
// while these datastructures aren't even used.
915917
// 2) The aliasAndIndexLookup can be updated instead of rebuilding it all the time.
916918

917-
// build all concrete indices arrays:
918-
// TODO: I think we can remove these arrays. it isn't worth the effort, for operations on all indices.
919-
// When doing an operation across all indices, most of the time is spent on actually going to all shards and
920-
// do the required operations, the bottleneck isn't resolving expressions into concrete indices.
921-
List<String> allIndicesLst = new ArrayList<>();
919+
final Set<String> allIndices = new HashSet<>(indices.size());
920+
final List<String> allOpenIndices = new ArrayList<>();
921+
final List<String> allClosedIndices = new ArrayList<>();
922+
final Set<String> duplicateAliasesIndices = new HashSet<>();
922923
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
923-
allIndicesLst.add(cursor.value.getIndex().getName());
924-
}
925-
String[] allIndices = allIndicesLst.toArray(new String[allIndicesLst.size()]);
926-
927-
List<String> allOpenIndicesLst = new ArrayList<>();
928-
List<String> allClosedIndicesLst = new ArrayList<>();
929-
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
930-
IndexMetaData indexMetaData = cursor.value;
924+
final IndexMetaData indexMetaData = cursor.value;
925+
final String name = indexMetaData.getIndex().getName();
926+
boolean added = allIndices.add(name);
927+
assert added : "double index named [" + name + "]";
931928
if (indexMetaData.getState() == IndexMetaData.State.OPEN) {
932-
allOpenIndicesLst.add(indexMetaData.getIndex().getName());
929+
allOpenIndices.add(indexMetaData.getIndex().getName());
933930
} else if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
934-
allClosedIndicesLst.add(indexMetaData.getIndex().getName());
931+
allClosedIndices.add(indexMetaData.getIndex().getName());
932+
}
933+
indexMetaData.getAliases().keysIt().forEachRemaining(duplicateAliasesIndices::add);
934+
}
935+
duplicateAliasesIndices.retainAll(allIndices);
936+
if (duplicateAliasesIndices.isEmpty() == false) {
937+
// iterate again and constructs a helpful message
938+
ArrayList<String> duplicates = new ArrayList<>();
939+
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
940+
for (String alias: duplicateAliasesIndices) {
941+
if (cursor.value.getAliases().containsKey(alias)) {
942+
duplicates.add(alias + " (alias of " + cursor.value.getIndex() + ")");
943+
}
944+
}
935945
}
946+
assert duplicates.size() > 0;
947+
throw new IllegalStateException("index and alias names need to be unique, but the following duplicates were found ["
948+
+ Strings.collectionToCommaDelimitedString(duplicates)+ "]");
949+
936950
}
937-
String[] allOpenIndices = allOpenIndicesLst.toArray(new String[allOpenIndicesLst.size()]);
938-
String[] allClosedIndices = allClosedIndicesLst.toArray(new String[allClosedIndicesLst.size()]);
939951

940952
// build all indices map
941953
SortedMap<String, AliasOrIndex> aliasAndIndexLookup = new TreeMap<>();
942954
for (ObjectCursor<IndexMetaData> cursor : indices.values()) {
943955
IndexMetaData indexMetaData = cursor.value;
944-
aliasAndIndexLookup.put(indexMetaData.getIndex().getName(), new AliasOrIndex.Index(indexMetaData));
956+
AliasOrIndex existing = aliasAndIndexLookup.put(indexMetaData.getIndex().getName(), new AliasOrIndex.Index(indexMetaData));
957+
assert existing == null : "duplicate for " + indexMetaData.getIndex();
945958

946959
for (ObjectObjectCursor<String, AliasMetaData> aliasCursor : indexMetaData.getAliases()) {
947960
AliasMetaData aliasMetaData = aliasCursor.value;
948-
AliasOrIndex aliasOrIndex = aliasAndIndexLookup.get(aliasMetaData.getAlias());
949-
if (aliasOrIndex == null) {
950-
aliasOrIndex = new AliasOrIndex.Alias(aliasMetaData, indexMetaData);
951-
aliasAndIndexLookup.put(aliasMetaData.getAlias(), aliasOrIndex);
952-
} else if (aliasOrIndex instanceof AliasOrIndex.Alias) {
953-
AliasOrIndex.Alias alias = (AliasOrIndex.Alias) aliasOrIndex;
954-
alias.addIndex(indexMetaData);
955-
} else if (aliasOrIndex instanceof AliasOrIndex.Index) {
956-
AliasOrIndex.Index index = (AliasOrIndex.Index) aliasOrIndex;
957-
throw new IllegalStateException("index and alias names need to be unique, but alias [" + aliasMetaData.getAlias() + "] and index " + index.getIndex().getIndex() + " have the same name");
958-
} else {
959-
throw new IllegalStateException("unexpected alias [" + aliasMetaData.getAlias() + "][" + aliasOrIndex + "]");
960-
}
961+
aliasAndIndexLookup.compute(aliasMetaData.getAlias(), (aliasName, alias) -> {
962+
if (alias == null) {
963+
return new AliasOrIndex.Alias(aliasMetaData, indexMetaData);
964+
} else {
965+
assert alias instanceof AliasOrIndex.Alias : alias.getClass().getName();
966+
((AliasOrIndex.Alias) alias).addIndex(indexMetaData);
967+
return alias;
968+
}
969+
});
961970
}
962971
}
963972
aliasAndIndexLookup = Collections.unmodifiableSortedMap(aliasAndIndexLookup);
973+
// build all concrete indices arrays:
974+
// TODO: I think we can remove these arrays. it isn't worth the effort, for operations on all indices.
975+
// When doing an operation across all indices, most of the time is spent on actually going to all shards and
976+
// do the required operations, the bottleneck isn't resolving expressions into concrete indices.
977+
String[] allIndicesArray = allIndices.toArray(new String[allIndices.size()]);
978+
String[] allOpenIndicesArray = allOpenIndices.toArray(new String[allOpenIndices.size()]);
979+
String[] allClosedIndicesArray = allClosedIndices.toArray(new String[allClosedIndices.size()]);
980+
964981
return new MetaData(clusterUUID, version, transientSettings, persistentSettings, indices.build(), templates.build(),
965-
customs.build(), allIndices, allOpenIndices, allClosedIndices, aliasAndIndexLookup);
982+
customs.build(), allIndicesArray, allOpenIndicesArray, allClosedIndicesArray, aliasAndIndexLookup);
966983
}
967984

968985
public static String toXContent(MetaData metaData) throws IOException {

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,20 @@ public void updateSettings(final UpdateSettingsClusterStateUpdateRequest request
161161
final Settings normalizedSettings = Settings.builder().put(request.settings()).normalizePrefix(IndexMetaData.INDEX_SETTING_PREFIX).build();
162162
Settings.Builder settingsForClosedIndices = Settings.builder();
163163
Settings.Builder settingsForOpenIndices = Settings.builder();
164-
Settings.Builder skipppedSettings = Settings.builder();
164+
final Set<String> skippedSettings = new HashSet<>();
165165

166166
indexScopedSettings.validate(normalizedSettings);
167167
// never allow to change the number of shards
168-
for (Map.Entry<String, String> entry : normalizedSettings.getAsMap().entrySet()) {
169-
Setting setting = indexScopedSettings.get(entry.getKey());
168+
for (String key : normalizedSettings.getKeys()) {
169+
Setting setting = indexScopedSettings.get(key);
170170
assert setting != null; // we already validated the normalized settings
171-
settingsForClosedIndices.put(entry.getKey(), entry.getValue());
171+
settingsForClosedIndices.copy(key, normalizedSettings);
172172
if (setting.isDynamic()) {
173-
settingsForOpenIndices.put(entry.getKey(), entry.getValue());
173+
settingsForOpenIndices.copy(key, normalizedSettings);
174174
} else {
175-
skipppedSettings.put(entry.getKey(), entry.getValue());
175+
skippedSettings.add(key);
176176
}
177177
}
178-
final Settings skippedSettigns = skipppedSettings.build();
179178
final Settings closedSettings = settingsForClosedIndices.build();
180179
final Settings openSettings = settingsForOpenIndices.build();
181180
final boolean preserveExisting = request.isPreserveExisting();
@@ -210,11 +209,9 @@ public ClusterState execute(ClusterState currentState) {
210209
}
211210
}
212211

213-
if (!skippedSettigns.isEmpty() && !openIndices.isEmpty()) {
212+
if (!skippedSettings.isEmpty() && !openIndices.isEmpty()) {
214213
throw new IllegalArgumentException(String.format(Locale.ROOT,
215-
"Can't update non dynamic settings [%s] for open indices %s",
216-
skippedSettigns.getAsMap().keySet(),
217-
openIndices
214+
"Can't update non dynamic settings [%s] for open indices %s", skippedSettings, openIndices
218215
));
219216
}
220217

core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static boolean isIngestNode(Settings settings) {
8484
* <p>
8585
* <b>Note:</b> if the version of the node is unknown {@link Version#minimumCompatibilityVersion()} should be used for the current
8686
* version. it corresponds to the minimum version this elasticsearch version can communicate with. If a higher version is used
87-
* the node might not be able to communicate with the remove node. After initial handshakes node versions will be discovered
87+
* the node might not be able to communicate with the remote node. After initial handshakes node versions will be discovered
8888
* and updated.
8989
* </p>
9090
*
@@ -101,7 +101,7 @@ public DiscoveryNode(final String id, TransportAddress address, Version version)
101101
* <p>
102102
* <b>Note:</b> if the version of the node is unknown {@link Version#minimumCompatibilityVersion()} should be used for the current
103103
* version. it corresponds to the minimum version this elasticsearch version can communicate with. If a higher version is used
104-
* the node might not be able to communicate with the remove node. After initial handshakes node versions will be discovered
104+
* the node might not be able to communicate with the remote node. After initial handshakes node versions will be discovered
105105
* and updated.
106106
* </p>
107107
*
@@ -121,7 +121,7 @@ public DiscoveryNode(String id, TransportAddress address, Map<String, String> at
121121
* <p>
122122
* <b>Note:</b> if the version of the node is unknown {@link Version#minimumCompatibilityVersion()} should be used for the current
123123
* version. it corresponds to the minimum version this elasticsearch version can communicate with. If a higher version is used
124-
* the node might not be able to communicate with the remove node. After initial handshakes node versions will be discovered
124+
* the node might not be able to communicate with the remote node. After initial handshakes node versions will be discovered
125125
* and updated.
126126
* </p>
127127
*
@@ -143,7 +143,7 @@ public DiscoveryNode(String nodeName, String nodeId, TransportAddress address,
143143
* <p>
144144
* <b>Note:</b> if the version of the node is unknown {@link Version#minimumCompatibilityVersion()} should be used for the current
145145
* version. it corresponds to the minimum version this elasticsearch version can communicate with. If a higher version is used
146-
* the node might not be able to communicate with the remove node. After initial handshakes node versions will be discovered
146+
* the node might not be able to communicate with the remote node. After initial handshakes node versions will be discovered
147147
* and updated.
148148
* </p>
149149
*
@@ -189,9 +189,8 @@ public DiscoveryNode(String nodeName, String nodeId, String ephemeralId, String
189189

190190
/** Creates a DiscoveryNode representing the local node. */
191191
public static DiscoveryNode createLocal(Settings settings, TransportAddress publishAddress, String nodeId) {
192-
Map<String, String> attributes = new HashMap<>(Node.NODE_ATTRIBUTES.get(settings).getAsMap());
192+
Map<String, String> attributes = Node.NODE_ATTRIBUTES.getAsMap(settings);
193193
Set<Role> roles = getRolesFromSettings(settings);
194-
195194
return new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), nodeId, publishAddress, attributes, roles, Version.CURRENT);
196195
}
197196

0 commit comments

Comments
 (0)