Skip to content

Commit 5cdb1e6

Browse files
committed
Merge branch 'master' into feature/query-refactoring
2 parents 9fd61f7 + df8a300 commit 5cdb1e6

File tree

74 files changed

+1361
-1969
lines changed

Some content is hidden

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

74 files changed

+1361
-1969
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.index.merge.policy;
21-
22-
import org.apache.lucene.index.MergePolicy;
23-
import org.elasticsearch.index.shard.IndexShardComponent;
24-
25-
import java.io.Closeable;
20+
package org.apache.lucene.index;
2621

2722
/**
28-
*
23+
* Allows pkg private access
2924
*/
30-
public interface MergePolicyProvider<T extends MergePolicy> extends IndexShardComponent, Closeable {
31-
32-
T getMergePolicy();
25+
public class OneMergeHelper {
26+
private OneMergeHelper() {}
27+
public static String getSegmentName(MergePolicy.OneMerge merge) {
28+
return merge.info != null ? merge.info.info.name : "_na_";
29+
}
3330
}

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ protected CreateSnapshotResponse newResponse() {
5959

6060
@Override
6161
protected ClusterBlockException checkBlock(CreateSnapshotRequest request, ClusterState state) {
62-
// We are writing to the cluster metadata and reading from indices - so we need to check both blocks
63-
ClusterBlockException clusterBlockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
62+
// We are reading the cluster metadata and indices - so we need to check both blocks
63+
ClusterBlockException clusterBlockException = state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
6464
if (clusterBlockException != null) {
6565
return clusterBlockException;
6666
}

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/delete/TransportDeleteSnapshotAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ protected DeleteSnapshotResponse newResponse() {
5858

5959
@Override
6060
protected ClusterBlockException checkBlock(DeleteSnapshotRequest request, ClusterState state) {
61-
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
61+
// Cluster is not affected but we look up repositories in metadata
62+
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);
6263
}
6364

6465
@Override

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.collect.ImmutableMap;
2424
import org.elasticsearch.cluster.metadata.SnapshotId;
25-
import org.elasticsearch.cluster.metadata.SnapshotMetaData.State;
25+
import org.elasticsearch.cluster.SnapshotsInProgress.State;
2626
import org.elasticsearch.common.io.stream.StreamInput;
2727
import org.elasticsearch.common.io.stream.StreamOutput;
2828
import org.elasticsearch.common.io.stream.Streamable;

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.elasticsearch.cluster.block.ClusterBlockException;
3030
import org.elasticsearch.cluster.block.ClusterBlockLevel;
3131
import org.elasticsearch.cluster.metadata.SnapshotId;
32-
import org.elasticsearch.cluster.metadata.SnapshotMetaData;
32+
import org.elasticsearch.cluster.SnapshotsInProgress;
3333
import org.elasticsearch.common.Strings;
3434
import org.elasticsearch.common.inject.Inject;
3535
import org.elasticsearch.common.settings.Settings;
@@ -82,16 +82,16 @@ protected SnapshotsStatusResponse newResponse() {
8282
protected void masterOperation(final SnapshotsStatusRequest request,
8383
final ClusterState state,
8484
final ActionListener<SnapshotsStatusResponse> listener) throws Exception {
85-
List<SnapshotMetaData.Entry> currentSnapshots = snapshotsService.currentSnapshots(request.repository(), request.snapshots());
85+
List<SnapshotsInProgress.Entry> currentSnapshots = snapshotsService.currentSnapshots(request.repository(), request.snapshots());
8686

8787
if (currentSnapshots.isEmpty()) {
8888
listener.onResponse(buildResponse(request, currentSnapshots, null));
8989
return;
9090
}
9191

9292
Set<String> nodesIds = newHashSet();
93-
for (SnapshotMetaData.Entry entry : currentSnapshots) {
94-
for (SnapshotMetaData.ShardSnapshotStatus status : entry.shards().values()) {
93+
for (SnapshotsInProgress.Entry entry : currentSnapshots) {
94+
for (SnapshotsInProgress.ShardSnapshotStatus status : entry.shards().values()) {
9595
if (status.nodeId() != null) {
9696
nodesIds.add(status.nodeId());
9797
}
@@ -111,7 +111,7 @@ protected void masterOperation(final SnapshotsStatusRequest request,
111111
@Override
112112
public void onResponse(TransportNodesSnapshotsStatus.NodesSnapshotStatus nodeSnapshotStatuses) {
113113
try {
114-
List<SnapshotMetaData.Entry> currentSnapshots =
114+
List<SnapshotsInProgress.Entry> currentSnapshots =
115115
snapshotsService.currentSnapshots(request.repository(), request.snapshots());
116116
listener.onResponse(buildResponse(request, currentSnapshots, nodeSnapshotStatuses));
117117
} catch (Throwable e) {
@@ -131,7 +131,7 @@ public void onFailure(Throwable e) {
131131

132132
}
133133

134-
private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, List<SnapshotMetaData.Entry> currentSnapshots,
134+
private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, List<SnapshotsInProgress.Entry> currentSnapshots,
135135
TransportNodesSnapshotsStatus.NodesSnapshotStatus nodeSnapshotStatuses) throws IOException {
136136
// First process snapshot that are currently processed
137137
ImmutableList.Builder<SnapshotStatus> builder = ImmutableList.builder();
@@ -144,11 +144,11 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li
144144
nodeSnapshotStatusMap = newHashMap();
145145
}
146146

147-
for (SnapshotMetaData.Entry entry : currentSnapshots) {
147+
for (SnapshotsInProgress.Entry entry : currentSnapshots) {
148148
currentSnapshotIds.add(entry.snapshotId());
149149
ImmutableList.Builder<SnapshotIndexShardStatus> shardStatusBuilder = ImmutableList.builder();
150-
for (ImmutableMap.Entry<ShardId, SnapshotMetaData.ShardSnapshotStatus> shardEntry : entry.shards().entrySet()) {
151-
SnapshotMetaData.ShardSnapshotStatus status = shardEntry.getValue();
150+
for (ImmutableMap.Entry<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shardEntry : entry.shards().entrySet()) {
151+
SnapshotsInProgress.ShardSnapshotStatus status = shardEntry.getValue();
152152
if (status.nodeId() != null) {
153153
// We should have information about this shard from the shard:
154154
TransportNodesSnapshotsStatus.NodeSnapshotStatus nodeStatus = nodeSnapshotStatusMap.get(status.nodeId());
@@ -204,16 +204,16 @@ private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, Li
204204
for (ImmutableMap.Entry<ShardId, IndexShardSnapshotStatus> shardStatus : shardStatues.entrySet()) {
205205
shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), shardStatus.getValue()));
206206
}
207-
final SnapshotMetaData.State state;
207+
final SnapshotsInProgress.State state;
208208
switch (snapshot.state()) {
209209
case FAILED:
210-
state = SnapshotMetaData.State.FAILED;
210+
state = SnapshotsInProgress.State.FAILED;
211211
break;
212212
case SUCCESS:
213213
case PARTIAL:
214214
// Translating both PARTIAL and SUCCESS to SUCCESS for now
215215
// TODO: add the differentiation on the metadata level in the next major release
216-
state = SnapshotMetaData.State.SUCCESS;
216+
state = SnapshotsInProgress.State.SUCCESS;
217217
break;
218218
default:
219219
throw new IllegalArgumentException("Unknown snapshot state " + snapshot.state());

core/src/main/java/org/elasticsearch/action/admin/cluster/state/ClusterStateRequest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ClusterStateRequest extends MasterNodeReadRequest<ClusterStateReque
3838
private boolean nodes = true;
3939
private boolean metaData = true;
4040
private boolean blocks = true;
41+
private boolean customs = true;
4142
private String[] indices = Strings.EMPTY_ARRAY;
4243
private IndicesOptions indicesOptions = IndicesOptions.lenientExpandOpen();
4344

@@ -54,6 +55,7 @@ public ClusterStateRequest all() {
5455
nodes = true;
5556
metaData = true;
5657
blocks = true;
58+
customs = true;
5759
indices = Strings.EMPTY_ARRAY;
5860
return this;
5961
}
@@ -63,6 +65,7 @@ public ClusterStateRequest clear() {
6365
nodes = false;
6466
metaData = false;
6567
blocks = false;
68+
customs = false;
6669
indices = Strings.EMPTY_ARRAY;
6770
return this;
6871
}
@@ -124,13 +127,23 @@ public final ClusterStateRequest indicesOptions(IndicesOptions indicesOptions) {
124127
return this;
125128
}
126129

130+
public ClusterStateRequest customs(boolean customs) {
131+
this.customs = customs;
132+
return this;
133+
}
134+
135+
public boolean customs() {
136+
return customs;
137+
}
138+
127139
@Override
128140
public void readFrom(StreamInput in) throws IOException {
129141
super.readFrom(in);
130142
routingTable = in.readBoolean();
131143
nodes = in.readBoolean();
132144
metaData = in.readBoolean();
133145
blocks = in.readBoolean();
146+
customs = in.readBoolean();
134147
indices = in.readStringArray();
135148
indicesOptions = IndicesOptions.readIndicesOptions(in);
136149
}
@@ -142,6 +155,7 @@ public void writeTo(StreamOutput out) throws IOException {
142155
out.writeBoolean(nodes);
143156
out.writeBoolean(metaData);
144157
out.writeBoolean(blocks);
158+
out.writeBoolean(customs);
145159
out.writeStringArray(indices);
146160
indicesOptions.writeIndicesOptions(out);
147161
}

core/src/main/java/org/elasticsearch/action/admin/cluster/state/TransportClusterStateAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ protected void masterOperation(final ClusterStateRequest request, final ClusterS
123123

124124
builder.metaData(mdBuilder);
125125
}
126+
if (request.customs()) {
127+
builder.customs(currentState.customs());
128+
}
126129
listener.onResponse(new ClusterStateResponse(clusterName, builder.build()));
127130
}
128131

core/src/main/java/org/elasticsearch/action/support/nodes/TransportNodesAction.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ protected String[] filterNodeIds(DiscoveryNodes nodes, String[] nodesIds) {
8383
return nodesIds;
8484
}
8585

86+
protected String[] resolveNodes(NodesRequest request, ClusterState clusterState) {
87+
return clusterState.nodes().resolveNodesIds(request.nodesIds());
88+
}
89+
90+
8691
private class AsyncAction {
8792

8893
private final NodesRequest request;
@@ -96,7 +101,7 @@ private AsyncAction(NodesRequest request, ActionListener<NodesResponse> listener
96101
this.request = request;
97102
this.listener = listener;
98103
clusterState = clusterService.state();
99-
String[] nodesIds = clusterState.nodes().resolveNodesIds(request.nodesIds());
104+
String[] nodesIds = resolveNodes(request, clusterState);
100105
this.nodesIds = filterNodeIds(clusterState.nodes(), nodesIds);
101106
this.responses = new AtomicReferenceArray<>(this.nodesIds.length);
102107
}

core/src/main/java/org/elasticsearch/cluster/ClusterState.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ public static void registerPrototype(String type, Custom proto) {
117117
customPrototypes.put(type, proto);
118118
}
119119

120+
static {
121+
// register non plugin custom parts
122+
registerPrototype(SnapshotsInProgress.TYPE, SnapshotsInProgress.PROTO);
123+
registerPrototype(RestoreInProgress.TYPE, RestoreInProgress.PROTO);
124+
}
125+
120126
@Nullable
121127
public static <T extends Custom> T lookupPrototype(String type) {
122128
//noinspection unchecked
@@ -249,6 +255,10 @@ public ImmutableOpenMap<String, Custom> getCustoms() {
249255
return this.customs;
250256
}
251257

258+
public <T extends Custom> T custom(String type) {
259+
return (T) customs.get(type);
260+
}
261+
252262
public ClusterName getClusterName() {
253263
return this.clusterName;
254264
}

core/src/main/java/org/elasticsearch/cluster/metadata/RestoreMetaData.java renamed to core/src/main/java/org/elasticsearch/cluster/RestoreInProgress.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,30 @@
1717
* under the License.
1818
*/
1919

20-
package org.elasticsearch.cluster.metadata;
20+
package org.elasticsearch.cluster;
2121

2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.collect.ImmutableMap;
24-
import org.elasticsearch.cluster.AbstractDiffable;
24+
import org.elasticsearch.cluster.ClusterState.Custom;
25+
import org.elasticsearch.cluster.metadata.SnapshotId;
2526
import org.elasticsearch.common.io.stream.StreamInput;
2627
import org.elasticsearch.common.io.stream.StreamOutput;
2728
import org.elasticsearch.common.xcontent.ToXContent;
2829
import org.elasticsearch.common.xcontent.XContentBuilder;
29-
import org.elasticsearch.common.xcontent.XContentParser;
3030
import org.elasticsearch.index.shard.ShardId;
3131

3232
import java.io.IOException;
33-
import java.util.EnumSet;
3433
import java.util.List;
3534
import java.util.Map;
3635

3736
/**
3837
* Meta data about restore processes that are currently executing
3938
*/
40-
public class RestoreMetaData extends AbstractDiffable<MetaData.Custom> implements MetaData.Custom {
39+
public class RestoreInProgress extends AbstractDiffable<Custom> implements Custom {
4140

4241
public static final String TYPE = "restore";
4342

44-
public static final RestoreMetaData PROTO = new RestoreMetaData();
43+
public static final RestoreInProgress PROTO = new RestoreInProgress();
4544

4645
private final ImmutableList<Entry> entries;
4746

@@ -50,7 +49,7 @@ public class RestoreMetaData extends AbstractDiffable<MetaData.Custom> implement
5049
*
5150
* @param entries list of currently running restore processes
5251
*/
53-
public RestoreMetaData(ImmutableList<Entry> entries) {
52+
public RestoreInProgress(ImmutableList<Entry> entries) {
5453
this.entries = entries;
5554
}
5655

@@ -59,7 +58,7 @@ public RestoreMetaData(ImmutableList<Entry> entries) {
5958
*
6059
* @param entries list of currently running restore processes
6160
*/
62-
public RestoreMetaData(Entry... entries) {
61+
public RestoreInProgress(Entry... entries) {
6362
this.entries = ImmutableList.copyOf(entries);
6463
}
6564

@@ -93,7 +92,7 @@ public boolean equals(Object o) {
9392
if (this == o) return true;
9493
if (o == null || getClass() != o.getClass()) return false;
9594

96-
RestoreMetaData that = (RestoreMetaData) o;
95+
RestoreInProgress that = (RestoreInProgress) o;
9796

9897
if (!entries.equals(that.entries)) return false;
9998

@@ -408,7 +407,7 @@ public String type() {
408407
* {@inheritDoc}
409408
*/
410409
@Override
411-
public RestoreMetaData readFrom(StreamInput in) throws IOException {
410+
public RestoreInProgress readFrom(StreamInput in) throws IOException {
412411
Entry[] entries = new Entry[in.readVInt()];
413412
for (int i = 0; i < entries.length; i++) {
414413
SnapshotId snapshotId = SnapshotId.readSnapshotId(in);
@@ -427,7 +426,7 @@ public RestoreMetaData readFrom(StreamInput in) throws IOException {
427426
}
428427
entries[i] = new Entry(snapshotId, state, indexBuilder.build(), builder.build());
429428
}
430-
return new RestoreMetaData(entries);
429+
return new RestoreInProgress(entries);
431430
}
432431

433432
/**
@@ -451,19 +450,6 @@ public void writeTo(StreamOutput out) throws IOException {
451450
}
452451
}
453452

454-
/**
455-
* {@inheritDoc}
456-
*/
457-
@Override
458-
public RestoreMetaData fromXContent(XContentParser parser) throws IOException {
459-
throw new UnsupportedOperationException();
460-
}
461-
462-
@Override
463-
public EnumSet<MetaData.XContentContext> context() {
464-
return MetaData.API_ONLY;
465-
}
466-
467453
/**
468454
* {@inheritDoc}
469455
*/

0 commit comments

Comments
 (0)