Skip to content

Commit 570390a

Browse files
committed
Merge branch 'master' into feature/client_aggs_parsing
2 parents 2e602d6 + e13db1b commit 570390a

File tree

72 files changed

+1870
-627
lines changed

Some content is hidden

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

72 files changed

+1870
-627
lines changed

buildSrc/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# When updating elasticsearch, please update 'rest' version in core/src/main/resources/org/elasticsearch/bootstrap/test-framework.policy
2-
elasticsearch = 6.0.0-alpha1
2+
elasticsearch = 6.0.0-alpha2
33
lucene = 7.0.0-snapshot-89f6d17
44

55
# optional dependencies

core/src/main/java/org/elasticsearch/Version.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public class Version implements Comparable<Version> {
8787
public static final int V_6_0_0_alpha1_ID_UNRELEASED = 6000001;
8888
public static final Version V_6_0_0_alpha1_UNRELEASED =
8989
new Version(V_6_0_0_alpha1_ID_UNRELEASED, org.apache.lucene.util.Version.LUCENE_7_0_0);
90-
public static final Version CURRENT = V_6_0_0_alpha1_UNRELEASED;
90+
public static final int V_6_0_0_alpha2_ID_UNRELEASED = 6000002;
91+
public static final Version V_6_0_0_alpha2_UNRELEASED =
92+
new Version(V_6_0_0_alpha2_ID_UNRELEASED, org.apache.lucene.util.Version.LUCENE_7_0_0);
93+
public static final Version CURRENT = V_6_0_0_alpha2_UNRELEASED;
9194

9295
// unreleased versions must be added to the above list with the suffix _UNRELEASED (with the exception of CURRENT)
9396

@@ -102,6 +105,8 @@ public static Version readVersion(StreamInput in) throws IOException {
102105

103106
public static Version fromId(int id) {
104107
switch (id) {
108+
case V_6_0_0_alpha2_ID_UNRELEASED:
109+
return V_6_0_0_alpha2_UNRELEASED;
105110
case V_6_0_0_alpha1_ID_UNRELEASED:
106111
return V_6_0_0_alpha1_UNRELEASED;
107112
case V_5_5_0_ID_UNRELEASED:

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929

3030
import static org.elasticsearch.action.ValidateActions.addValidationError;
31+
import static org.elasticsearch.snapshots.SnapshotInfo.VERBOSE_INTRODUCED;
3132

3233
/**
3334
* Get snapshot request
@@ -43,6 +44,8 @@ public class GetSnapshotsRequest extends MasterNodeRequest<GetSnapshotsRequest>
4344

4445
private boolean ignoreUnavailable;
4546

47+
private boolean verbose = true;
48+
4649
public GetSnapshotsRequest() {
4750
}
4851

@@ -123,19 +126,44 @@ public GetSnapshotsRequest ignoreUnavailable(boolean ignoreUnavailable) {
123126
this.ignoreUnavailable = ignoreUnavailable;
124127
return this;
125128
}
129+
126130
/**
127131
* @return Whether snapshots should be ignored when unavailable (corrupt or temporarily not fetchable)
128132
*/
129133
public boolean ignoreUnavailable() {
130134
return ignoreUnavailable;
131135
}
132136

137+
/**
138+
* Set to {@code false} to only show the snapshot names and the indices they contain.
139+
* This is useful when the snapshots belong to a cloud-based repository where each
140+
* blob read is a concern (cost wise and performance wise), as the snapshot names and
141+
* indices they contain can be retrieved from a single index blob in the repository,
142+
* whereas the rest of the information requires reading a snapshot metadata file for
143+
* each snapshot requested. Defaults to {@code true}, which returns all information
144+
* about each requested snapshot.
145+
*/
146+
public GetSnapshotsRequest verbose(boolean verbose) {
147+
this.verbose = verbose;
148+
return this;
149+
}
150+
151+
/**
152+
* Returns whether the request will return a verbose response.
153+
*/
154+
public boolean verbose() {
155+
return verbose;
156+
}
157+
133158
@Override
134159
public void readFrom(StreamInput in) throws IOException {
135160
super.readFrom(in);
136161
repository = in.readString();
137162
snapshots = in.readStringArray();
138163
ignoreUnavailable = in.readBoolean();
164+
if (in.getVersion().onOrAfter(VERBOSE_INTRODUCED)) {
165+
verbose = in.readBoolean();
166+
}
139167
}
140168

141169
@Override
@@ -144,5 +172,8 @@ public void writeTo(StreamOutput out) throws IOException {
144172
out.writeString(repository);
145173
out.writeStringArray(snapshots);
146174
out.writeBoolean(ignoreUnavailable);
175+
if (out.getVersion().onOrAfter(VERBOSE_INTRODUCED)) {
176+
out.writeBoolean(verbose);
177+
}
147178
}
148179
}

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsRequestBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,18 @@ public GetSnapshotsRequestBuilder setIgnoreUnavailable(boolean ignoreUnavailable
9696
return this;
9797
}
9898

99+
/**
100+
* Set to {@code false} to only show the snapshot names and the indices they contain.
101+
* This is useful when the snapshots belong to a cloud-based repository where each
102+
* blob read is a concern (cost wise and performance wise), as the snapshot names and
103+
* indices they contain can be retrieved from a single index blob in the repository,
104+
* whereas the rest of the information requires reading a snapshot metadata file for
105+
* each snapshot requested. Defaults to {@code true}, which returns all information
106+
* about each requested snapshot.
107+
*/
108+
public GetSnapshotsRequestBuilder setVerbose(boolean verbose) {
109+
request.verbose(verbose);
110+
return this;
111+
}
112+
99113
}

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/TransportGetSnapshotsAction.java

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.action.admin.cluster.snapshots.get;
2121

22+
import org.apache.lucene.util.CollectionUtil;
2223
import org.elasticsearch.action.ActionListener;
2324
import org.elasticsearch.action.support.ActionFilters;
2425
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
@@ -30,6 +31,7 @@
3031
import org.elasticsearch.common.inject.Inject;
3132
import org.elasticsearch.common.regex.Regex;
3233
import org.elasticsearch.common.settings.Settings;
34+
import org.elasticsearch.repositories.IndexId;
3335
import org.elasticsearch.repositories.RepositoryData;
3436
import org.elasticsearch.snapshots.SnapshotId;
3537
import org.elasticsearch.snapshots.SnapshotInfo;
@@ -39,11 +41,13 @@
3941
import org.elasticsearch.transport.TransportService;
4042

4143
import java.util.ArrayList;
44+
import java.util.Collections;
4245
import java.util.HashMap;
4346
import java.util.HashSet;
4447
import java.util.List;
4548
import java.util.Map;
4649
import java.util.Set;
50+
import java.util.stream.Collectors;
4751

4852
/**
4953
* Transport Action for get snapshots operation
@@ -76,31 +80,35 @@ protected ClusterBlockException checkBlock(GetSnapshotsRequest request, ClusterS
7680
}
7781

7882
@Override
79-
protected void masterOperation(final GetSnapshotsRequest request, ClusterState state,
83+
protected void masterOperation(final GetSnapshotsRequest request, final ClusterState state,
8084
final ActionListener<GetSnapshotsResponse> listener) {
8185
try {
8286
final String repository = request.repository();
83-
List<SnapshotInfo> snapshotInfoBuilder = new ArrayList<>();
8487
final Map<String, SnapshotId> allSnapshotIds = new HashMap<>();
85-
final List<SnapshotId> currentSnapshotIds = new ArrayList<>();
86-
final RepositoryData repositoryData = snapshotsService.getRepositoryData(repository);
88+
final List<SnapshotInfo> currentSnapshots = new ArrayList<>();
8789
for (SnapshotInfo snapshotInfo : snapshotsService.currentSnapshots(repository)) {
8890
SnapshotId snapshotId = snapshotInfo.snapshotId();
8991
allSnapshotIds.put(snapshotId.getName(), snapshotId);
90-
currentSnapshotIds.add(snapshotId);
92+
currentSnapshots.add(snapshotInfo);
9193
}
94+
95+
final RepositoryData repositoryData;
9296
if (isCurrentSnapshotsOnly(request.snapshots()) == false) {
97+
repositoryData = snapshotsService.getRepositoryData(repository);
9398
for (SnapshotId snapshotId : repositoryData.getAllSnapshotIds()) {
9499
allSnapshotIds.put(snapshotId.getName(), snapshotId);
95100
}
101+
} else {
102+
repositoryData = null;
96103
}
104+
97105
final Set<SnapshotId> toResolve = new HashSet<>();
98106
if (isAllSnapshots(request.snapshots())) {
99107
toResolve.addAll(allSnapshotIds.values());
100108
} else {
101109
for (String snapshotOrPattern : request.snapshots()) {
102110
if (GetSnapshotsRequest.CURRENT_SNAPSHOT.equalsIgnoreCase(snapshotOrPattern)) {
103-
toResolve.addAll(currentSnapshotIds);
111+
toResolve.addAll(currentSnapshots.stream().map(SnapshotInfo::snapshotId).collect(Collectors.toList()));
104112
} else if (Regex.isSimpleMatchPattern(snapshotOrPattern) == false) {
105113
if (allSnapshotIds.containsKey(snapshotOrPattern)) {
106114
toResolve.add(allSnapshotIds.get(snapshotOrPattern));
@@ -121,9 +129,23 @@ protected void masterOperation(final GetSnapshotsRequest request, ClusterState s
121129
}
122130
}
123131

124-
snapshotInfoBuilder.addAll(snapshotsService.snapshots(
125-
repository, new ArrayList<>(toResolve), repositoryData.getIncompatibleSnapshotIds(), request.ignoreUnavailable()));
126-
listener.onResponse(new GetSnapshotsResponse(snapshotInfoBuilder));
132+
final List<SnapshotInfo> snapshotInfos;
133+
if (request.verbose()) {
134+
final Set<SnapshotId> incompatibleSnapshots = repositoryData != null ?
135+
new HashSet<>(repositoryData.getIncompatibleSnapshotIds()) : Collections.emptySet();
136+
snapshotInfos = snapshotsService.snapshots(repository, new ArrayList<>(toResolve),
137+
incompatibleSnapshots, request.ignoreUnavailable());
138+
} else {
139+
if (repositoryData != null) {
140+
// want non-current snapshots as well, which are found in the repository data
141+
snapshotInfos = buildSimpleSnapshotInfos(toResolve, repositoryData, currentSnapshots);
142+
} else {
143+
// only want current snapshots
144+
snapshotInfos = currentSnapshots.stream().map(SnapshotInfo::basic).collect(Collectors.toList());
145+
CollectionUtil.timSort(snapshotInfos);
146+
}
147+
}
148+
listener.onResponse(new GetSnapshotsResponse(snapshotInfos));
127149
} catch (Exception e) {
128150
listener.onFailure(e);
129151
}
@@ -136,4 +158,32 @@ private boolean isAllSnapshots(String[] snapshots) {
136158
private boolean isCurrentSnapshotsOnly(String[] snapshots) {
137159
return (snapshots.length == 1 && GetSnapshotsRequest.CURRENT_SNAPSHOT.equalsIgnoreCase(snapshots[0]));
138160
}
161+
162+
private List<SnapshotInfo> buildSimpleSnapshotInfos(final Set<SnapshotId> toResolve,
163+
final RepositoryData repositoryData,
164+
final List<SnapshotInfo> currentSnapshots) {
165+
List<SnapshotInfo> snapshotInfos = new ArrayList<>();
166+
for (SnapshotInfo snapshotInfo : currentSnapshots) {
167+
if (toResolve.remove(snapshotInfo.snapshotId())) {
168+
snapshotInfos.add(snapshotInfo.basic());
169+
}
170+
}
171+
Map<SnapshotId, List<String>> snapshotsToIndices = new HashMap<>();
172+
for (IndexId indexId : repositoryData.getIndices().values()) {
173+
for (SnapshotId snapshotId : repositoryData.getSnapshots(indexId)) {
174+
if (toResolve.contains(snapshotId)) {
175+
snapshotsToIndices.computeIfAbsent(snapshotId, (k) -> new ArrayList<>())
176+
.add(indexId.getName());
177+
}
178+
}
179+
}
180+
for (Map.Entry<SnapshotId, List<String>> entry : snapshotsToIndices.entrySet()) {
181+
final List<String> indices = entry.getValue();
182+
CollectionUtil.timSort(indices);
183+
final SnapshotId snapshotId = entry.getKey();
184+
snapshotInfos.add(new SnapshotInfo(snapshotId, indices, repositoryData.getSnapshotState(snapshotId)));
185+
}
186+
CollectionUtil.timSort(snapshotInfos);
187+
return Collections.unmodifiableList(snapshotInfos);
188+
}
139189
}

core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,6 @@ private void setup(boolean addShutdownHook, Environment environment) throws Boot
163163

164164
try {
165165
spawner.spawnNativePluginControllers(environment);
166-
Runtime.getRuntime().addShutdownHook(new Thread() {
167-
@Override
168-
public void run() {
169-
try {
170-
spawner.close();
171-
} catch (IOException e) {
172-
throw new ElasticsearchException("Failed to destroy spawned controllers", e);
173-
}
174-
}
175-
});
176166
} catch (IOException e) {
177167
throw new BootstrapException(e);
178168
}
@@ -191,7 +181,7 @@ public void run() {
191181
@Override
192182
public void run() {
193183
try {
194-
IOUtils.close(node);
184+
IOUtils.close(node, spawner);
195185
LoggerContext context = (LoggerContext) LogManager.getContext(false);
196186
Configurator.shutdown(context);
197187
} catch (IOException ex) {
@@ -269,7 +259,7 @@ private void start() throws NodeValidationException {
269259

270260
static void stop() throws IOException {
271261
try {
272-
IOUtils.close(INSTANCE.node);
262+
IOUtils.close(INSTANCE.node, INSTANCE.spawner);
273263
} finally {
274264
INSTANCE.keepAliveLatch.countDown();
275265
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,11 @@ public ClusterState execute(ClusterState currentState) {
276276
for (Index index : closeIndices) {
277277
final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
278278
final IndexMetaData updatedMetaData = updatedState.metaData().getIndexSafe(index);
279+
// Verifies that the current index settings can be updated with the updated dynamic settings.
279280
indicesService.verifyIndexMetadata(currentMetaData, updatedMetaData);
281+
// Now check that we can create the index with the updated settings (dynamic and non-dynamic).
282+
// This step is mandatory since we allow to update non-dynamic settings on closed indices.
283+
indicesService.verifyIndexMetadata(updatedMetaData, updatedMetaData);
280284
}
281285
} catch (IOException ex) {
282286
throw ExceptionsHelper.convertToElastic(ex);

core/src/main/java/org/elasticsearch/index/analysis/PreConfiguredTokenFilter.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.index.IndexSettings;
2828
import org.elasticsearch.indices.analysis.AnalysisModule;
2929
import org.elasticsearch.indices.analysis.PreBuiltCacheFactory;
30+
import org.elasticsearch.indices.analysis.PreBuiltCacheFactory.CachingStrategy;
3031

3132
import java.io.IOException;
3233
import java.util.function.BiFunction;
@@ -36,31 +37,46 @@
3637
* Provides pre-configured, shared {@link TokenFilter}s.
3738
*/
3839
public final class PreConfiguredTokenFilter implements AnalysisModule.AnalysisProvider<TokenFilterFactory> {
40+
/**
41+
* Create a pre-configured token filter that may not vary at all.
42+
*/
43+
public static PreConfiguredTokenFilter singleton(String name, boolean useFilterForMultitermQueries,
44+
Function<TokenStream, TokenStream> create) {
45+
return new PreConfiguredTokenFilter(name, useFilterForMultitermQueries, CachingStrategy.ONE,
46+
(tokenStream, version) -> create.apply(tokenStream));
47+
}
48+
49+
/**
50+
* Create a pre-configured token filter that may vary based on the Lucene version.
51+
*/
52+
public static PreConfiguredTokenFilter luceneVersion(String name, boolean useFilterForMultitermQueries,
53+
BiFunction<TokenStream, org.apache.lucene.util.Version, TokenStream> create) {
54+
return new PreConfiguredTokenFilter(name, useFilterForMultitermQueries, CachingStrategy.LUCENE,
55+
(tokenStream, version) -> create.apply(tokenStream, version.luceneVersion));
56+
}
57+
58+
/**
59+
* Create a pre-configured token filter that may vary based on the Elasticsearch version.
60+
*/
61+
public static PreConfiguredTokenFilter elasticsearchVersion(String name, boolean useFilterForMultitermQueries,
62+
BiFunction<TokenStream, org.elasticsearch.Version, TokenStream> create) {
63+
return new PreConfiguredTokenFilter(name, useFilterForMultitermQueries, CachingStrategy.ELASTICSEARCH,
64+
(tokenStream, version) -> create.apply(tokenStream, version));
65+
}
66+
3967
private final String name;
4068
private final boolean useFilterForMultitermQueries;
4169
private final PreBuiltCacheFactory.PreBuiltCache<TokenFilterFactory> cache;
4270
private final BiFunction<TokenStream, Version, TokenStream> create;
4371

44-
/**
45-
* Standard ctor with all the power.
46-
*/
47-
public PreConfiguredTokenFilter(String name, boolean useFilterForMultitermQueries,
48-
PreBuiltCacheFactory.CachingStrategy cachingStrategy, BiFunction<TokenStream, Version, TokenStream> create) {
72+
private PreConfiguredTokenFilter(String name, boolean useFilterForMultitermQueries,
73+
PreBuiltCacheFactory.CachingStrategy cache, BiFunction<TokenStream, Version, TokenStream> create) {
4974
this.name = name;
5075
this.useFilterForMultitermQueries = useFilterForMultitermQueries;
51-
cache = PreBuiltCacheFactory.getCache(cachingStrategy);
76+
this.cache = PreBuiltCacheFactory.getCache(cache);
5277
this.create = create;
5378
}
5479

55-
/**
56-
* Convenience ctor for token streams that don't vary based on version.
57-
*/
58-
public PreConfiguredTokenFilter(String name, boolean useFilterForMultitermQueries,
59-
PreBuiltCacheFactory.CachingStrategy cachingStrategy, Function<TokenStream, TokenStream> create) {
60-
this(name, useFilterForMultitermQueries, cachingStrategy, (input, version) -> create.apply(input));
61-
// TODO why oh why aren't these all CachingStrategy.ONE? They *can't* vary based on version because they don't get it, right?!
62-
}
63-
6480
@Override
6581
public TokenFilterFactory get(IndexSettings indexSettings, Environment environment, String name, Settings settings) throws IOException {
6682
return getTokenFilterFactory(Version.indexCreated(settings));

core/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,8 +1515,6 @@ public long getGlobalCheckpoint() {
15151515
*/
15161516
public void updateGlobalCheckpointOnReplica(final long globalCheckpoint) {
15171517
verifyReplicationTarget();
1518-
// we sample the recovery stage before sampling the local checkpoint or we are subject to a race condition in the below assertion
1519-
final RecoveryState.Stage stage = recoveryState().getStage();
15201518
final SequenceNumbersService seqNoService = getEngine().seqNoService();
15211519
final long localCheckpoint = seqNoService.getLocalCheckpoint();
15221520
if (globalCheckpoint > localCheckpoint) {
@@ -1526,10 +1524,10 @@ public void updateGlobalCheckpointOnReplica(final long globalCheckpoint) {
15261524
* case that the global checkpoint update from the primary is ahead of the local checkpoint on this shard. In this case, we
15271525
* ignore the global checkpoint update. This can happen if we are in the translog stage of recovery. Prior to this, the engine
15281526
* is not opened and this shard will not receive global checkpoint updates, and after this the shard will be contributing to
1529-
* calculations of the the global checkpoint.
1527+
* calculations of the the global checkpoint. However, we can not assert that we are in the translog stage of recovery here as
1528+
* while the global checkpoint update may have emanated from the primary when we were in that state, we could subsequently move
1529+
* to recovery finalization, or even finished recovery before the update arrives here.
15301530
*/
1531-
assert stage == RecoveryState.Stage.TRANSLOG
1532-
: "expected recovery stage [" + RecoveryState.Stage.TRANSLOG + "] but was [" + stage + "]";
15331531
return;
15341532
}
15351533
seqNoService.updateGlobalCheckpointOnReplica(globalCheckpoint);

0 commit comments

Comments
 (0)