move validate query to read bytes ref
This commit is contained in:
parent
0f1b3f0457
commit
bb1b46431c
|
@ -20,6 +20,7 @@
|
||||||
package org.elasticsearch.action.admin.indices.validate.query;
|
package org.elasticsearch.action.admin.indices.validate.query;
|
||||||
|
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
|
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
|
||||||
|
import org.elasticsearch.common.BytesHolder;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -29,14 +30,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal validate request executed directly against a specific index shard.
|
* Internal validate request executed directly against a specific index shard.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
||||||
|
|
||||||
private byte[] querySource;
|
private BytesHolder querySource;
|
||||||
private int querySourceOffset;
|
|
||||||
private int querySourceLength;
|
|
||||||
|
|
||||||
private String[] types = Strings.EMPTY_ARRAY;
|
private String[] types = Strings.EMPTY_ARRAY;
|
||||||
|
|
||||||
|
@ -50,24 +47,14 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
||||||
public ShardValidateQueryRequest(String index, int shardId, @Nullable String[] filteringAliases, ValidateQueryRequest request) {
|
public ShardValidateQueryRequest(String index, int shardId, @Nullable String[] filteringAliases, ValidateQueryRequest request) {
|
||||||
super(index, shardId);
|
super(index, shardId);
|
||||||
this.querySource = request.querySource();
|
this.querySource = request.querySource();
|
||||||
this.querySourceOffset = request.querySourceOffset();
|
|
||||||
this.querySourceLength = request.querySourceLength();
|
|
||||||
this.types = request.types();
|
this.types = request.types();
|
||||||
this.filteringAliases = filteringAliases;
|
this.filteringAliases = filteringAliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] querySource() {
|
public BytesHolder querySource() {
|
||||||
return querySource;
|
return querySource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int querySourceOffset() {
|
|
||||||
return querySourceOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int querySourceLength() {
|
|
||||||
return querySourceLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String[] types() {
|
public String[] types() {
|
||||||
return this.types;
|
return this.types;
|
||||||
}
|
}
|
||||||
|
@ -79,10 +66,8 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
querySourceLength = in.readVInt();
|
querySource = in.readBytesReference();
|
||||||
querySourceOffset = 0;
|
|
||||||
querySource = new byte[querySourceLength];
|
|
||||||
in.readFully(querySource);
|
|
||||||
int typesSize = in.readVInt();
|
int typesSize = in.readVInt();
|
||||||
if (typesSize > 0) {
|
if (typesSize > 0) {
|
||||||
types = new String[typesSize];
|
types = new String[typesSize];
|
||||||
|
@ -102,8 +87,8 @@ class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
out.writeVInt(querySourceLength);
|
out.writeBytesHolder(querySource);
|
||||||
out.writeBytes(querySource, querySourceOffset, querySourceLength);
|
|
||||||
out.writeVInt(types.length);
|
out.writeVInt(types.length);
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
out.writeUTF(type);
|
out.writeUTF(type);
|
||||||
|
|
|
@ -136,11 +136,11 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct
|
||||||
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) throws ElasticSearchException {
|
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) throws ElasticSearchException {
|
||||||
IndexQueryParserService queryParserService = indicesService.indexServiceSafe(request.index()).queryParserService();
|
IndexQueryParserService queryParserService = indicesService.indexServiceSafe(request.index()).queryParserService();
|
||||||
boolean valid;
|
boolean valid;
|
||||||
if (request.querySourceLength() == 0) {
|
if (request.querySource().length() == 0) {
|
||||||
valid = true;
|
valid = true;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
queryParserService.parse(request.querySource(), request.querySourceOffset(), request.querySourceLength());
|
queryParserService.parse(request.querySource().bytes(), request.querySource().offset(), request.querySource().length());
|
||||||
valid = true;
|
valid = true;
|
||||||
} catch (QueryParsingException e) {
|
} catch (QueryParsingException e) {
|
||||||
valid = false;
|
valid = false;
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
|
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
|
||||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
|
||||||
import org.elasticsearch.client.Requests;
|
import org.elasticsearch.client.Requests;
|
||||||
|
import org.elasticsearch.common.BytesHolder;
|
||||||
import org.elasticsearch.common.Required;
|
import org.elasticsearch.common.Required;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.Unicode;
|
import org.elasticsearch.common.Unicode;
|
||||||
|
@ -45,8 +46,6 @@ import java.util.Map;
|
||||||
* <p/>
|
* <p/>
|
||||||
* <p>The request requires the query source to be set either using {@link #query(org.elasticsearch.index.query.QueryBuilder)},
|
* <p>The request requires the query source to be set either using {@link #query(org.elasticsearch.index.query.QueryBuilder)},
|
||||||
* or {@link #query(byte[])}.
|
* or {@link #query(byte[])}.
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ValidateQueryRequest extends BroadcastOperationRequest {
|
public class ValidateQueryRequest extends BroadcastOperationRequest {
|
||||||
|
|
||||||
|
@ -111,16 +110,8 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
||||||
/**
|
/**
|
||||||
* The query source to execute.
|
* The query source to execute.
|
||||||
*/
|
*/
|
||||||
byte[] querySource() {
|
BytesHolder querySource() {
|
||||||
return querySource;
|
return new BytesHolder(querySource, querySourceOffset, querySourceLength);
|
||||||
}
|
|
||||||
|
|
||||||
int querySourceOffset() {
|
|
||||||
return querySourceOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
int querySourceLength() {
|
|
||||||
return querySourceLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,11 +209,11 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
|
|
||||||
|
BytesHolder bytes = in.readBytesReference();
|
||||||
querySourceUnsafe = false;
|
querySourceUnsafe = false;
|
||||||
querySourceOffset = 0;
|
querySource = bytes.bytes();
|
||||||
querySourceLength = in.readVInt();
|
querySourceOffset = bytes.offset();
|
||||||
querySource = new byte[querySourceLength];
|
querySourceLength = bytes.length();
|
||||||
in.readFully(querySource);
|
|
||||||
|
|
||||||
int typesSize = in.readVInt();
|
int typesSize = in.readVInt();
|
||||||
if (typesSize > 0) {
|
if (typesSize > 0) {
|
||||||
|
@ -237,8 +228,7 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
|
|
||||||
out.writeVInt(querySourceLength);
|
out.writeBytesHolder(querySource, querySourceOffset, querySourceLength);
|
||||||
out.writeBytes(querySource, querySourceOffset, querySourceLength);
|
|
||||||
|
|
||||||
out.writeVInt(types.length);
|
out.writeVInt(types.length);
|
||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
|
@ -248,6 +238,6 @@ public class ValidateQueryRequest extends BroadcastOperationRequest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", querySource[" + Unicode.fromBytes(querySource) + "]";
|
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types) + ", querySource[" + Unicode.fromBytes(querySource, querySourceOffset, querySourceLength) + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue