Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unsafe options #10360

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,7 +47,6 @@
public class ValidateQueryRequest extends BroadcastOperationRequest<ValidateQueryRequest> {

private BytesReference source;
private boolean sourceUnsafe;

private boolean explain;

Expand All @@ -74,14 +73,6 @@ public ActionRequestValidationException validate() {
return validationException;
}

@Override
protected void beforeStart() {
if (sourceUnsafe) {
source = source.copyBytesArray();
sourceUnsafe = false;
}
}

/**
* The source to execute.
*/
Expand All @@ -91,7 +82,6 @@ public BytesReference source() {

public ValidateQueryRequest source(QuerySourceBuilder sourceBuilder) {
this.source = sourceBuilder.buildAsBytes(Requests.CONTENT_TYPE);
this.sourceUnsafe = false;
return this;
}

Expand All @@ -110,7 +100,6 @@ public ValidateQueryRequest source(Map source) {

public ValidateQueryRequest source(XContentBuilder builder) {
this.source = builder.bytes();
this.sourceUnsafe = false;
return this;
}

Expand All @@ -120,30 +109,28 @@ public ValidateQueryRequest source(XContentBuilder builder) {
*/
public ValidateQueryRequest source(String source) {
this.source = new BytesArray(source);
this.sourceUnsafe = false;
return this;
}

/**
* The source to validate.
*/
public ValidateQueryRequest source(byte[] source) {
return source(source, 0, source.length, false);
return source(source, 0, source.length);
}

/**
* The source to validate.
*/
public ValidateQueryRequest source(byte[] source, int offset, int length, boolean unsafe) {
return source(new BytesArray(source, offset, length), unsafe);
public ValidateQueryRequest source(byte[] source, int offset, int length) {
return source(new BytesArray(source, offset, length));
}

/**
* The source to validate.
*/
public ValidateQueryRequest source(BytesReference source, boolean unsafe) {
public ValidateQueryRequest source(BytesReference source) {
this.source = source;
this.sourceUnsafe = unsafe;
return this;
}

Expand Down Expand Up @@ -180,7 +167,6 @@ public boolean explain() {
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);

sourceUnsafe = false;
source = in.readBytesReference();

int typesSize = in.readVInt();
Expand Down
Expand Up @@ -61,17 +61,7 @@ public ValidateQueryRequestBuilder setQuery(QueryBuilder queryBuilder) {
* @see org.elasticsearch.index.query.QueryBuilders
*/
public ValidateQueryRequestBuilder setSource(BytesReference source) {
request().source(source, false);
return this;
}

/**
* The source to validate.
*
* @see org.elasticsearch.index.query.QueryBuilders
*/
public ValidateQueryRequestBuilder setSource(BytesReference source, boolean unsafe) {
request().source(source, unsafe);
request().source(source);
return this;
}

Expand Down
Expand Up @@ -281,12 +281,12 @@ private synchronized void internalAdd(ActionRequest request, @Nullable Object pa
executeIfNeeded();
}

public BulkProcessor add(BytesReference data, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
return add(data, contentUnsafe, defaultIndex, defaultType, null);
public BulkProcessor add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
return add(data, defaultIndex, defaultType, null);
}

public synchronized BulkProcessor add(BytesReference data, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable Object payload) throws Exception {
bulkRequest.add(data, contentUnsafe, defaultIndex, defaultType, null, payload, true);
public synchronized BulkProcessor add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable Object payload) throws Exception {
bulkRequest.add(data, defaultIndex, defaultType, null, payload, true);
executeIfNeeded();
return this;
}
Expand Down
28 changes: 13 additions & 15 deletions src/main/java/org/elasticsearch/action/bulk/BulkRequest.java
Expand Up @@ -104,12 +104,10 @@ public BulkRequest add(Iterable<ActionRequest> requests) {
* (for example, if no id is provided, one will be generated, or usage of the create flag).
*/
public BulkRequest add(IndexRequest request) {
request.beforeLocalFork();
return internalAdd(request, null);
}

public BulkRequest add(IndexRequest request, @Nullable Object payload) {
request.beforeLocalFork();
return internalAdd(request, payload);
}

Expand Down Expand Up @@ -222,32 +220,32 @@ public long estimatedSizeInBytes() {
/**
* Adds a framed data in binary format
*/
public BulkRequest add(byte[] data, int from, int length, boolean contentUnsafe) throws Exception {
return add(data, from, length, contentUnsafe, null, null);
public BulkRequest add(byte[] data, int from, int length) throws Exception {
return add(data, from, length, null, null);
}

/**
* Adds a framed data in binary format
*/
public BulkRequest add(byte[] data, int from, int length, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
return add(new BytesArray(data, from, length), contentUnsafe, defaultIndex, defaultType);
public BulkRequest add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
return add(new BytesArray(data, from, length), defaultIndex, defaultType);
}

/**
* Adds a framed data in binary format
*/
public BulkRequest add(BytesReference data, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
return add(data, contentUnsafe, defaultIndex, defaultType, null, null, true);
public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
return add(data, defaultIndex, defaultType, null, null, true);
}

/**
* Adds a framed data in binary format
*/
public BulkRequest add(BytesReference data, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType, boolean allowExplicitIndex) throws Exception {
return add(data, contentUnsafe, defaultIndex, defaultType, null, null, allowExplicitIndex);
public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, boolean allowExplicitIndex) throws Exception {
return add(data, defaultIndex, defaultType, null, null, allowExplicitIndex);
}

public BulkRequest add(BytesReference data, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String defaultRouting, @Nullable Object payload, boolean allowExplicitIndex) throws Exception {
public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Nullable String defaultType, @Nullable String defaultRouting, @Nullable Object payload, boolean allowExplicitIndex) throws Exception {
XContent xContent = XContentFactory.xContent(data);
int from = 0;
int length = data.length();
Expand Down Expand Up @@ -336,20 +334,20 @@ public BulkRequest add(BytesReference data, boolean contentUnsafe, @Nullable Str
}
// order is important, we set parent after routing, so routing will be set to parent if not set explicitly
// we use internalAdd so we don't fork here, this allows us not to copy over the big byte array to small chunks
// of index request. All index requests are still unsafe if applicable.
// of index request.
if ("index".equals(action)) {
if (opType == null) {
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
.source(data.slice(from, nextMarker - from), contentUnsafe), payload);
.source(data.slice(from, nextMarker - from)), payload);
} else {
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
.create("create".equals(opType))
.source(data.slice(from, nextMarker - from), contentUnsafe), payload);
.source(data.slice(from, nextMarker - from)), payload);
}
} else if ("create".equals(action)) {
internalAdd(new IndexRequest(index, type, id).routing(routing).parent(parent).timestamp(timestamp).ttl(ttl).version(version).versionType(versionType)
.create(true)
.source(data.slice(from, nextMarker - from), contentUnsafe), payload);
.source(data.slice(from, nextMarker - from)), payload);
} else if ("update".equals(action)) {
UpdateRequest updateRequest = new UpdateRequest(index, type, id).routing(routing).parent(parent).retryOnConflict(retryOnConflict)
.version(version).versionType(versionType)
Expand Down
Expand Up @@ -96,16 +96,16 @@ public BulkRequestBuilder add(UpdateRequestBuilder request) {
/**
* Adds a framed data in binary format
*/
public BulkRequestBuilder add(byte[] data, int from, int length, boolean contentUnsafe) throws Exception {
request.add(data, from, length, contentUnsafe, null, null);
public BulkRequestBuilder add(byte[] data, int from, int length) throws Exception {
request.add(data, from, length, null, null);
return this;
}

/**
* Adds a framed data in binary format
*/
public BulkRequestBuilder add(byte[] data, int from, int length, boolean contentUnsafe, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
request.add(data, from, length, contentUnsafe, defaultIndex, defaultType);
public BulkRequestBuilder add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType) throws Exception {
request.add(data, from, length, defaultIndex, defaultType);
return this;
}

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/org/elasticsearch/action/bulk/BulkShardRequest.java
Expand Up @@ -74,20 +74,6 @@ public String[] indices() {
return indices.toArray(new String[indices.size()]);
}

/**
* Before we fork on a local thread, make sure we copy over the bytes if they are unsafe
*/
@Override
public void beforeLocalFork() {
for (BulkItemRequest item : items) {
if (item.request() instanceof InstanceShardOperationRequest) {
((InstanceShardOperationRequest) item.request()).beforeLocalFork();
} else {
((ShardReplicationOperationRequest) item.request()).beforeLocalFork();
}
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/org/elasticsearch/action/count/CountRequest.java
Expand Up @@ -65,7 +65,6 @@ public class CountRequest extends BroadcastOperationRequest<CountRequest> {
private String preference;

private BytesReference source;
private boolean sourceUnsafe;

private String[] types = Strings.EMPTY_ARRAY;

Expand All @@ -89,14 +88,6 @@ public ActionRequestValidationException validate() {
return validationException;
}

@Override
protected void beforeStart() {
if (sourceUnsafe) {
source = source.copyBytesArray();
sourceUnsafe = false;
}
}

/**
* The minimum score of the documents to include in the count.
*/
Expand Down Expand Up @@ -125,7 +116,6 @@ public BytesReference source() {
*/
public CountRequest source(QuerySourceBuilder sourceBuilder) {
this.source = sourceBuilder.buildAsBytes(Requests.CONTENT_TYPE);
this.sourceUnsafe = false;
return this;
}

Expand All @@ -144,7 +134,6 @@ public CountRequest source(Map querySource) {

public CountRequest source(XContentBuilder builder) {
this.source = builder.bytes();
this.sourceUnsafe = false;
return this;
}

Expand All @@ -154,27 +143,25 @@ public CountRequest source(XContentBuilder builder) {
*/
public CountRequest source(String querySource) {
this.source = new BytesArray(querySource);
this.sourceUnsafe = false;
return this;
}

/**
* The source to execute.
*/
public CountRequest source(byte[] querySource) {
return source(querySource, 0, querySource.length, false);
return source(querySource, 0, querySource.length);
}

/**
* The source to execute.
*/
public CountRequest source(byte[] querySource, int offset, int length, boolean unsafe) {
return source(new BytesArray(querySource, offset, length), unsafe);
public CountRequest source(byte[] querySource, int offset, int length) {
return source(new BytesArray(querySource, offset, length));
}

public CountRequest source(BytesReference querySource, boolean unsafe) {
public CountRequest source(BytesReference querySource) {
this.source = querySource;
this.sourceUnsafe = unsafe;
return this;
}

Expand Down Expand Up @@ -246,7 +233,6 @@ public void readFrom(StreamInput in) throws IOException {
minScore = in.readFloat();
routing = in.readOptionalString();
preference = in.readOptionalString();
sourceUnsafe = false;
source = in.readBytesReference();
types = in.readStringArray();
terminateAfter = in.readVInt();
Expand Down
Expand Up @@ -112,15 +112,7 @@ public CountRequestBuilder setQuery(XContentBuilder query) {
* The source to execute.
*/
public CountRequestBuilder setSource(BytesReference source) {
request().source(source, false);
return this;
}

/**
* The source to execute.
*/
public CountRequestBuilder setSource(BytesReference source, boolean unsafe) {
request().source(source, unsafe);
request().source(source);
return this;
}

Expand Down
Expand Up @@ -71,7 +71,6 @@ protected String executor() {
@Override
protected void doExecute(final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
if (autoCreateIndex.shouldAutoCreate(request.index(), clusterService.state())) {
request.beforeLocalFork();
createIndexAction.execute(new CreateIndexRequest(request).index(request.index()).cause("auto(delete api)").masterNodeTimeout(request.timeout()), new ActionListener<CreateIndexResponse>() {
@Override
public void onResponse(CreateIndexResponse result) {
Expand Down