builder based search source is safe now

This commit is contained in:
Shay Banon 2011-10-18 05:53:53 +02:00
parent 184a38439f
commit b113eb18fe
6 changed files with 12 additions and 7 deletions

View File

@ -100,7 +100,7 @@ public class CountRequest extends BroadcastOperationRequest {
return this;
}
@Override protected void beforeLocalFork() {
@Override protected void beforeStart() {
if (querySourceUnsafe) {
querySource = Arrays.copyOfRange(querySource, querySourceOffset, querySourceOffset + querySourceLength);
querySourceOffset = 0;

View File

@ -325,7 +325,7 @@ public class MoreLikeThisRequest implements ActionRequest {
* more like this documents.
*/
public MoreLikeThisRequest searchSource(SearchSourceBuilder sourceBuilder) {
BytesStream bos = sourceBuilder.buildAsUnsafeBytes(Requests.CONTENT_TYPE);
BytesStream bos = sourceBuilder.buildAsBytesStream(Requests.CONTENT_TYPE);
this.searchSource = bos.underlyingBytes();
this.searchSourceOffset = 0;
this.searchSourceLength = bos.size();

View File

@ -261,11 +261,11 @@ public class SearchRequest implements ActionRequest {
* The source of the search request.
*/
public SearchRequest source(SearchSourceBuilder sourceBuilder) {
BytesStream bos = sourceBuilder.buildAsUnsafeBytes(Requests.CONTENT_TYPE);
BytesStream bos = sourceBuilder.buildAsBytesStream(Requests.CONTENT_TYPE);
this.source = bos.underlyingBytes();
this.sourceOffset = 0;
this.sourceLength = bos.size();
this.sourceUnsafe = true;
this.sourceUnsafe = false;
return this;
}
@ -356,11 +356,11 @@ public class SearchRequest implements ActionRequest {
extraSource = null;
return this;
}
BytesStream bos = sourceBuilder.buildAsUnsafeBytes(Requests.CONTENT_TYPE);
BytesStream bos = sourceBuilder.buildAsBytesStream(Requests.CONTENT_TYPE);
this.extraSource = bos.underlyingBytes();
this.extraSourceOffset = 0;
this.extraSourceLength = bos.size();
this.extraSourceUnsafe = true;
this.extraSourceUnsafe = false;
return this;
}

View File

@ -96,6 +96,10 @@ public abstract class BroadcastOperationRequest implements ActionRequest {
return operationThreading(BroadcastOperationThreading.fromString(operationThreading, this.operationThreading));
}
protected void beforeStart() {
}
protected void beforeLocalFork() {
}

View File

@ -156,6 +156,7 @@ public abstract class TransportBroadcastOperationAction<Request extends Broadcas
// no shards
listener.onResponse(newResponse(request, new AtomicReferenceArray(0), clusterState));
}
request.beforeStart();
// count the local operations, and perform the non local ones
int localOperations = 0;
for (final ShardIterator shardIt : shardsIts) {

View File

@ -495,7 +495,7 @@ public class SearchSourceBuilder implements ToXContent {
}
}
public BytesStream buildAsUnsafeBytes(XContentType contentType) throws SearchSourceBuilderException {
public BytesStream buildAsBytesStream(XContentType contentType) throws SearchSourceBuilderException {
try {
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
toXContent(builder, ToXContent.EMPTY_PARAMS);