Skip to content

Commit c7c8bb3

Browse files
committed
Merge pull request #16861 from nik9000/reindex_is_ready
Reindex required some parsing changes for search requests to support differing defaults from the regular search api.
2 parents 83d1e09 + aeed7ee commit c7c8bb3

File tree

90 files changed

+9049
-116
lines changed

Some content is hidden

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

90 files changed

+9049
-116
lines changed

core/src/main/java/org/elasticsearch/action/ActionListener.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121

2222
/**
2323
* A listener for action responses or failures.
24-
*
25-
*
2624
*/
2725
public interface ActionListener<Response> {
28-
2926
/**
30-
* A response handler.
27+
* Handle action response. This response may constitute a failure or a
28+
* success but it is up to the listener to make that decision.
3129
*/
3230
void onResponse(Response response);
3331

3432
/**
35-
* A failure handler.
33+
* A failure caused by an exception at some phase of the task.
3634
*/
3735
void onFailure(Throwable e);
3836
}

core/src/main/java/org/elasticsearch/action/bulk/BulkItemResponse.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import org.elasticsearch.common.io.stream.StreamInput;
2929
import org.elasticsearch.common.io.stream.StreamOutput;
3030
import org.elasticsearch.common.io.stream.Streamable;
31+
import org.elasticsearch.common.io.stream.Writeable;
3132
import org.elasticsearch.common.xcontent.StatusToXContent;
33+
import org.elasticsearch.common.xcontent.ToXContent;
3234
import org.elasticsearch.common.xcontent.XContentBuilder;
3335
import org.elasticsearch.common.xcontent.XContentBuilderString;
3436
import org.elasticsearch.rest.RestStatus;
@@ -76,7 +78,15 @@ static final class Fields {
7678
/**
7779
* Represents a failure.
7880
*/
79-
public static class Failure {
81+
public static class Failure implements Writeable<Failure>, ToXContent {
82+
static final String INDEX_FIELD = "index";
83+
static final String TYPE_FIELD = "type";
84+
static final String ID_FIELD = "id";
85+
static final String CAUSE_FIELD = "cause";
86+
static final String STATUS_FIELD = "status";
87+
88+
public static final Failure PROTOTYPE = new Failure(null, null, null, null);
89+
8090
private final String index;
8191
private final String type;
8292
private final String id;
@@ -126,9 +136,39 @@ public RestStatus getStatus() {
126136
return this.status;
127137
}
128138

139+
/**
140+
* The actual cause of the failure.
141+
*/
129142
public Throwable getCause() {
130143
return cause;
131144
}
145+
146+
@Override
147+
public Failure readFrom(StreamInput in) throws IOException {
148+
return new Failure(in.readString(), in.readString(), in.readOptionalString(), in.readThrowable());
149+
}
150+
151+
@Override
152+
public void writeTo(StreamOutput out) throws IOException {
153+
out.writeString(getIndex());
154+
out.writeString(getType());
155+
out.writeOptionalString(getId());
156+
out.writeThrowable(getCause());
157+
}
158+
159+
@Override
160+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
161+
builder.field(INDEX_FIELD, index);
162+
builder.field(TYPE_FIELD, type);
163+
if (id != null) {
164+
builder.field(ID_FIELD, id);
165+
}
166+
builder.startObject(CAUSE_FIELD);
167+
ElasticsearchException.toXContent(builder, params, cause);
168+
builder.endObject();
169+
builder.field(STATUS_FIELD, status.getStatus());
170+
return builder;
171+
}
132172
}
133173

134174
private int id;
@@ -265,11 +305,7 @@ public void readFrom(StreamInput in) throws IOException {
265305
}
266306

267307
if (in.readBoolean()) {
268-
String fIndex = in.readString();
269-
String fType = in.readString();
270-
String fId = in.readOptionalString();
271-
Throwable throwable = in.readThrowable();
272-
failure = new Failure(fIndex, fType, fId, throwable);
308+
failure = Failure.PROTOTYPE.readFrom(in);
273309
}
274310
}
275311

@@ -294,10 +330,7 @@ public void writeTo(StreamOutput out) throws IOException {
294330
out.writeBoolean(false);
295331
} else {
296332
out.writeBoolean(true);
297-
out.writeString(failure.getIndex());
298-
out.writeString(failure.getType());
299-
out.writeOptionalString(failure.getId());
300-
out.writeThrowable(failure.getCause());
333+
failure.writeTo(out);
301334
}
302335
}
303336
}

core/src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public void readFrom(StreamInput in) throws IOException {
9494

9595
@Override
9696
public String toString() {
97-
return "shard bulk {" + super.toString() + "}";
97+
// This is included in error messages so we'll try to make it somewhat user friendly.
98+
StringBuilder b = new StringBuilder("BulkShardRequest to [");
99+
b.append(index).append("] containing [").append(items.length).append("] requests");
100+
if (refresh) {
101+
b.append(" and a refresh");
102+
}
103+
return b.toString();
98104
}
99105
}

core/src/main/java/org/elasticsearch/action/bulk/Retry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
/**
3939
* Encapsulates synchronous and asynchronous retry logic.
4040
*/
41-
class Retry {
41+
public class Retry {
4242
private final Class<? extends Throwable> retryOnThrowable;
4343

4444
private BackoffPolicy backoffPolicy;

core/src/main/java/org/elasticsearch/action/index/IndexRequest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ public ActionRequestValidationException validate() {
223223
return validationException;
224224
}
225225

226+
/**
227+
* The content type that will be used when generating a document from user provided objects like Maps.
228+
*/
229+
public XContentType getContentType() {
230+
return contentType;
231+
}
232+
226233
/**
227234
* Sets the content type that will be used when generating a document from user provided objects (like Map).
228235
*/
@@ -294,6 +301,7 @@ public IndexRequest parent(String parent) {
294301
return this;
295302
}
296303

304+
@Override
297305
public String parent() {
298306
return this.parent;
299307
}
@@ -645,7 +653,7 @@ public void process(MetaData metaData, @Nullable MappingMetaData mappingMd, bool
645653
@Override
646654
public void readFrom(StreamInput in) throws IOException {
647655
super.readFrom(in);
648-
type = in.readString();
656+
type = in.readOptionalString();
649657
id = in.readOptionalString();
650658
routing = in.readOptionalString();
651659
parent = in.readOptionalString();
@@ -663,7 +671,7 @@ public void readFrom(StreamInput in) throws IOException {
663671
@Override
664672
public void writeTo(StreamOutput out) throws IOException {
665673
super.writeTo(out);
666-
out.writeString(type);
674+
out.writeOptionalString(type);
667675
out.writeOptionalString(id);
668676
out.writeOptionalString(routing);
669677
out.writeOptionalString(parent);

core/src/main/java/org/elasticsearch/action/support/TransportAction.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.common.logging.ESLogger;
3131
import org.elasticsearch.common.settings.Settings;
3232
import org.elasticsearch.tasks.Task;
33+
import org.elasticsearch.tasks.TaskListener;
3334
import org.elasticsearch.tasks.TaskManager;
3435
import org.elasticsearch.threadpool.ThreadPool;
3536

@@ -72,6 +73,13 @@ public final ActionFuture<Response> execute(Request request) {
7273
* This is a typical behavior.
7374
*/
7475
public final Task execute(Request request, ActionListener<Response> listener) {
76+
/*
77+
* While this version of execute could delegate to the TaskListener
78+
* version of execute that'd add yet another layer of wrapping on the
79+
* listener and prevent us from using the listener bare if there isn't a
80+
* task. That just seems like too many objects. Thus the two versions of
81+
* this method.
82+
*/
7583
Task task = taskManager.register("transport", actionName, request);
7684
if (task == null) {
7785
execute(null, request, listener);
@@ -93,11 +101,32 @@ public void onFailure(Throwable e) {
93101
return task;
94102
}
95103

104+
public final Task execute(Request request, TaskListener<Response> listener) {
105+
Task task = taskManager.register("transport", actionName, request);
106+
execute(task, request, new ActionListener<Response>() {
107+
@Override
108+
public void onResponse(Response response) {
109+
if (task != null) {
110+
taskManager.unregister(task);
111+
}
112+
listener.onResponse(task, response);
113+
}
114+
115+
@Override
116+
public void onFailure(Throwable e) {
117+
if (task != null) {
118+
taskManager.unregister(task);
119+
}
120+
listener.onFailure(task, e);
121+
}
122+
});
123+
return task;
124+
}
125+
96126
/**
97127
* Use this method when the transport action should continue to run in the context of the current task
98128
*/
99129
public final void execute(Task task, Request request, ActionListener<Response> listener) {
100-
101130
ActionRequestValidationException validationException = request.validate();
102131
if (validationException != null) {
103132
listener.onFailure(validationException);

0 commit comments

Comments
 (0)