Merge branch 'master' into feature-suggest-refactoring
This commit is contained in:
commit
09c8a21e83
|
@ -39,6 +39,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_UUID_NA_VALUE;
|
||||
|
||||
/**
|
||||
* A base class for all elasticsearch exceptions.
|
||||
*/
|
||||
|
@ -49,6 +51,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
public static final boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT = true;
|
||||
public static final boolean REST_EXCEPTION_SKIP_CAUSE_DEFAULT = false;
|
||||
private static final String INDEX_HEADER_KEY = "es.index";
|
||||
private static final String INDEX_HEADER_KEY_UUID = "es.index_uuid";
|
||||
private static final String SHARD_HEADER_KEY = "es.shard";
|
||||
private static final String RESOURCE_HEADER_TYPE_KEY = "es.resource.type";
|
||||
private static final String RESOURCE_HEADER_ID_KEY = "es.resource.id";
|
||||
|
@ -70,7 +73,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
* The message can be parameterized using <code>{}</code> as placeholders for the given
|
||||
* arguments
|
||||
*
|
||||
* @param msg the detail message
|
||||
* @param msg the detail message
|
||||
* @param args the arguments for the message
|
||||
*/
|
||||
public ElasticsearchException(String msg, Object... args) {
|
||||
|
@ -332,7 +335,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
|
||||
private void xContentHeader(XContentBuilder builder, String key, List<String> values) throws IOException {
|
||||
if (values != null && values.isEmpty() == false) {
|
||||
if(values.size() == 1) {
|
||||
if (values.size() == 1) {
|
||||
builder.field(key, values.get(0));
|
||||
} else {
|
||||
builder.startArray(key);
|
||||
|
@ -374,7 +377,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
if (cause != null && cause instanceof ElasticsearchException) {
|
||||
return ((ElasticsearchException) cause).guessRootCauses();
|
||||
}
|
||||
return new ElasticsearchException[] {this};
|
||||
return new ElasticsearchException[]{this};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -387,7 +390,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
if (ex instanceof ElasticsearchException) {
|
||||
return ((ElasticsearchException) ex).guessRootCauses();
|
||||
}
|
||||
return new ElasticsearchException[] {new ElasticsearchException(t.getMessage(), t) {
|
||||
return new ElasticsearchException[]{new ElasticsearchException(t.getMessage(), t) {
|
||||
@Override
|
||||
protected String getExceptionName() {
|
||||
return getExceptionName(getCause());
|
||||
|
@ -414,7 +417,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (headers.containsKey(INDEX_HEADER_KEY)) {
|
||||
builder.append('[').append(getIndex()).append(']');
|
||||
builder.append(getIndex());
|
||||
if (headers.containsKey(SHARD_HEADER_KEY)) {
|
||||
builder.append('[').append(getShardId()).append(']');
|
||||
}
|
||||
|
@ -435,7 +438,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
final String fileName = in.readOptionalString();
|
||||
final String methodName = in.readString();
|
||||
final int lineNumber = in.readVInt();
|
||||
stackTrace[i] = new StackTraceElement(declaringClasss,methodName, fileName, lineNumber);
|
||||
stackTrace[i] = new StackTraceElement(declaringClasss, methodName, fileName, lineNumber);
|
||||
}
|
||||
throwable.setStackTrace(stackTrace);
|
||||
|
||||
|
@ -631,10 +634,11 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
CLASS_TO_ELASTICSEARCH_EXCEPTION_HANDLE = Collections.unmodifiableMap(exceptions);
|
||||
}
|
||||
|
||||
public String getIndex() {
|
||||
public Index getIndex() {
|
||||
List<String> index = getHeader(INDEX_HEADER_KEY);
|
||||
if (index != null && index.isEmpty() == false) {
|
||||
return index.get(0);
|
||||
List<String> index_uuid = getHeader(INDEX_HEADER_KEY_UUID);
|
||||
return new Index(index.get(0), index_uuid.get(0));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -651,22 +655,28 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
public void setIndex(Index index) {
|
||||
if (index != null) {
|
||||
addHeader(INDEX_HEADER_KEY, index.getName());
|
||||
addHeader(INDEX_HEADER_KEY_UUID, index.getUUID());
|
||||
}
|
||||
}
|
||||
|
||||
public void setIndex(String index) {
|
||||
if (index != null) {
|
||||
addHeader(INDEX_HEADER_KEY, index);
|
||||
setIndex(new Index(index, INDEX_UUID_NA_VALUE));
|
||||
}
|
||||
}
|
||||
|
||||
public void setShard(ShardId shardId) {
|
||||
if (shardId != null) {
|
||||
addHeader(INDEX_HEADER_KEY, shardId.getIndex());
|
||||
setIndex(shardId.getIndex());
|
||||
addHeader(SHARD_HEADER_KEY, Integer.toString(shardId.id()));
|
||||
}
|
||||
}
|
||||
|
||||
public void setShard(String index, int shardId) {
|
||||
setIndex(index);
|
||||
addHeader(SHARD_HEADER_KEY, Integer.toString(shardId));
|
||||
}
|
||||
|
||||
public void setResources(String type, String... id) {
|
||||
assert type != null;
|
||||
addHeader(RESOURCE_HEADER_ID_KEY, id);
|
||||
|
@ -691,7 +701,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
|
|||
final ElasticsearchException[] rootCauses = ElasticsearchException.guessRootCauses(t);
|
||||
builder.field("root_cause");
|
||||
builder.startArray();
|
||||
for (ElasticsearchException rootCause : rootCauses){
|
||||
for (ElasticsearchException rootCause : rootCauses) {
|
||||
builder.startObject();
|
||||
rootCause.toXContent(builder, new ToXContent.DelegatingMapParams(Collections.singletonMap(ElasticsearchException.REST_EXCEPTION_SKIP_CAUSE, "true"), params));
|
||||
builder.endObject();
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.action.ShardOperationFailedException;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -243,7 +244,12 @@ public final class ExceptionsHelper {
|
|||
|
||||
public GroupBy(Throwable t) {
|
||||
if (t instanceof ElasticsearchException) {
|
||||
index = ((ElasticsearchException) t).getIndex();
|
||||
final Index index = ((ElasticsearchException) t).getIndex();
|
||||
if (index != null) {
|
||||
this.index = index.getName();
|
||||
} else {
|
||||
this.index = null;
|
||||
}
|
||||
} else {
|
||||
index = null;
|
||||
}
|
||||
|
|
|
@ -32,10 +32,6 @@ public abstract class ActionRequest<Request extends ActionRequest<Request>> exte
|
|||
|
||||
public ActionRequest() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected ActionRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
// this does not set the listenerThreaded API, if needed, its up to the caller to set it
|
||||
// since most times, we actually want it to not be threaded...
|
||||
// this.listenerThreaded = request.listenerThreaded();
|
||||
|
|
|
@ -49,12 +49,6 @@ public abstract class ActionRequestBuilder<Request extends ActionRequest, Respon
|
|||
return this.request;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public final RequestBuilder putHeader(String key, Object value) {
|
||||
request.putHeader(key, value);
|
||||
return (RequestBuilder) this;
|
||||
}
|
||||
|
||||
public ListenableActionFuture<Response> execute() {
|
||||
PlainListenableActionFuture<Response> future = new PlainListenableActionFuture<>(threadPool);
|
||||
execute(future);
|
||||
|
|
|
@ -53,7 +53,7 @@ public abstract class DocWriteResponse extends ReplicationResponse implements St
|
|||
* The index the document was changed in.
|
||||
*/
|
||||
public String getIndex() {
|
||||
return this.shardId.getIndex();
|
||||
return this.shardId.getIndexName();
|
||||
}
|
||||
|
||||
|
||||
|
@ -119,7 +119,7 @@ public abstract class DocWriteResponse extends ReplicationResponse implements St
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
ReplicationResponse.ShardInfo shardInfo = getShardInfo();
|
||||
builder.field(Fields._INDEX, shardId.getIndex())
|
||||
builder.field(Fields._INDEX, shardId.getIndexName())
|
||||
.field(Fields._TYPE, type)
|
||||
.field(Fields._ID, id)
|
||||
.field(Fields._VERSION, version);
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.common.io.stream.Streamable;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -169,15 +170,13 @@ public class ReplicationResponse extends ActionResponse {
|
|||
|
||||
public static class Failure implements ShardOperationFailedException, ToXContent {
|
||||
|
||||
private String index;
|
||||
private int shardId;
|
||||
private ShardId shardId;
|
||||
private String nodeId;
|
||||
private Throwable cause;
|
||||
private RestStatus status;
|
||||
private boolean primary;
|
||||
|
||||
public Failure(String index, int shardId, @Nullable String nodeId, Throwable cause, RestStatus status, boolean primary) {
|
||||
this.index = index;
|
||||
public Failure(ShardId shardId, @Nullable String nodeId, Throwable cause, RestStatus status, boolean primary) {
|
||||
this.shardId = shardId;
|
||||
this.nodeId = nodeId;
|
||||
this.cause = cause;
|
||||
|
@ -193,7 +192,7 @@ public class ReplicationResponse extends ActionResponse {
|
|||
*/
|
||||
@Override
|
||||
public String index() {
|
||||
return index;
|
||||
return shardId.getIndexName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,6 +200,10 @@ public class ReplicationResponse extends ActionResponse {
|
|||
*/
|
||||
@Override
|
||||
public int shardId() {
|
||||
return shardId.id();
|
||||
}
|
||||
|
||||
public ShardId fullShardId() {
|
||||
return shardId;
|
||||
}
|
||||
|
||||
|
@ -243,8 +246,7 @@ public class ReplicationResponse extends ActionResponse {
|
|||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
index = in.readString();
|
||||
shardId = in.readVInt();
|
||||
shardId = ShardId.readShardId(in);
|
||||
nodeId = in.readOptionalString();
|
||||
cause = in.readThrowable();
|
||||
status = RestStatus.readFrom(in);
|
||||
|
@ -253,8 +255,7 @@ public class ReplicationResponse extends ActionResponse {
|
|||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(index);
|
||||
out.writeVInt(shardId);
|
||||
shardId.writeTo(out);
|
||||
out.writeOptionalString(nodeId);
|
||||
out.writeThrowable(cause);
|
||||
RestStatus.writeTo(out, status);
|
||||
|
@ -264,8 +265,8 @@ public class ReplicationResponse extends ActionResponse {
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(Fields._INDEX, index);
|
||||
builder.field(Fields._SHARD, shardId);
|
||||
builder.field(Fields._INDEX, shardId.getIndexName());
|
||||
builder.field(Fields._SHARD, shardId.id());
|
||||
builder.field(Fields._NODE, nodeId);
|
||||
builder.field(Fields.REASON);
|
||||
builder.startObject();
|
||||
|
|
|
@ -36,13 +36,19 @@ public class UnavailableShardsException extends ElasticsearchException {
|
|||
super(buildMessage(shardId, message), args);
|
||||
}
|
||||
|
||||
public UnavailableShardsException(String index, int shardId, String message, Object... args) {
|
||||
super(buildMessage(index, shardId, message), args);
|
||||
}
|
||||
|
||||
private static String buildMessage(ShardId shardId, String message) {
|
||||
if (shardId == null) {
|
||||
return message;
|
||||
}
|
||||
return "[" + shardId.index().name() + "][" + shardId.id() + "] " + message;
|
||||
return buildMessage(shardId.getIndexName(), shardId.id(), message);
|
||||
}
|
||||
|
||||
private static String buildMessage(String index, int shardId, String message) {return "[" + index + "][" + shardId + "] " + message;}
|
||||
|
||||
public UnavailableShardsException(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ public class TransportClusterHealthAction extends TransportMasterNodeReadAction<
|
|||
}
|
||||
|
||||
assert waitFor >= 0;
|
||||
final ClusterStateObserver observer = new ClusterStateObserver(clusterService, logger);
|
||||
final ClusterStateObserver observer = new ClusterStateObserver(clusterService, logger, threadPool.getThreadContext());
|
||||
final ClusterState state = observer.observedState();
|
||||
if (waitFor == 0 || request.timeout().millis() == 0) {
|
||||
listener.onResponse(getResponse(request, state, waitFor, request.timeout().millis() == 0));
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TransportNodesHotThreadsAction extends TransportNodesAction<NodesHo
|
|||
}
|
||||
|
||||
NodeRequest(String nodeId, NodesHotThreadsRequest request) {
|
||||
super(request, nodeId);
|
||||
super(nodeId);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TransportNodesInfoAction extends TransportNodesAction<NodesInfoRequ
|
|||
}
|
||||
|
||||
NodeInfoRequest(String nodeId, NodesInfoRequest request) {
|
||||
super(request, nodeId);
|
||||
super(nodeId);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TransportNodesStatsAction extends TransportNodesAction<NodesStatsRe
|
|||
}
|
||||
|
||||
NodeStatsRequest(String nodeId, NodesStatsRequest request) {
|
||||
super(request, nodeId);
|
||||
super(nodeId);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.io.stream.StreamOutput;
|
|||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -32,7 +33,7 @@ import java.io.IOException;
|
|||
*/
|
||||
public class ClusterSearchShardsGroup implements Streamable, ToXContent {
|
||||
|
||||
private String index;
|
||||
private Index index;
|
||||
private int shardId;
|
||||
ShardRouting[] shards;
|
||||
|
||||
|
@ -40,7 +41,7 @@ public class ClusterSearchShardsGroup implements Streamable, ToXContent {
|
|||
|
||||
}
|
||||
|
||||
public ClusterSearchShardsGroup(String index, int shardId, ShardRouting[] shards) {
|
||||
public ClusterSearchShardsGroup(Index index, int shardId, ShardRouting[] shards) {
|
||||
this.index = index;
|
||||
this.shardId = shardId;
|
||||
this.shards = shards;
|
||||
|
@ -53,7 +54,7 @@ public class ClusterSearchShardsGroup implements Streamable, ToXContent {
|
|||
}
|
||||
|
||||
public String getIndex() {
|
||||
return index;
|
||||
return index.getName();
|
||||
}
|
||||
|
||||
public int getShardId() {
|
||||
|
@ -66,7 +67,7 @@ public class ClusterSearchShardsGroup implements Streamable, ToXContent {
|
|||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
index = in.readString();
|
||||
index = Index.readIndex(in);
|
||||
shardId = in.readVInt();
|
||||
shards = new ShardRouting[in.readVInt()];
|
||||
for (int i = 0; i < shards.length; i++) {
|
||||
|
@ -76,7 +77,7 @@ public class ClusterSearchShardsGroup implements Streamable, ToXContent {
|
|||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
out.writeString(index);
|
||||
index.writeTo(out);
|
||||
out.writeVInt(shardId);
|
||||
out.writeVInt(shards.length);
|
||||
for (ShardRouting shardRouting : shards) {
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.cluster.routing.ShardIterator;
|
|||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -77,7 +78,7 @@ public class TransportClusterSearchShardsAction extends TransportMasterNodeReadA
|
|||
ClusterSearchShardsGroup[] groupResponses = new ClusterSearchShardsGroup[groupShardsIterator.size()];
|
||||
int currentGroup = 0;
|
||||
for (ShardIterator shardIt : groupShardsIterator) {
|
||||
String index = shardIt.shardId().getIndex();
|
||||
Index index = shardIt.shardId().getIndex();
|
||||
int shardId = shardIt.shardId().getId();
|
||||
ShardRouting[] shardRoutings = new ShardRouting[shardIt.size()];
|
||||
int currentShard = 0;
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.action.admin.cluster.snapshots.status;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.FailedNodeException;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.nodes.BaseNodeRequest;
|
||||
|
@ -146,8 +145,8 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction<Transpor
|
|||
public Request() {
|
||||
}
|
||||
|
||||
public Request(ActionRequest<?> request, String[] nodesIds) {
|
||||
super(request, nodesIds);
|
||||
public Request(String[] nodesIds) {
|
||||
super(nodesIds);
|
||||
}
|
||||
|
||||
public Request snapshotIds(SnapshotId[] snapshotIds) {
|
||||
|
@ -214,7 +213,7 @@ public class TransportNodesSnapshotsStatus extends TransportNodesAction<Transpor
|
|||
}
|
||||
|
||||
NodeRequest(String nodeId, TransportNodesSnapshotsStatus.Request request) {
|
||||
super(request, nodeId);
|
||||
super(nodeId);
|
||||
snapshotIds = request.snapshotIds;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ public class TransportSnapshotsStatusAction extends TransportMasterNodeAction<Sn
|
|||
snapshotIds[i] = currentSnapshots.get(i).snapshotId();
|
||||
}
|
||||
|
||||
TransportNodesSnapshotsStatus.Request nodesRequest = new TransportNodesSnapshotsStatus.Request(request, nodesIds.toArray(new String[nodesIds.size()]))
|
||||
TransportNodesSnapshotsStatus.Request nodesRequest = new TransportNodesSnapshotsStatus.Request(nodesIds.toArray(new String[nodesIds.size()]))
|
||||
.snapshotIds(snapshotIds).timeout(request.masterNodeTimeout());
|
||||
transportNodesSnapshotsStatus.execute(nodesRequest, new ActionListener<TransportNodesSnapshotsStatus.NodesSnapshotStatus>() {
|
||||
@Override
|
||||
|
|
|
@ -66,10 +66,10 @@ public class ClusterStatsIndices implements ToXContent, Streamable {
|
|||
|
||||
for (ClusterStatsNodeResponse r : nodeResponses) {
|
||||
for (org.elasticsearch.action.admin.indices.stats.ShardStats shardStats : r.shardsStats()) {
|
||||
ShardStats indexShardStats = countsPerIndex.get(shardStats.getShardRouting().getIndex());
|
||||
ShardStats indexShardStats = countsPerIndex.get(shardStats.getShardRouting().getIndexName());
|
||||
if (indexShardStats == null) {
|
||||
indexShardStats = new ShardStats();
|
||||
countsPerIndex.put(shardStats.getShardRouting().getIndex(), indexShardStats);
|
||||
countsPerIndex.put(shardStats.getShardRouting().getIndexName(), indexShardStats);
|
||||
}
|
||||
|
||||
indexShardStats.total++;
|
||||
|
|
|
@ -132,7 +132,7 @@ public class TransportClusterStatsAction extends TransportNodesAction<ClusterSta
|
|||
}
|
||||
|
||||
ClusterStatsNodeRequest(String nodeId, ClusterStatsRequest request) {
|
||||
super(request, nodeId);
|
||||
super(nodeId);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class TransportRenderSearchTemplateAction extends HandledTransportAction<
|
|||
|
||||
@Override
|
||||
protected void doRun() throws Exception {
|
||||
ExecutableScript executable = scriptService.executable(request.template(), ScriptContext.Standard.SEARCH, request, Collections.emptyMap());
|
||||
ExecutableScript executable = scriptService.executable(request.template(), ScriptContext.Standard.SEARCH, Collections.emptyMap());
|
||||
BytesReference processedTemplate = (BytesReference) executable.run();
|
||||
RenderSearchTemplateResponse response = new RenderSearchTemplateResponse();
|
||||
response.source(processedTemplate);
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TransportClearIndicesCacheAction extends TransportBroadcastByNodeAc
|
|||
|
||||
@Override
|
||||
protected EmptyResult shardOperation(ClearIndicesCacheRequest request, ShardRouting shardRouting) {
|
||||
IndexService service = indicesService.indexService(shardRouting.getIndex());
|
||||
IndexService service = indicesService.indexService(shardRouting.getIndexName());
|
||||
if (service != null) {
|
||||
IndexShard shard = service.getShardOrNull(shardRouting.id());
|
||||
boolean clearedAtLeastOne = false;
|
||||
|
|
|
@ -81,14 +81,6 @@ public class CreateIndexRequest extends AcknowledgedRequest<CreateIndexRequest>
|
|||
public CreateIndexRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new request to create an index that was triggered by a different request,
|
||||
* provided as an argument so that its headers and context can be copied to the new request.
|
||||
*/
|
||||
public CreateIndexRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new request to create an index with the specified name.
|
||||
*/
|
||||
|
|
|
@ -42,17 +42,6 @@ public class FlushRequest extends BroadcastRequest<FlushRequest> {
|
|||
private boolean force = false;
|
||||
private boolean waitIfOngoing = false;
|
||||
|
||||
public FlushRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new flush request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public FlushRequest(ActionRequest originalRequest) {
|
||||
super(originalRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new flush request against one or more indices. If nothing is provided, all indices will
|
||||
* be flushed.
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ShardFlushRequest extends ReplicationRequest<ShardFlushRequest> {
|
|||
private FlushRequest request = new FlushRequest();
|
||||
|
||||
public ShardFlushRequest(FlushRequest request, ShardId shardId) {
|
||||
super(request, shardId);
|
||||
super(shardId);
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,17 +36,6 @@ import java.util.Arrays;
|
|||
*/
|
||||
public class SyncedFlushRequest extends BroadcastRequest<SyncedFlushRequest> {
|
||||
|
||||
public SyncedFlushRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new synced flush request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public SyncedFlushRequest(ActionRequest originalRequest) {
|
||||
super(originalRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new synced flush request against one or more indices. If nothing is provided, all indices will
|
||||
* be sync flushed.
|
||||
|
|
|
@ -42,7 +42,6 @@ public class GetFieldMappingsIndexRequest extends SingleShardRequest<GetFieldMap
|
|||
}
|
||||
|
||||
GetFieldMappingsIndexRequest(GetFieldMappingsRequest other, String index, boolean probablySingleFieldRequest) {
|
||||
super(other);
|
||||
this.probablySingleFieldRequest = probablySingleFieldRequest;
|
||||
this.includeDefaults = other.includeDefaults();
|
||||
this.types = other.types();
|
||||
|
|
|
@ -102,7 +102,7 @@ public class TransportGetFieldMappingsIndexAction extends TransportSingleShardAc
|
|||
.filter(type -> Regex.simpleMatch(request.types(), type))
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
if (typeIntersection.isEmpty()) {
|
||||
throw new TypeMissingException(shardId.index(), request.types());
|
||||
throw new TypeMissingException(shardId.getIndex(), request.types());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class TransportGetFieldMappingsIndexAction extends TransportSingleShardAc
|
|||
}
|
||||
}
|
||||
|
||||
return new GetFieldMappingsResponse(singletonMap(shardId.getIndex(), typeMappings.immutableMap()));
|
||||
return new GetFieldMappingsResponse(singletonMap(shardId.getIndexName(), typeMappings.immutableMap()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -75,7 +75,7 @@ public class TransportRecoveryAction extends TransportBroadcastByNodeAction<Reco
|
|||
if (recoveryState == null) {
|
||||
continue;
|
||||
}
|
||||
String indexName = recoveryState.getShardId().getIndex();
|
||||
String indexName = recoveryState.getShardId().getIndexName();
|
||||
if (!shardResponses.containsKey(indexName)) {
|
||||
shardResponses.put(indexName, new ArrayList<>());
|
||||
}
|
||||
|
|
|
@ -33,17 +33,6 @@ import org.elasticsearch.action.support.broadcast.BroadcastRequest;
|
|||
*/
|
||||
public class RefreshRequest extends BroadcastRequest<RefreshRequest> {
|
||||
|
||||
public RefreshRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new refresh request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public RefreshRequest(ActionRequest originalRequest) {
|
||||
super(originalRequest);
|
||||
}
|
||||
|
||||
public RefreshRequest(String... indices) {
|
||||
super(indices);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class TransportRefreshAction extends TransportBroadcastReplicationAction<
|
|||
|
||||
@Override
|
||||
protected BasicReplicationRequest newShardRequest(RefreshRequest request, ShardId shardId) {
|
||||
return new BasicReplicationRequest(request, shardId);
|
||||
return new BasicReplicationRequest(shardId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -62,17 +62,17 @@ public class IndicesSegmentResponse extends BroadcastResponse implements ToXCont
|
|||
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (ShardSegments shard : shards) {
|
||||
indices.add(shard.getShardRouting().getIndex());
|
||||
indices.add(shard.getShardRouting().getIndexName());
|
||||
}
|
||||
|
||||
for (String index : indices) {
|
||||
for (String indexName : indices) {
|
||||
List<ShardSegments> shards = new ArrayList<>();
|
||||
for (ShardSegments shard : this.shards) {
|
||||
if (shard.getShardRouting().index().equals(index)) {
|
||||
if (shard.getShardRouting().getIndexName().equals(indexName)) {
|
||||
shards.add(shard);
|
||||
}
|
||||
}
|
||||
indicesSegments.put(index, new IndexSegments(index, shards.toArray(new ShardSegments[shards.size()])));
|
||||
indicesSegments.put(indexName, new IndexSegments(indexName, shards.toArray(new ShardSegments[shards.size()])));
|
||||
}
|
||||
this.indicesSegments = indicesSegments;
|
||||
return indicesSegments;
|
||||
|
|
|
@ -93,7 +93,7 @@ public class TransportIndicesSegmentsAction extends TransportBroadcastByNodeActi
|
|||
|
||||
@Override
|
||||
protected ShardSegments shardOperation(IndicesSegmentsRequest request, ShardRouting shardRouting) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRouting.getIndex());
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardRouting.getIndexName());
|
||||
IndexShard indexShard = indexService.getShard(shardRouting.id());
|
||||
return new ShardSegments(indexShard.routingEntry(), indexShard.segments(request.verbose()));
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc
|
|||
ImmutableOpenMap.Builder<String, ImmutableOpenIntMap<java.util.List<IndicesShardStoresResponse.StoreStatus>>> indicesStoreStatusesBuilder = ImmutableOpenMap.builder();
|
||||
java.util.List<IndicesShardStoresResponse.Failure> failureBuilder = new ArrayList<>();
|
||||
for (Response fetchResponse : fetchResponses) {
|
||||
ImmutableOpenIntMap<java.util.List<IndicesShardStoresResponse.StoreStatus>> indexStoreStatuses = indicesStoreStatusesBuilder.get(fetchResponse.shardId.getIndex());
|
||||
ImmutableOpenIntMap<java.util.List<IndicesShardStoresResponse.StoreStatus>> indexStoreStatuses = indicesStoreStatusesBuilder.get(fetchResponse.shardId.getIndexName());
|
||||
final ImmutableOpenIntMap.Builder<java.util.List<IndicesShardStoresResponse.StoreStatus>> indexShardsBuilder;
|
||||
if (indexStoreStatuses == null) {
|
||||
indexShardsBuilder = ImmutableOpenIntMap.builder();
|
||||
|
@ -179,15 +179,15 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc
|
|||
}
|
||||
for (NodeGatewayStartedShards response : fetchResponse.responses) {
|
||||
if (shardExistsInNode(response)) {
|
||||
IndicesShardStoresResponse.StoreStatus.AllocationStatus allocationStatus = getAllocationStatus(fetchResponse.shardId.getIndex(), fetchResponse.shardId.id(), response.getNode());
|
||||
IndicesShardStoresResponse.StoreStatus.AllocationStatus allocationStatus = getAllocationStatus(fetchResponse.shardId.getIndexName(), fetchResponse.shardId.id(), response.getNode());
|
||||
storeStatuses.add(new IndicesShardStoresResponse.StoreStatus(response.getNode(), response.version(), response.allocationId(), allocationStatus, response.storeException()));
|
||||
}
|
||||
}
|
||||
CollectionUtil.timSort(storeStatuses);
|
||||
indexShardsBuilder.put(fetchResponse.shardId.id(), storeStatuses);
|
||||
indicesStoreStatusesBuilder.put(fetchResponse.shardId.getIndex(), indexShardsBuilder.build());
|
||||
indicesStoreStatusesBuilder.put(fetchResponse.shardId.getIndexName(), indexShardsBuilder.build());
|
||||
for (FailedNodeException failure : fetchResponse.failures) {
|
||||
failureBuilder.add(new IndicesShardStoresResponse.Failure(failure.nodeId(), fetchResponse.shardId.getIndex(), fetchResponse.shardId.id(), failure.getCause()));
|
||||
failureBuilder.add(new IndicesShardStoresResponse.Failure(failure.nodeId(), fetchResponse.shardId.getIndexName(), fetchResponse.shardId.id(), failure.getCause()));
|
||||
}
|
||||
}
|
||||
listener.onResponse(new IndicesShardStoresResponse(indicesStoreStatusesBuilder.build(), Collections.unmodifiableList(failureBuilder)));
|
||||
|
@ -196,7 +196,7 @@ public class TransportIndicesShardStoresAction extends TransportMasterNodeReadAc
|
|||
private IndicesShardStoresResponse.StoreStatus.AllocationStatus getAllocationStatus(String index, int shardID, DiscoveryNode node) {
|
||||
for (ShardRouting shardRouting : routingNodes.node(node.id())) {
|
||||
ShardId shardId = shardRouting.shardId();
|
||||
if (shardId.id() == shardID && shardId.getIndex().equals(index)) {
|
||||
if (shardId.id() == shardID && shardId.getIndexName().equals(index)) {
|
||||
if (shardRouting.primary()) {
|
||||
return IndicesShardStoresResponse.StoreStatus.AllocationStatus.PRIMARY;
|
||||
} else if (shardRouting.assignedToNode()) {
|
||||
|
|
|
@ -89,17 +89,17 @@ public class IndicesStatsResponse extends BroadcastResponse implements ToXConten
|
|||
|
||||
Set<String> indices = new HashSet<>();
|
||||
for (ShardStats shard : shards) {
|
||||
indices.add(shard.getShardRouting().getIndex());
|
||||
indices.add(shard.getShardRouting().getIndexName());
|
||||
}
|
||||
|
||||
for (String index : indices) {
|
||||
for (String indexName : indices) {
|
||||
List<ShardStats> shards = new ArrayList<>();
|
||||
for (ShardStats shard : this.shards) {
|
||||
if (shard.getShardRouting().index().equals(index)) {
|
||||
if (shard.getShardRouting().getIndexName().equals(indexName)) {
|
||||
shards.add(shard);
|
||||
}
|
||||
}
|
||||
indicesStats.put(index, new IndexStats(index, shards.toArray(new ShardStats[shards.size()])));
|
||||
indicesStats.put(indexName, new IndexStats(indexName, shards.toArray(new ShardStats[shards.size()])));
|
||||
}
|
||||
this.indicesStats = indicesStats;
|
||||
return indicesStats;
|
||||
|
|
|
@ -59,14 +59,14 @@ public class UpgradeStatusResponse extends BroadcastResponse implements ToXConte
|
|||
indices.add(shard.getIndex());
|
||||
}
|
||||
|
||||
for (String index : indices) {
|
||||
for (String indexName : indices) {
|
||||
List<ShardUpgradeStatus> shards = new ArrayList<>();
|
||||
for (ShardUpgradeStatus shard : this.shards) {
|
||||
if (shard.getShardRouting().index().equals(index)) {
|
||||
if (shard.getShardRouting().getIndexName().equals(indexName)) {
|
||||
shards.add(shard);
|
||||
}
|
||||
}
|
||||
indicesUpgradeStats.put(index, new IndexUpgradeStatus(index, shards.toArray(new ShardUpgradeStatus[shards.size()])));
|
||||
indicesUpgradeStats.put(indexName, new IndexUpgradeStatus(indexName, shards.toArray(new ShardUpgradeStatus[shards.size()])));
|
||||
}
|
||||
this.indicesUpgradeStatus = indicesUpgradeStats;
|
||||
return indicesUpgradeStats;
|
||||
|
|
|
@ -75,7 +75,7 @@ public class TransportUpgradeAction extends TransportBroadcastByNodeAction<Upgra
|
|||
Map<String, Tuple<Version, org.apache.lucene.util.Version>> versions = new HashMap<>();
|
||||
for (ShardUpgradeResult result : shardUpgradeResults) {
|
||||
successfulShards++;
|
||||
String index = result.getShardId().getIndex();
|
||||
String index = result.getShardId().getIndex().getName();
|
||||
if (result.primary()) {
|
||||
Integer count = successfulPrimaryShards.get(index);
|
||||
successfulPrimaryShards.put(index, count == null ? 1 : count + 1);
|
||||
|
|
|
@ -96,7 +96,7 @@ public class TransportValidateQueryAction extends TransportBroadcastAction<Valid
|
|||
|
||||
@Override
|
||||
protected ShardValidateQueryRequest newShardRequest(int numShards, ShardRouting shard, ValidateQueryRequest request) {
|
||||
String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.index(), request.indices());
|
||||
String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.getIndexName(), request.indices());
|
||||
return new ShardValidateQueryRequest(shard.shardId(), filteringAliases, request);
|
||||
}
|
||||
|
||||
|
|
|
@ -69,14 +69,6 @@ public class BulkRequest extends ActionRequest<BulkRequest> implements Composite
|
|||
public BulkRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a bulk request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public BulkRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of requests to be executed. Either index or delete requests.
|
||||
*/
|
||||
|
|
|
@ -41,7 +41,7 @@ public class BulkShardRequest extends ReplicationRequest<BulkShardRequest> {
|
|||
}
|
||||
|
||||
BulkShardRequest(BulkRequest bulkRequest, ShardId shardId, boolean refresh, BulkItemRequest[] items) {
|
||||
super(bulkRequest, shardId);
|
||||
super(shardId);
|
||||
this.items = items;
|
||||
this.refresh = refresh;
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
|
|||
for (Map.Entry<String, Set<String>> entry : indicesAndTypes.entrySet()) {
|
||||
final String index = entry.getKey();
|
||||
if (autoCreateIndex.shouldAutoCreate(index, state)) {
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest(bulkRequest);
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
|
||||
createIndexRequest.index(index);
|
||||
for (String type : entry.getValue()) {
|
||||
createIndexRequest.mapping(type);
|
||||
|
@ -377,7 +377,7 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
|
|||
if (unavailableException == null) {
|
||||
IndexMetaData indexMetaData = metaData.index(concreteIndex);
|
||||
if (indexMetaData.getState() == IndexMetaData.State.CLOSE) {
|
||||
unavailableException = new IndexClosedException(new Index(metaData.index(request.index()).getIndex()));
|
||||
unavailableException = new IndexClosedException(metaData.index(request.index()).getIndex());
|
||||
}
|
||||
}
|
||||
if (unavailableException != null) {
|
||||
|
|
|
@ -92,7 +92,7 @@ public class DeleteRequest extends ReplicationRequest<DeleteRequest> implements
|
|||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public DeleteRequest(DeleteRequest request, ActionRequest originalRequest) {
|
||||
super(request, originalRequest);
|
||||
super(request);
|
||||
this.type = request.type();
|
||||
this.id = request.id();
|
||||
this.routing = request.routing();
|
||||
|
@ -102,14 +102,6 @@ public class DeleteRequest extends ReplicationRequest<DeleteRequest> implements
|
|||
this.versionType = request.versionType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a delete request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public DeleteRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
ActionRequestValidationException validationException = super.validate();
|
||||
|
|
|
@ -72,7 +72,7 @@ public class TransportDeleteAction extends TransportReplicationAction<DeleteRequ
|
|||
protected void doExecute(final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
|
||||
ClusterState state = clusterService.state();
|
||||
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
|
||||
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
|
||||
createIndexAction.execute(new CreateIndexRequest().index(request.index()).cause("auto(delete api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
|
||||
@Override
|
||||
public void onResponse(CreateIndexResponse result) {
|
||||
innerExecute(request, listener);
|
||||
|
|
|
@ -108,7 +108,7 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
|||
Term uidTerm = new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(request.type(), request.id()));
|
||||
Engine.GetResult result = indexShard.get(new Engine.Get(false, uidTerm));
|
||||
if (!result.exists()) {
|
||||
return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), false);
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), false);
|
||||
}
|
||||
|
||||
SearchContext context = new DefaultSearchContext(
|
||||
|
@ -134,9 +134,9 @@ public class TransportExplainAction extends TransportSingleShardAction<ExplainRe
|
|||
// because we are working in the same searcher in engineGetResult we can be sure that a
|
||||
// doc isn't deleted between the initial get and this call.
|
||||
GetResult getResult = indexShard.getService().get(result, request.id(), request.type(), request.fields(), request.fetchSourceContext(), false);
|
||||
return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), true, explanation, getResult);
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation, getResult);
|
||||
} else {
|
||||
return new ExplainResponse(shardId.getIndex(), request.type(), request.id(), true, explanation);
|
||||
return new ExplainResponse(shardId.getIndexName(), request.type(), request.id(), true, explanation);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Could not explain", e);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.RealtimeRequest;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
|
@ -72,8 +71,7 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
|||
* Copy constructor that creates a new get request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public GetRequest(GetRequest getRequest, ActionRequest originalRequest) {
|
||||
super(originalRequest);
|
||||
public GetRequest(GetRequest getRequest) {
|
||||
this.index = getRequest.index;
|
||||
this.type = getRequest.type;
|
||||
this.id = getRequest.id;
|
||||
|
@ -98,14 +96,6 @@ public class GetRequest extends SingleShardRequest<GetRequest> implements Realti
|
|||
this.type = "_all";
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new get request starting from the provided request, meaning that it will
|
||||
* inherit its headers and context, and against the specified index.
|
||||
*/
|
||||
public GetRequest(ActionRequest request, String index) {
|
||||
super(request, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new get request against the specified index with the type and id.
|
||||
*
|
||||
|
|
|
@ -266,18 +266,6 @@ public class MultiGetRequest extends ActionRequest<MultiGetRequest> implements I
|
|||
|
||||
List<Item> items = new ArrayList<>();
|
||||
|
||||
public MultiGetRequest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a multi get request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public MultiGetRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
public List<Item> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public class MultiGetShardRequest extends SingleShardRequest<MultiGetShardReques
|
|||
}
|
||||
|
||||
MultiGetShardRequest(MultiGetRequest multiGetRequest, String index, int shardId) {
|
||||
super(multiGetRequest, index);
|
||||
super(index);
|
||||
this.shardId = shardId;
|
||||
locations = new IntArrayList();
|
||||
items = new ArrayList<>();
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TransportMultiGetAction extends HandledTransportAction<MultiGetRequ
|
|||
.getShards(clusterState, concreteSingleIndex, item.type(), item.id(), item.routing(), null).shardId();
|
||||
MultiGetShardRequest shardRequest = shardRequests.get(shardId);
|
||||
if (shardRequest == null) {
|
||||
shardRequest = new MultiGetShardRequest(request, shardId.index().name(), shardId.id());
|
||||
shardRequest = new MultiGetShardRequest(request, shardId.getIndexName(), shardId.id());
|
||||
shardRequests.put(shardId, shardRequest);
|
||||
}
|
||||
shardRequest.add(i, item);
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.action.index;
|
|||
|
||||
import org.elasticsearch.ElasticsearchGenerationException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.DocumentRequest;
|
||||
import org.elasticsearch.action.RoutingMissingException;
|
||||
|
@ -160,20 +159,12 @@ public class IndexRequest extends ReplicationRequest<IndexRequest> implements Do
|
|||
public IndexRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an index request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public IndexRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new index request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public IndexRequest(IndexRequest indexRequest, ActionRequest originalRequest) {
|
||||
super(indexRequest, originalRequest);
|
||||
public IndexRequest(IndexRequest indexRequest) {
|
||||
super(indexRequest);
|
||||
this.type = indexRequest.type;
|
||||
this.id = indexRequest.id;
|
||||
this.routing = indexRequest.routing;
|
||||
|
|
|
@ -88,7 +88,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
|
|||
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
|
||||
ClusterState state = clusterService.state();
|
||||
if (autoCreateIndex.shouldAutoCreate(request.index(), state)) {
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest(request);
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
|
||||
createIndexRequest.index(request.index());
|
||||
createIndexRequest.mapping(request.type());
|
||||
createIndexRequest.cause("auto(index api)");
|
||||
|
@ -146,7 +146,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
|
|||
MappingMetaData mappingMd = indexMetaData.mappingOrDefault(request.type());
|
||||
if (mappingMd != null && mappingMd.routing().required()) {
|
||||
if (request.routing() == null) {
|
||||
throw new RoutingMissingException(request.shardId().getIndex(), request.type(), request.id());
|
||||
throw new RoutingMissingException(request.shardId().getIndex().getName(), request.type(), request.id());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
|
|||
*/
|
||||
public static Engine.Index executeIndexRequestOnReplica(IndexRequest request, IndexShard indexShard) {
|
||||
final ShardId shardId = indexShard.shardId();
|
||||
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.REPLICA, request.source()).index(shardId.getIndex()).type(request.type()).id(request.id())
|
||||
SourceToParse sourceToParse = SourceToParse.source(SourceToParse.Origin.REPLICA, request.source()).index(shardId.getIndexName()).type(request.type()).id(request.id())
|
||||
.routing(request.routing()).parent(request.parent()).timestamp(request.timestamp()).ttl(request.ttl());
|
||||
|
||||
final Engine.Index operation = indexShard.prepareIndexOnReplica(sourceToParse, request.version(), request.versionType());
|
||||
|
@ -204,7 +204,7 @@ public class TransportIndexAction extends TransportReplicationAction<IndexReques
|
|||
Mapping update = operation.parsedDoc().dynamicMappingsUpdate();
|
||||
final ShardId shardId = indexShard.shardId();
|
||||
if (update != null) {
|
||||
final String indexName = shardId.getIndex();
|
||||
final String indexName = shardId.getIndexName();
|
||||
mappingUpdatedAction.updateMappingOnMasterSynchronously(indexName, request.type(), update);
|
||||
operation = prepareIndexOperationOnPrimary(request, indexShard);
|
||||
update = operation.parsedDoc().dynamicMappingsUpdate();
|
||||
|
|
|
@ -158,7 +158,7 @@ public final class IngestActionFilter extends AbstractComponent implements Actio
|
|||
if (itemResponses.isEmpty()) {
|
||||
return bulkRequest;
|
||||
} else {
|
||||
BulkRequest modifiedBulkRequest = new BulkRequest(bulkRequest);
|
||||
BulkRequest modifiedBulkRequest = new BulkRequest();
|
||||
modifiedBulkRequest.refresh(bulkRequest.refresh());
|
||||
modifiedBulkRequest.consistencyLevel(bulkRequest.consistencyLevel());
|
||||
modifiedBulkRequest.timeout(bulkRequest.timeout());
|
||||
|
|
|
@ -66,7 +66,6 @@ public class PercolateRequest extends BroadcastRequest<PercolateRequest> impleme
|
|||
}
|
||||
|
||||
PercolateRequest(PercolateRequest request, BytesReference docSource) {
|
||||
super(request);
|
||||
this.indices = request.indices();
|
||||
this.documentType = request.documentType();
|
||||
this.routing = request.routing();
|
||||
|
@ -274,7 +273,7 @@ public class PercolateRequest extends BroadcastRequest<PercolateRequest> impleme
|
|||
source = in.readBytesReference();
|
||||
docSource = in.readBytesReference();
|
||||
if (in.readBoolean()) {
|
||||
getRequest = new GetRequest(null);
|
||||
getRequest = new GetRequest();
|
||||
getRequest.readFrom(in);
|
||||
}
|
||||
onlyCount = in.readBoolean();
|
||||
|
|
|
@ -57,7 +57,7 @@ public class PercolateShardResponse extends BroadcastShardResponse {
|
|||
}
|
||||
|
||||
public PercolateShardResponse(TopDocs topDocs, Map<Integer, String> ids, Map<Integer, Map<String, HighlightField>> hls, PercolateContext context) {
|
||||
super(new ShardId(context.shardTarget().getIndex(), context.shardTarget().getShardId()));
|
||||
super(context.indexShard().shardId());
|
||||
this.topDocs = topDocs;
|
||||
this.ids = ids;
|
||||
this.hls = hls;
|
||||
|
|
|
@ -97,7 +97,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
|
|||
}
|
||||
|
||||
if (!existingDocsRequests.isEmpty()) {
|
||||
final MultiGetRequest multiGetRequest = new MultiGetRequest(request);
|
||||
final MultiGetRequest multiGetRequest = new MultiGetRequest();
|
||||
for (GetRequest getRequest : existingDocsRequests) {
|
||||
multiGetRequest.add(
|
||||
new MultiGetRequest.Item(getRequest.index(), getRequest.type(), getRequest.id())
|
||||
|
@ -200,7 +200,7 @@ public class TransportMultiPercolateAction extends HandledTransportAction<MultiP
|
|||
ShardId shardId = shard.shardId();
|
||||
TransportShardMultiPercolateAction.Request requests = requestsByShard.get(shardId);
|
||||
if (requests == null) {
|
||||
requestsByShard.put(shardId, requests = new TransportShardMultiPercolateAction.Request(multiPercolateRequest, shardId.getIndex(), shardId.getId(), percolateRequest.preference()));
|
||||
requestsByShard.put(shardId, requests = new TransportShardMultiPercolateAction.Request(shardId.getIndexName(), shardId.getId(), percolateRequest.preference()));
|
||||
}
|
||||
logger.trace("Adding shard[{}] percolate request for item[{}]", shardId, slot);
|
||||
requests.add(new TransportShardMultiPercolateAction.Request.Item(slot, new PercolateShardRequest(shardId, percolateRequest)));
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TransportPercolateAction extends TransportBroadcastAction<Percolate
|
|||
request.startTime = System.currentTimeMillis();
|
||||
if (request.getRequest() != null) {
|
||||
//create a new get request to make sure it has the same headers and context as the original percolate request
|
||||
GetRequest getRequest = new GetRequest(request.getRequest(), request);
|
||||
GetRequest getRequest = new GetRequest(request.getRequest());
|
||||
getAction.execute(getRequest, new ActionListener<GetResponse>() {
|
||||
@Override
|
||||
public void onResponse(GetResponse getResponse) {
|
||||
|
@ -150,7 +150,7 @@ public class TransportPercolateAction extends TransportBroadcastAction<Percolate
|
|||
} else {
|
||||
PercolatorService.ReduceResult result = null;
|
||||
try {
|
||||
result = percolatorService.reduce(onlyCount, shardResults, request);
|
||||
result = percolatorService.reduce(onlyCount, shardResults);
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("error during reduce phase", e);
|
||||
}
|
||||
|
|
|
@ -117,8 +117,8 @@ public class TransportShardMultiPercolateAction extends TransportSingleShardActi
|
|||
public Request() {
|
||||
}
|
||||
|
||||
Request(MultiPercolateRequest multiPercolateRequest, String concreteIndex, int shardId, String preference) {
|
||||
super(multiPercolateRequest, concreteIndex);
|
||||
Request(String concreteIndex, int shardId, String preference) {
|
||||
super(concreteIndex);
|
||||
this.shardId = shardId;
|
||||
this.preference = preference;
|
||||
this.items = new ArrayList<>();
|
||||
|
|
|
@ -37,17 +37,6 @@ public class ClearScrollRequest extends ActionRequest<ClearScrollRequest> {
|
|||
|
||||
private List<String> scrollIds;
|
||||
|
||||
public ClearScrollRequest() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a clear scroll request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public ClearScrollRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
public List<String> getScrollIds() {
|
||||
return scrollIds;
|
||||
}
|
||||
|
|
|
@ -80,8 +80,7 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
|||
* Copy constructor that creates a new search request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
public SearchRequest(SearchRequest searchRequest, ActionRequest originalRequest) {
|
||||
super(originalRequest);
|
||||
public SearchRequest(SearchRequest searchRequest) {
|
||||
this.searchType = searchRequest.searchType;
|
||||
this.indices = searchRequest.indices;
|
||||
this.routing = searchRequest.routing;
|
||||
|
@ -94,15 +93,6 @@ public class SearchRequest extends ActionRequest<SearchRequest> implements Indic
|
|||
this.indicesOptions = searchRequest.indicesOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search request starting from the provided request, meaning that it will
|
||||
* inherit its headers and context
|
||||
*/
|
||||
public SearchRequest(ActionRequest request) {
|
||||
super(request);
|
||||
this.source = new SearchSourceBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new search request against the indices. No indices provided here means that search
|
||||
* will run against all indices.
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.index.query.QueryBuilder;
|
|||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.Template;
|
||||
import org.elasticsearch.search.Scroll;
|
||||
import org.elasticsearch.search.searchafter.SearchAfterBuilder;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.fetch.innerhits.InnerHitsBuilder;
|
||||
|
|
|
@ -46,14 +46,6 @@ public class SearchScrollRequest extends ActionRequest<SearchScrollRequest> {
|
|||
this.scrollId = scrollId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a scroll request caused by some other request, which is provided as an
|
||||
* argument so that its headers and context can be copied to the new request
|
||||
*/
|
||||
public SearchScrollRequest(ActionRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
ActionRequestValidationException validationException = null;
|
||||
|
|
|
@ -59,7 +59,7 @@ public class TransportMultiSearchAction extends HandledTransportAction<MultiSear
|
|||
final AtomicInteger counter = new AtomicInteger(responses.length());
|
||||
for (int i = 0; i < responses.length(); i++) {
|
||||
final int index = i;
|
||||
SearchRequest searchRequest = new SearchRequest(request.requests().get(i), request);
|
||||
SearchRequest searchRequest = new SearchRequest(request.requests().get(i));
|
||||
searchAction.execute(searchRequest, new ActionListener<SearchResponse>() {
|
||||
@Override
|
||||
public void onResponse(SearchResponse searchResponse) {
|
||||
|
|
|
@ -135,7 +135,7 @@ public class TransportSearchDfsQueryAndFetchAction extends TransportSearchTypeAc
|
|||
public void doRun() throws IOException {
|
||||
sortedShardList = searchPhaseController.sortDocs(true, queryFetchResults);
|
||||
final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryFetchResults,
|
||||
queryFetchResults, request);
|
||||
queryFetchResults);
|
||||
String scrollId = null;
|
||||
if (request.scroll() != null) {
|
||||
scrollId = TransportSearchHelper.buildScrollId(request.searchType(), firstResults, null);
|
||||
|
|
|
@ -211,7 +211,7 @@ public class TransportSearchDfsQueryThenFetchAction extends TransportSearchTypeA
|
|||
@Override
|
||||
public void doRun() throws IOException {
|
||||
final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryResults,
|
||||
fetchResults, request);
|
||||
fetchResults);
|
||||
String scrollId = null;
|
||||
if (request.scroll() != null) {
|
||||
scrollId = TransportSearchHelper.buildScrollId(request.searchType(), firstResults, null);
|
||||
|
|
|
@ -82,7 +82,7 @@ public class TransportSearchQueryAndFetchAction extends TransportSearchTypeActio
|
|||
boolean useScroll = request.scroll() != null;
|
||||
sortedShardList = searchPhaseController.sortDocs(useScroll, firstResults);
|
||||
final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, firstResults,
|
||||
firstResults, request);
|
||||
firstResults);
|
||||
String scrollId = null;
|
||||
if (request.scroll() != null) {
|
||||
scrollId = buildScrollId(request.searchType(), firstResults, null);
|
||||
|
|
|
@ -146,7 +146,7 @@ public class TransportSearchQueryThenFetchAction extends TransportSearchTypeActi
|
|||
@Override
|
||||
public void doRun() throws IOException {
|
||||
final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, firstResults,
|
||||
fetchResults, request);
|
||||
fetchResults);
|
||||
String scrollId = null;
|
||||
if (request.scroll() != null) {
|
||||
scrollId = TransportSearchHelper.buildScrollId(request.searchType(), firstResults, null);
|
||||
|
|
|
@ -193,7 +193,7 @@ public class TransportSearchScrollQueryAndFetchAction extends AbstractComponent
|
|||
private void innerFinishHim() throws Exception {
|
||||
ScoreDoc[] sortedShardList = searchPhaseController.sortDocs(true, queryFetchResults);
|
||||
final InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryFetchResults,
|
||||
queryFetchResults, request);
|
||||
queryFetchResults);
|
||||
String scrollId = null;
|
||||
if (request.scroll() != null) {
|
||||
scrollId = request.scrollId();
|
||||
|
|
|
@ -208,7 +208,7 @@ public class TransportSearchScrollQueryThenFetchAction extends AbstractComponent
|
|||
IntArrayList docIds = entry.value;
|
||||
final QuerySearchResult querySearchResult = queryResults.get(entry.index);
|
||||
ScoreDoc lastEmittedDoc = lastEmittedDocPerShard[entry.index];
|
||||
ShardFetchRequest shardFetchRequest = new ShardFetchRequest(request, querySearchResult.id(), docIds, lastEmittedDoc);
|
||||
ShardFetchRequest shardFetchRequest = new ShardFetchRequest(querySearchResult.id(), docIds, lastEmittedDoc);
|
||||
DiscoveryNode node = nodes.get(querySearchResult.shardTarget().nodeId());
|
||||
searchService.sendExecuteFetchScroll(node, shardFetchRequest, new ActionListener<FetchSearchResult>() {
|
||||
@Override
|
||||
|
@ -243,7 +243,7 @@ public class TransportSearchScrollQueryThenFetchAction extends AbstractComponent
|
|||
}
|
||||
|
||||
private void innerFinishHim() {
|
||||
InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryResults, fetchResults, request);
|
||||
InternalSearchResponse internalResponse = searchPhaseController.merge(sortedShardList, queryResults, fetchResults);
|
||||
String scrollId = null;
|
||||
if (request.scroll() != null) {
|
||||
scrollId = request.scrollId();
|
||||
|
|
|
@ -163,7 +163,7 @@ public abstract class TransportSearchTypeAction extends TransportAction<SearchRe
|
|||
if (node == null) {
|
||||
onFirstPhaseResult(shardIndex, shard, null, shardIt, new NoShardAvailableActionException(shardIt.shardId()));
|
||||
} else {
|
||||
String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterState, shard.index(), request.indices());
|
||||
String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterState, shard.index().getName(), request.indices());
|
||||
sendExecuteFirstPhase(node, internalSearchRequest(shard, shardsIts.size(), request, filteringAliases, startTime()), new ActionListener<FirstResult>() {
|
||||
@Override
|
||||
public void onResponse(FirstResult result) {
|
||||
|
|
|
@ -143,7 +143,7 @@ public class TransportSuggestAction extends TransportBroadcastAction<SuggestRequ
|
|||
throw new IllegalArgumentException("suggest content missing");
|
||||
}
|
||||
final SuggestionSearchContext context = suggestPhase.parseElement().parseInternal(parser, indexService.mapperService(),
|
||||
indexService.fieldData(), request.shardId().getIndex(), request.shardId().id(), request);
|
||||
indexService.fieldData(), request.shardId().getIndexName(), request.shardId().id());
|
||||
final Suggest result = suggestPhase.execute(context, searcher.searcher());
|
||||
return new ShardSuggestResponse(request.shardId(), result);
|
||||
}
|
||||
|
|
|
@ -23,111 +23,100 @@ import org.elasticsearch.cluster.ClusterState;
|
|||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||
import org.elasticsearch.common.Booleans;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.regex.Regex;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Encapsulates the logic of whether a new index should be automatically created when
|
||||
* a write operation is about to happen in a non existing index.
|
||||
*/
|
||||
public final class AutoCreateIndex {
|
||||
|
||||
private final boolean needToCheck;
|
||||
private final boolean globallyDisabled;
|
||||
private final boolean dynamicMappingDisabled;
|
||||
private final String[] matches;
|
||||
private final String[] matches2;
|
||||
private final IndexNameExpressionResolver resolver;
|
||||
public static final Setting<AutoCreate> AUTO_CREATE_INDEX_SETTING = new Setting<>("action.auto_create_index", "true", AutoCreate::new, false, Setting.Scope.CLUSTER);
|
||||
|
||||
private final boolean dynamicMappingDisabled;
|
||||
private final IndexNameExpressionResolver resolver;
|
||||
private final AutoCreate autoCreate;
|
||||
|
||||
@Inject
|
||||
public AutoCreateIndex(Settings settings, IndexNameExpressionResolver resolver) {
|
||||
this.resolver = resolver;
|
||||
dynamicMappingDisabled = !MapperService.INDEX_MAPPER_DYNAMIC_SETTING.get(settings);
|
||||
final AutoCreate autoCreate = AUTO_CREATE_INDEX_SETTING.get(settings);
|
||||
if (autoCreate.autoCreateIndex) {
|
||||
needToCheck = true;
|
||||
globallyDisabled = false;
|
||||
matches = autoCreate.indices;
|
||||
if (matches != null) {
|
||||
matches2 = new String[matches.length];
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
matches2[i] = matches[i].substring(1);
|
||||
}
|
||||
} else {
|
||||
matches2 = null;
|
||||
}
|
||||
} else {
|
||||
needToCheck = false;
|
||||
globallyDisabled = true;
|
||||
matches = null;
|
||||
matches2 = null;
|
||||
}
|
||||
this.autoCreate = AUTO_CREATE_INDEX_SETTING.get(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do we really need to check if an index should be auto created?
|
||||
*/
|
||||
public boolean needToCheck() {
|
||||
return this.needToCheck;
|
||||
return this.autoCreate.autoCreateIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the index be auto created?
|
||||
*/
|
||||
public boolean shouldAutoCreate(String index, ClusterState state) {
|
||||
if (!needToCheck) {
|
||||
if (autoCreate.autoCreateIndex == false) {
|
||||
return false;
|
||||
}
|
||||
boolean exists = resolver.hasIndexOrAlias(index, state);
|
||||
if (exists) {
|
||||
if (dynamicMappingDisabled) {
|
||||
return false;
|
||||
}
|
||||
if (globallyDisabled || dynamicMappingDisabled) {
|
||||
if (resolver.hasIndexOrAlias(index, state)) {
|
||||
return false;
|
||||
}
|
||||
// matches not set, default value of "true"
|
||||
if (matches == null) {
|
||||
if (autoCreate.expressions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < matches.length; i++) {
|
||||
char c = matches[i].charAt(0);
|
||||
if (c == '-') {
|
||||
if (Regex.simpleMatch(matches2[i], index)) {
|
||||
return false;
|
||||
}
|
||||
} else if (c == '+') {
|
||||
if (Regex.simpleMatch(matches2[i], index)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (Regex.simpleMatch(matches[i], index)) {
|
||||
return true;
|
||||
}
|
||||
for (Tuple<String, Boolean> expression : autoCreate.expressions) {
|
||||
String indexExpression = expression.v1();
|
||||
boolean include = expression.v2();
|
||||
if (Regex.simpleMatch(indexExpression, index)) {
|
||||
return include;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class AutoCreate {
|
||||
private static class AutoCreate {
|
||||
private final boolean autoCreateIndex;
|
||||
private final String[] indices;
|
||||
private final List<Tuple<String, Boolean>> expressions;
|
||||
|
||||
public AutoCreate(String value) {
|
||||
private AutoCreate(String value) {
|
||||
boolean autoCreateIndex;
|
||||
String[] indices = null;
|
||||
List<Tuple<String, Boolean>> expressions = new ArrayList<>();
|
||||
try {
|
||||
autoCreateIndex = Booleans.parseBooleanExact(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
try {
|
||||
indices = Strings.commaDelimitedListToStringArray(value);
|
||||
for (String string : indices) {
|
||||
if (string == null || string.length() == 0) {
|
||||
throw new IllegalArgumentException("Can't parse [" + value + "] for setting [action.auto_create_index] must be either [true, false, or a comma seperated list of index patterns]");
|
||||
String[] patterns = Strings.commaDelimitedListToStringArray(value);
|
||||
for (String pattern : patterns) {
|
||||
if (pattern == null || pattern.length() == 0) {
|
||||
throw new IllegalArgumentException("Can't parse [" + value + "] for setting [action.auto_create_index] must be either [true, false, or a comma separated list of index patterns]");
|
||||
}
|
||||
Tuple<String, Boolean> expression;
|
||||
if (pattern.startsWith("-")) {
|
||||
if (pattern.length() == 1) {
|
||||
throw new IllegalArgumentException("Can't parse [" + value + "] for setting [action.auto_create_index] must contain an index name after [-]");
|
||||
}
|
||||
expression = new Tuple<>(pattern.substring(1), false);
|
||||
} else if(pattern.startsWith("+")) {
|
||||
if (pattern.length() == 1) {
|
||||
throw new IllegalArgumentException("Can't parse [" + value + "] for setting [action.auto_create_index] must contain an index name after [+]");
|
||||
}
|
||||
expression = new Tuple<>(pattern.substring(1), true);
|
||||
} else {
|
||||
expression = new Tuple<>(pattern, true);
|
||||
}
|
||||
expressions.add(expression);
|
||||
}
|
||||
autoCreateIndex = true;
|
||||
} catch (IllegalArgumentException ex1) {
|
||||
|
@ -135,7 +124,7 @@ public final class AutoCreateIndex {
|
|||
throw ex1;
|
||||
}
|
||||
}
|
||||
this.indices = indices;
|
||||
this.expressions = expressions;
|
||||
this.autoCreateIndex = autoCreateIndex;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,11 +38,6 @@ public class ChildTaskRequest extends TransportRequest {
|
|||
private long parentTaskId;
|
||||
|
||||
protected ChildTaskRequest() {
|
||||
|
||||
}
|
||||
|
||||
protected ChildTaskRequest(TransportRequest parentTaskRequest) {
|
||||
super(parentTaskRequest);
|
||||
}
|
||||
|
||||
public void setParentTask(String parentTaskNode, long parentTaskId) {
|
||||
|
|
|
@ -48,7 +48,7 @@ public class DefaultShardOperationFailedException implements ShardOperationFaile
|
|||
}
|
||||
|
||||
public DefaultShardOperationFailedException(ElasticsearchException e) {
|
||||
this.index = e.getIndex();
|
||||
this.index = e.getIndex() == null ? null : e.getIndex().getName();
|
||||
this.shardId = e.getShardId().id();
|
||||
this.reason = e;
|
||||
this.status = e.status();
|
||||
|
|
|
@ -50,7 +50,7 @@ public final class ThreadedActionListener<Response> implements ActionListener<Re
|
|||
this.threadPool = threadPool;
|
||||
// Should the action listener be threaded or not by default. Action listeners are automatically threaded for client
|
||||
// nodes and transport client in order to make sure client side code is not executed on IO threads.
|
||||
this.threadedListener = DiscoveryNode.clientNode(settings) || TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING));
|
||||
this.threadedListener = DiscoveryNode.clientNode(settings) || TransportClient.CLIENT_TYPE.equals(Client.CLIENT_TYPE_SETTING_S.get(settings));
|
||||
}
|
||||
|
||||
public <Response> ActionListener<Response> wrap(ActionListener<Response> listener) {
|
||||
|
|
|
@ -37,11 +37,6 @@ public class BroadcastRequest<Request extends BroadcastRequest<Request>> extends
|
|||
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosed();
|
||||
|
||||
public BroadcastRequest() {
|
||||
|
||||
}
|
||||
|
||||
protected BroadcastRequest(ActionRequest<?> originalRequest) {
|
||||
super(originalRequest);
|
||||
}
|
||||
|
||||
protected BroadcastRequest(String[] indices) {
|
||||
|
|
|
@ -42,7 +42,6 @@ public abstract class BroadcastShardRequest extends TransportRequest implements
|
|||
}
|
||||
|
||||
protected BroadcastShardRequest(ShardId shardId, BroadcastRequest request) {
|
||||
super(request);
|
||||
this.shardId = shardId;
|
||||
this.originalIndices = new OriginalIndices(request);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class BroadcastShardResponse extends TransportResponse {
|
|||
}
|
||||
|
||||
public String getIndex() {
|
||||
return this.shardId.getIndex();
|
||||
return this.shardId.getIndexName();
|
||||
}
|
||||
|
||||
public int getShardId() {
|
||||
|
|
|
@ -118,7 +118,7 @@ public abstract class TransportBroadcastByNodeAction<Request extends BroadcastRe
|
|||
FailedNodeException exception = (FailedNodeException) responses.get(i);
|
||||
totalShards += nodes.get(exception.nodeId()).size();
|
||||
for (ShardRouting shard : nodes.get(exception.nodeId())) {
|
||||
exceptions.add(new DefaultShardOperationFailedException(shard.getIndex(), shard.getId(), exception));
|
||||
exceptions.add(new DefaultShardOperationFailedException(shard.getIndexName(), shard.getId(), exception));
|
||||
}
|
||||
} else {
|
||||
NodeResponse response = (NodeResponse) responses.get(i);
|
||||
|
@ -127,7 +127,7 @@ public abstract class TransportBroadcastByNodeAction<Request extends BroadcastRe
|
|||
successfulShards += response.getSuccessfulShards();
|
||||
for (BroadcastShardOperationFailedException throwable : response.getExceptions()) {
|
||||
if (!TransportActions.isShardNotAvailableException(throwable)) {
|
||||
exceptions.add(new DefaultShardOperationFailedException(throwable.getIndex(), throwable.getShardId().getId(), throwable));
|
||||
exceptions.add(new DefaultShardOperationFailedException(throwable.getShardId().getIndexName(), throwable.getShardId().getId(), throwable));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ public abstract class TransportBroadcastByNodeAction<Request extends BroadcastRe
|
|||
}
|
||||
} catch (Throwable t) {
|
||||
BroadcastShardOperationFailedException e = new BroadcastShardOperationFailedException(shardRouting.shardId(), "operation " + actionName + " failed", t);
|
||||
e.setIndex(shardRouting.getIndex());
|
||||
e.setIndex(shardRouting.getIndexName());
|
||||
e.setShard(shardRouting.shardId());
|
||||
shardResults[shardIndex] = e;
|
||||
if (TransportActions.isShardNotAvailableException(t)) {
|
||||
|
@ -433,7 +433,6 @@ public abstract class TransportBroadcastByNodeAction<Request extends BroadcastRe
|
|||
}
|
||||
|
||||
public NodeRequest(String nodeId, Request request, List<ShardRouting> shards) {
|
||||
super(request);
|
||||
this.indicesLevelRequest = request;
|
||||
this.shards = shards;
|
||||
this.nodeId = nodeId;
|
||||
|
|
|
@ -42,10 +42,6 @@ public abstract class AcknowledgedRequest<Request extends MasterNodeRequest<Requ
|
|||
protected AcknowledgedRequest() {
|
||||
}
|
||||
|
||||
protected AcknowledgedRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to set the timeout
|
||||
* @param timeout timeout as a string (e.g. 1s)
|
||||
|
|
|
@ -36,11 +36,6 @@ public abstract class MasterNodeRequest<Request extends MasterNodeRequest<Reques
|
|||
protected TimeValue masterNodeTimeout = DEFAULT_MASTER_NODE_TIMEOUT;
|
||||
|
||||
protected MasterNodeRequest() {
|
||||
|
||||
}
|
||||
|
||||
protected MasterNodeRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -121,7 +121,7 @@ public abstract class TransportMasterNodeAction<Request extends MasterNodeReques
|
|||
}
|
||||
|
||||
public void start() {
|
||||
this.observer = new ClusterStateObserver(clusterService, request.masterNodeTimeout(), logger);
|
||||
this.observer = new ClusterStateObserver(clusterService, request.masterNodeTimeout(), logger, threadPool.getThreadContext());
|
||||
doStart();
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,7 @@ public abstract class BaseNodeRequest extends ChildTaskRequest {
|
|||
|
||||
}
|
||||
|
||||
protected BaseNodeRequest(BaseNodesRequest request, String nodeId) {
|
||||
super(request);
|
||||
protected BaseNodeRequest(String nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,11 +43,6 @@ public abstract class BaseNodesRequest<Request extends BaseNodesRequest<Request>
|
|||
|
||||
}
|
||||
|
||||
protected BaseNodesRequest(ActionRequest<?> request, String... nodesIds) {
|
||||
super(request);
|
||||
this.nodesIds = nodesIds;
|
||||
}
|
||||
|
||||
protected BaseNodesRequest(String... nodesIds) {
|
||||
this.nodesIds = nodesIds;
|
||||
}
|
||||
|
|
|
@ -30,22 +30,13 @@ import org.elasticsearch.index.shard.ShardId;
|
|||
*/
|
||||
public class BasicReplicationRequest extends ReplicationRequest<BasicReplicationRequest> {
|
||||
public BasicReplicationRequest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new request that inherits headers and context from the request
|
||||
* provided as argument.
|
||||
*/
|
||||
public BasicReplicationRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new request with resolved shard id
|
||||
*/
|
||||
public BasicReplicationRequest(ActionRequest<?> request, ShardId shardId) {
|
||||
super(request, shardId);
|
||||
public BasicReplicationRequest(ShardId shardId) {
|
||||
super(shardId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,35 +58,20 @@ public abstract class ReplicationRequest<Request extends ReplicationRequest<Requ
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new request that inherits headers and context from the request provided as argument.
|
||||
*/
|
||||
public ReplicationRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new request with resolved shard id
|
||||
*/
|
||||
public ReplicationRequest(ActionRequest<?> request, ShardId shardId) {
|
||||
super(request);
|
||||
this.index = shardId.getIndex();
|
||||
public ReplicationRequest(ShardId shardId) {
|
||||
this.index = shardId.getIndexName();
|
||||
this.shardId = shardId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new request that is a copy of the one provided as an argument.
|
||||
*/
|
||||
protected ReplicationRequest(Request request) {
|
||||
this(request, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor that creates a new request that is a copy of the one provided as an argument.
|
||||
* The new request will inherit though headers and context from the original request that caused it.
|
||||
*/
|
||||
protected ReplicationRequest(Request request, ActionRequest<?> originalRequest) {
|
||||
super(originalRequest);
|
||||
protected ReplicationRequest(Request request) {
|
||||
this.timeout = request.timeout();
|
||||
this.index = request.index();
|
||||
this.consistencyLevel = request.consistencyLevel();
|
||||
|
|
|
@ -90,13 +90,13 @@ public abstract class TransportBroadcastReplicationAction<Request extends Broadc
|
|||
@Override
|
||||
public void onFailure(Throwable e) {
|
||||
logger.trace("{}: got failure from {}", actionName, shardId);
|
||||
int totalNumCopies = clusterState.getMetaData().index(shardId.index().getName()).getNumberOfReplicas() + 1;
|
||||
int totalNumCopies = clusterState.getMetaData().index(shardId.getIndexName()).getNumberOfReplicas() + 1;
|
||||
ShardResponse shardResponse = newShardResponse();
|
||||
ReplicationResponse.ShardInfo.Failure[] failures;
|
||||
if (TransportActions.isShardNotAvailableException(e)) {
|
||||
failures = new ReplicationResponse.ShardInfo.Failure[0];
|
||||
} else {
|
||||
ReplicationResponse.ShardInfo.Failure failure = new ReplicationResponse.ShardInfo.Failure(shardId.index().name(), shardId.id(), null, e, ExceptionsHelper.status(e), true);
|
||||
ReplicationResponse.ShardInfo.Failure failure = new ReplicationResponse.ShardInfo.Failure(shardId, null, e, ExceptionsHelper.status(e), true);
|
||||
failures = new ReplicationResponse.ShardInfo.Failure[totalNumCopies];
|
||||
Arrays.fill(failures, failure);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public abstract class TransportBroadcastReplicationAction<Request extends Broadc
|
|||
shardFailures = new ArrayList<>();
|
||||
}
|
||||
for (ReplicationResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
|
||||
shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(new ShardId(failure.index(), failure.shardId()), failure.getCause())));
|
||||
shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(failure.fullShardId(), failure.getCause())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.index.IndexService;
|
||||
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
||||
import org.elasticsearch.index.shard.IndexShard;
|
||||
|
@ -297,7 +298,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
private final TransportChannel channel;
|
||||
// important: we pass null as a timeout as failing a replica is
|
||||
// something we want to avoid at all costs
|
||||
private final ClusterStateObserver observer = new ClusterStateObserver(clusterService, null, logger);
|
||||
private final ClusterStateObserver observer = new ClusterStateObserver(clusterService, null, logger, threadPool.getThreadContext());
|
||||
|
||||
AsyncReplicaAction(ReplicaRequest request, TransportChannel channel) {
|
||||
this.request = request;
|
||||
|
@ -308,9 +309,12 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
public void onFailure(Throwable t) {
|
||||
if (t instanceof RetryOnReplicaException) {
|
||||
logger.trace("Retrying operation on replica, action [{}], request [{}]", t, transportReplicaAction, request);
|
||||
final ThreadContext threadContext = threadPool.getThreadContext();
|
||||
final ThreadContext.StoredContext context = threadPool.getThreadContext().newStoredContext();
|
||||
observer.waitForNextChange(new ClusterStateObserver.Listener() {
|
||||
@Override
|
||||
public void onNewClusterState(ClusterState state) {
|
||||
context.close();
|
||||
// Forking a thread on local node via transport service so that custom transport service have an
|
||||
// opportunity to execute custom logic before the replica operation begins
|
||||
String extraMessage = "action [" + transportReplicaAction + "], request[" + request + "]";
|
||||
|
@ -339,7 +343,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
}
|
||||
}
|
||||
private void failReplicaIfNeeded(Throwable t) {
|
||||
String index = request.shardId().getIndex();
|
||||
String index = request.shardId().getIndex().getName();
|
||||
int shardId = request.shardId().id();
|
||||
logger.trace("failure on replica [{}][{}], action [{}], request [{}]", t, index, shardId, actionName, request);
|
||||
if (ignoreReplicaException(t) == false) {
|
||||
|
@ -406,7 +410,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
ReroutePhase(Request request, ActionListener<Response> listener) {
|
||||
this.request = request;
|
||||
this.listener = listener;
|
||||
this.observer = new ClusterStateObserver(clusterService, request.timeout(), logger);
|
||||
this.observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -432,7 +436,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
resolveRequest(state.metaData(), concreteIndex, request);
|
||||
assert request.shardId() != null : "request shardId must be set in resolveRequest";
|
||||
|
||||
IndexShardRoutingTable indexShard = state.getRoutingTable().shardRoutingTable(request.shardId().getIndex(), request.shardId().id());
|
||||
IndexShardRoutingTable indexShard = state.getRoutingTable().shardRoutingTable(request.shardId());
|
||||
final ShardRouting primary = indexShard.primaryShard();
|
||||
if (primary == null || primary.active() == false) {
|
||||
logger.trace("primary shard [{}] is not yet active, scheduling a retry: action [{}], request [{}], cluster state version [{}]", request.shardId(), actionName, request, state.version());
|
||||
|
@ -510,9 +514,12 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
finishAsFailed(failure);
|
||||
return;
|
||||
}
|
||||
final ThreadContext threadContext = threadPool.getThreadContext();
|
||||
final ThreadContext.StoredContext context = threadPool.getThreadContext().newStoredContext();
|
||||
observer.waitForNextChange(new ClusterStateObserver.Listener() {
|
||||
@Override
|
||||
public void onNewClusterState(ClusterState state) {
|
||||
context.close();
|
||||
run();
|
||||
}
|
||||
|
||||
|
@ -523,6 +530,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
|
||||
@Override
|
||||
public void onTimeout(TimeValue timeout) {
|
||||
context.close();
|
||||
// Try one more time...
|
||||
run();
|
||||
}
|
||||
|
@ -637,7 +645,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
}
|
||||
final int sizeActive;
|
||||
final int requiredNumber;
|
||||
IndexRoutingTable indexRoutingTable = state.getRoutingTable().index(shardId.getIndex());
|
||||
IndexRoutingTable indexRoutingTable = state.getRoutingTable().index(shardId.getIndexName());
|
||||
if (indexRoutingTable != null) {
|
||||
IndexShardRoutingTable shardRoutingTable = indexRoutingTable.shard(shardId.getId());
|
||||
if (shardRoutingTable != null) {
|
||||
|
@ -702,7 +710,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
}
|
||||
|
||||
protected Releasable getIndexShardOperationsCounter(ShardId shardId) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.index().getName());
|
||||
IndexService indexService = indicesService.indexServiceSafe(shardId.getIndex());
|
||||
IndexShard indexShard = indexService.getShard(shardId.id());
|
||||
return new IndexShardReference(indexShard);
|
||||
}
|
||||
|
@ -941,9 +949,7 @@ public abstract class TransportReplicationAction<Request extends ReplicationRequ
|
|||
failuresArray = new ReplicationResponse.ShardInfo.Failure[shardReplicaFailures.size()];
|
||||
for (Map.Entry<String, Throwable> entry : shardReplicaFailures.entrySet()) {
|
||||
RestStatus restStatus = ExceptionsHelper.status(entry.getValue());
|
||||
failuresArray[slot++] = new ReplicationResponse.ShardInfo.Failure(
|
||||
shardId.getIndex(), shardId.getId(), entry.getKey(), entry.getValue(), restStatus, false
|
||||
);
|
||||
failuresArray[slot++] = new ReplicationResponse.ShardInfo.Failure(shardId, entry.getKey(), entry.getValue(), restStatus, false);
|
||||
}
|
||||
} else {
|
||||
failuresArray = ReplicationResponse.EMPTY;
|
||||
|
|
|
@ -124,7 +124,7 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
|
|||
}
|
||||
|
||||
public void start() {
|
||||
this.observer = new ClusterStateObserver(clusterService, request.timeout(), logger);
|
||||
this.observer = new ClusterStateObserver(clusterService, request.timeout(), logger, threadPool.getThreadContext());
|
||||
doStart();
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
|
|||
request.concreteIndex(indexNameExpressionResolver.concreteSingleIndex(observer.observedState(), request));
|
||||
// check if we need to execute, and if not, return
|
||||
if (!resolveRequest(observer.observedState(), request, listener)) {
|
||||
listener.onFailure(new IllegalStateException(LoggerMessageFormat.format("{} request {} could not be resolved", new ShardId(request.index, request.shardId), actionName)));
|
||||
listener.onFailure(new IllegalStateException(LoggerMessageFormat.format("[{}][{}] request {} could not be resolved",request.index, request.shardId, actionName)));
|
||||
return;
|
||||
}
|
||||
blockException = checkRequestBlock(observer.observedState(), request);
|
||||
|
@ -217,7 +217,7 @@ public abstract class TransportInstanceSingleOperationAction<Request extends Ins
|
|||
Throwable listenFailure = failure;
|
||||
if (listenFailure == null) {
|
||||
if (shardIt == null) {
|
||||
listenFailure = new UnavailableShardsException(new ShardId(request.concreteIndex(), -1), "Timeout waiting for [{}], request: {}", request.timeout(), actionName);
|
||||
listenFailure = new UnavailableShardsException(request.concreteIndex(), -1, "Timeout waiting for [{}], request: {}", request.timeout(), actionName);
|
||||
} else {
|
||||
listenFailure = new UnavailableShardsException(shardIt.shardId(), "[{}] shardIt, [{}] active : Timeout waiting for [{}], request: {}", shardIt.size(), shardIt.sizeActive(), request.timeout(), actionName);
|
||||
}
|
||||
|
|
|
@ -56,15 +56,6 @@ public abstract class SingleShardRequest<Request extends SingleShardRequest<Requ
|
|||
this.index = index;
|
||||
}
|
||||
|
||||
protected SingleShardRequest(ActionRequest<?> request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
protected SingleShardRequest(ActionRequest<?> request, String index) {
|
||||
super(request);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a validation exception if the index property hasn't been set
|
||||
*/
|
||||
|
|
|
@ -61,15 +61,6 @@ public class BaseTasksRequest<Request extends BaseTasksRequest<Request>> extends
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about tasks from nodes based on the nodes ids specified.
|
||||
* If none are passed, information for all nodes will be returned.
|
||||
*/
|
||||
public BaseTasksRequest(ActionRequest<?> request, String... nodesIds) {
|
||||
super(request);
|
||||
this.nodesIds = nodesIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about tasks from nodes based on the nodes ids specified.
|
||||
* If none are passed, information for all nodes will be returned.
|
||||
|
|
|
@ -291,7 +291,7 @@ public abstract class TransportTasksAction<
|
|||
}
|
||||
|
||||
protected NodeTaskRequest(TasksRequest tasksRequest) {
|
||||
super(tasksRequest);
|
||||
super();
|
||||
this.tasksRequest = tasksRequest;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ public class MultiTermVectorsShardRequest extends SingleShardRequest<MultiTermVe
|
|||
|
||||
}
|
||||
|
||||
MultiTermVectorsShardRequest(MultiTermVectorsRequest request, String index, int shardId) {
|
||||
super(request, index);
|
||||
MultiTermVectorsShardRequest(String index, int shardId) {
|
||||
super(index);
|
||||
this.shardId = shardId;
|
||||
locations = new IntArrayList();
|
||||
requests = new ArrayList<>();
|
||||
|
|
|
@ -82,7 +82,7 @@ public class TransportMultiTermVectorsAction extends HandledTransportAction<Mult
|
|||
termVectorsRequest.id(), termVectorsRequest.routing());
|
||||
MultiTermVectorsShardRequest shardRequest = shardRequests.get(shardId);
|
||||
if (shardRequest == null) {
|
||||
shardRequest = new MultiTermVectorsShardRequest(request, shardId.index().name(), shardId.id());
|
||||
shardRequest = new MultiTermVectorsShardRequest(shardId.getIndexName(), shardId.id());
|
||||
shardRequest.preference(request.preference);
|
||||
shardRequests.put(shardId, shardRequest);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class TransportDfsOnlyAction extends TransportBroadcastAction<DfsOnlyRequ
|
|||
|
||||
@Override
|
||||
protected ShardDfsOnlyRequest newShardRequest(int numShards, ShardRouting shard, DfsOnlyRequest request) {
|
||||
String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.index(), request.indices());
|
||||
String[] filteringAliases = indexNameExpressionResolver.filteringAliases(clusterService.state(), shard.index().getName(), request.indices());
|
||||
return new ShardDfsOnlyRequest(shard, numShards, filteringAliases, request.nowInMillis, request);
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
|||
protected void doExecute(final UpdateRequest request, final ActionListener<UpdateResponse> listener) {
|
||||
// if we don't have a master, we don't have metadata, that's fine, let it find a master using create index API
|
||||
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
|
||||
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
|
||||
createIndexAction.execute(new CreateIndexRequest().index(request.index()).cause("auto(update api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
|
||||
@Override
|
||||
public void onResponse(CreateIndexResponse result) {
|
||||
innerExecute(request, listener);
|
||||
|
@ -164,12 +164,12 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
|||
}
|
||||
|
||||
protected void shardOperation(final UpdateRequest request, final ActionListener<UpdateResponse> listener, final int retryCount) {
|
||||
IndexService indexService = indicesService.indexServiceSafe(request.concreteIndex());
|
||||
IndexShard indexShard = indexService.getShard(request.shardId());
|
||||
final IndexService indexService = indicesService.indexServiceSafe(request.concreteIndex());
|
||||
final IndexShard indexShard = indexService.getShard(request.shardId());
|
||||
final UpdateHelper.Result result = updateHelper.prepare(request, indexShard);
|
||||
switch (result.operation()) {
|
||||
case UPSERT:
|
||||
IndexRequest upsertRequest = new IndexRequest(result.action(), request);
|
||||
IndexRequest upsertRequest = new IndexRequest((IndexRequest)result.action());
|
||||
// we fetch it from the index request so we don't generate the bytes twice, its already done in the index request
|
||||
final BytesReference upsertSourceBytes = upsertRequest.source();
|
||||
indexAction.execute(upsertRequest, new ActionListener<IndexResponse>() {
|
||||
|
@ -206,7 +206,7 @@ public class TransportUpdateAction extends TransportInstanceSingleOperationActio
|
|||
});
|
||||
break;
|
||||
case INDEX:
|
||||
IndexRequest indexRequest = new IndexRequest(result.action(), request);
|
||||
IndexRequest indexRequest = new IndexRequest((IndexRequest)result.action());
|
||||
// we fetch it from the index request so we don't generate the bytes twice, its already done in the index request
|
||||
final BytesReference indexSourceBytes = indexRequest.source();
|
||||
indexAction.execute(indexRequest, new ActionListener<IndexResponse>() {
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
|
|||
import org.elasticsearch.index.shard.IndexShard;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.search.fetch.source.FetchSourceContext;
|
||||
|
@ -75,16 +76,15 @@ public class UpdateHelper extends AbstractComponent {
|
|||
final GetResult getResult = indexShard.getService().get(request.type(), request.id(),
|
||||
new String[]{RoutingFieldMapper.NAME, ParentFieldMapper.NAME, TTLFieldMapper.NAME, TimestampFieldMapper.NAME},
|
||||
true, request.version(), request.versionType(), FetchSourceContext.FETCH_SOURCE, false);
|
||||
return prepare(request, getResult);
|
||||
return prepare(indexShard.shardId(), request, getResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares an update request by converting it into an index or delete request or an update response (no action).
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Result prepare(UpdateRequest request, final GetResult getResult) {
|
||||
protected Result prepare(ShardId shardId, UpdateRequest request, final GetResult getResult) {
|
||||
long getDateNS = System.nanoTime();
|
||||
final ShardId shardId = new ShardId(getResult.getIndex(), request.shardId());
|
||||
if (!getResult.isExists()) {
|
||||
if (request.upsertRequest() == null && !request.docAsUpsert()) {
|
||||
throw new DocumentMissingException(shardId, request.type(), request.id());
|
||||
|
@ -99,7 +99,7 @@ public class UpdateHelper extends AbstractComponent {
|
|||
// Tell the script that this is a create and not an update
|
||||
ctx.put("op", "create");
|
||||
ctx.put("_source", upsertDoc);
|
||||
ctx = executeScript(request, ctx);
|
||||
ctx = executeScript(request.script, ctx);
|
||||
//Allow the script to set TTL using ctx._ttl
|
||||
if (ttl == null) {
|
||||
ttl = getTTLFromScriptContext(ctx);
|
||||
|
@ -193,7 +193,7 @@ public class UpdateHelper extends AbstractComponent {
|
|||
ctx.put("_ttl", originalTtl);
|
||||
ctx.put("_source", sourceAndContent.v2());
|
||||
|
||||
ctx = executeScript(request, ctx);
|
||||
ctx = executeScript(request.script, ctx);
|
||||
|
||||
operation = (String) ctx.get("op");
|
||||
|
||||
|
@ -243,14 +243,14 @@ public class UpdateHelper extends AbstractComponent {
|
|||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> executeScript(UpdateRequest request, Map<String, Object> ctx) {
|
||||
private Map<String, Object> executeScript(Script script, Map<String, Object> ctx) {
|
||||
try {
|
||||
if (scriptService != null) {
|
||||
ExecutableScript script = scriptService.executable(request.script, ScriptContext.Standard.UPDATE, request, Collections.emptyMap());
|
||||
script.setNextVar("ctx", ctx);
|
||||
script.run();
|
||||
ExecutableScript executableScript = scriptService.executable(script, ScriptContext.Standard.UPDATE, Collections.emptyMap());
|
||||
executableScript.setNextVar("ctx", ctx);
|
||||
executableScript.run();
|
||||
// we need to unwrap the ctx...
|
||||
ctx = (Map<String, Object>) script.unwrap(ctx);
|
||||
ctx = (Map<String, Object>) executableScript.unwrap(ctx);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("failed to execute script", e);
|
||||
|
|
|
@ -171,7 +171,7 @@ final class Bootstrap {
|
|||
// placeholder
|
||||
Settings nodeSettings = Settings.settingsBuilder()
|
||||
.put(settings)
|
||||
.put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, true)
|
||||
.put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true)
|
||||
.build();
|
||||
|
||||
node = new Node(nodeSettings);
|
||||
|
|
|
@ -19,8 +19,12 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
|
@ -80,11 +84,13 @@ import org.elasticsearch.action.termvectors.TermVectorsResponse;
|
|||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequestBuilder;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.support.Headers;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.lease.Releasable;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A client provides a one stop interface for performing actions/operations against the cluster.
|
||||
* <p>
|
||||
|
@ -100,7 +106,15 @@ import org.elasticsearch.common.settings.Settings;
|
|||
*/
|
||||
public interface Client extends ElasticsearchClient, Releasable {
|
||||
|
||||
String CLIENT_TYPE_SETTING = "client.type";
|
||||
Setting<String> CLIENT_TYPE_SETTING_S = new Setting<>("client.type", "node", (s) -> {
|
||||
switch (s) {
|
||||
case "node":
|
||||
case "transport":
|
||||
return s;
|
||||
default:
|
||||
throw new IllegalArgumentException("Can't parse [client.type] must be one of [node, transport]");
|
||||
}
|
||||
}, false, Setting.Scope.CLUSTER);
|
||||
|
||||
/**
|
||||
* The admin client that can be used to perform administrative operations.
|
||||
|
@ -597,5 +611,9 @@ public interface Client extends ElasticsearchClient, Releasable {
|
|||
*/
|
||||
Settings settings();
|
||||
|
||||
Headers headers();
|
||||
/**
|
||||
* Returns a new lightweight Client that applies all given headers to each of the requests
|
||||
* issued from it.
|
||||
*/
|
||||
Client filterWithHeader(Map<String, String> headers);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class FilterClient extends AbstractClient {
|
|||
* @see #in()
|
||||
*/
|
||||
public FilterClient(Client in) {
|
||||
super(in.settings(), in.threadPool(), in.headers());
|
||||
super(in.settings(), in.threadPool());
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.action.ActionResponse;
|
|||
import org.elasticsearch.action.GenericAction;
|
||||
import org.elasticsearch.action.support.TransportAction;
|
||||
import org.elasticsearch.client.support.AbstractClient;
|
||||
import org.elasticsearch.client.support.Headers;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
@ -44,8 +43,8 @@ public class NodeClient extends AbstractClient {
|
|||
private final Map<GenericAction, TransportAction> actions;
|
||||
|
||||
@Inject
|
||||
public NodeClient(Settings settings, ThreadPool threadPool, Headers headers, Map<GenericAction, TransportAction> actions) {
|
||||
super(settings, threadPool, headers);
|
||||
public NodeClient(Settings settings, ThreadPool threadPool, Map<GenericAction, TransportAction> actions) {
|
||||
super(settings, threadPool);
|
||||
this.actions = unmodifiableMap(actions);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.client.node;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.support.Headers;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
|
||||
/**
|
||||
|
@ -30,7 +29,6 @@ public class NodeClientModule extends AbstractModule {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Headers.class).asEagerSingleton();
|
||||
bind(Client.class).to(NodeClient.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -332,13 +332,17 @@ import org.elasticsearch.client.AdminClient;
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ClusterAdminClient;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.client.FilterClient;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -346,23 +350,15 @@ public abstract class AbstractClient extends AbstractComponent implements Client
|
|||
|
||||
private final ThreadPool threadPool;
|
||||
private final Admin admin;
|
||||
|
||||
private final Headers headers;
|
||||
private final ThreadedActionListener.Wrapper threadedWrapper;
|
||||
|
||||
public AbstractClient(Settings settings, ThreadPool threadPool, Headers headers) {
|
||||
public AbstractClient(Settings settings, ThreadPool threadPool) {
|
||||
super(settings);
|
||||
this.threadPool = threadPool;
|
||||
this.headers = headers;
|
||||
this.admin = new Admin(this);
|
||||
this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Headers headers() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Settings settings() {
|
||||
return this.settings;
|
||||
|
@ -398,7 +394,6 @@ public abstract class AbstractClient extends AbstractComponent implements Client
|
|||
@Override
|
||||
public final <Request extends ActionRequest<Request>, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void execute(
|
||||
Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
|
||||
headers.applyTo(request);
|
||||
listener = threadedWrapper.wrap(listener);
|
||||
doExecute(action, request, listener);
|
||||
}
|
||||
|
@ -1757,4 +1752,17 @@ public abstract class AbstractClient extends AbstractComponent implements Client
|
|||
execute(GetSettingsAction.INSTANCE, request, listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Client filterWithHeader(Map<String, String> headers) {
|
||||
return new FilterClient(this) {
|
||||
@Override
|
||||
protected <Request extends ActionRequest<Request>, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
|
||||
ThreadContext threadContext = threadPool().getThreadContext();
|
||||
try (ThreadContext.StoredContext ctx = threadContext.stashAndMergeHeaders(headers)) {
|
||||
super.doExecute(action, request, listener);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client.support;
|
||||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.transport.TransportMessage;
|
||||
|
||||
/**
|
||||
* Client request headers picked up from the client settings. Applied to every
|
||||
* request sent by the client (both transport and node clients)
|
||||
*/
|
||||
public class Headers {
|
||||
|
||||
public static final String PREFIX = "request.headers";
|
||||
|
||||
public static final Headers EMPTY = new Headers(Settings.EMPTY) {
|
||||
@Override
|
||||
public <M extends TransportMessage<?>> M applyTo(M message) {
|
||||
return message;
|
||||
}
|
||||
};
|
||||
|
||||
private final Settings headers;
|
||||
|
||||
@Inject
|
||||
public Headers(Settings settings) {
|
||||
headers = resolveHeaders(settings);
|
||||
}
|
||||
|
||||
public <M extends TransportMessage<?>> M applyTo(M message) {
|
||||
for (String key : headers.names()) {
|
||||
if (!message.hasHeader(key)) {
|
||||
message.putHeader(key, headers.get(key));
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public Settings headers() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
static Settings resolveHeaders(Settings settings) {
|
||||
Settings headers = settings.getAsSettings(PREFIX);
|
||||
return headers != null ? headers : Settings.EMPTY;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.action.ActionRequestBuilder;
|
|||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||
import org.elasticsearch.client.support.AbstractClient;
|
||||
import org.elasticsearch.client.support.Headers;
|
||||
import org.elasticsearch.client.transport.support.TransportProxyClient;
|
||||
import org.elasticsearch.cluster.ClusterNameModule;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
|
@ -115,7 +114,7 @@ public class TransportClient extends AbstractClient {
|
|||
.put( InternalSettingsPreparer.prepareSettings(settings))
|
||||
.put("network.server", false)
|
||||
.put(Node.NODE_CLIENT_SETTING.getKey(), true)
|
||||
.put(CLIENT_TYPE_SETTING, CLIENT_TYPE);
|
||||
.put(CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE);
|
||||
return new PluginsService(settingsBuilder.build(), null, null, pluginClasses);
|
||||
}
|
||||
|
||||
|
@ -177,7 +176,7 @@ public class TransportClient extends AbstractClient {
|
|||
private final TransportProxyClient proxy;
|
||||
|
||||
private TransportClient(Injector injector) {
|
||||
super(injector.getInstance(Settings.class), injector.getInstance(ThreadPool.class), injector.getInstance(Headers.class));
|
||||
super(injector.getInstance(Settings.class), injector.getInstance(ThreadPool.class));
|
||||
this.injector = injector;
|
||||
nodesService = injector.getInstance(TransportClientNodesService.class);
|
||||
proxy = injector.getInstance(TransportProxyClient.class);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue