Simplified percolate reduce logic and the percolator recovery test

This commit is contained in:
Martijn van Groningen 2013-08-27 10:45:09 +02:00
parent 28e1744e79
commit 2c939847b4
3 changed files with 30 additions and 38 deletions

View File

@ -67,15 +67,6 @@ public class PercolateShardResponse extends BroadcastShardOperationResponse {
this.requestedSize = context.size;
}
public PercolateShardResponse(BytesRef[] matches, long count, PercolateContext context, String index, int shardId) {
super(index, shardId);
this.matches = matches;
this.scores = new float[0];
this.count = count;
this.percolatorTypeId = context.percolatorTypeId;
this.requestedSize = context.size;
}
public PercolateShardResponse(BytesRef[] matches, List<Map<String, HighlightField>> hls, long count, PercolateContext context, String index, int shardId) {
super(index, shardId);
this.matches = matches;
@ -127,7 +118,7 @@ public class PercolateShardResponse extends BroadcastShardOperationResponse {
}
public boolean isEmpty() {
return matches.length == 0 && count == 0;
return percolatorTypeId == 0x00;
}
@Override

View File

@ -131,7 +131,6 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
List<ShardOperationFailedException> shardFailures = null;
byte percolatorTypeId = 0x00;
int nonEmptyResponses = 0;
for (int i = 0; i < shardsResponses.length(); i++) {
Object shardResponse = shardsResponses.get(i);
if (shardResponse == null) {
@ -144,21 +143,18 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
} else {
PercolateShardResponse percolateShardResponse = (PercolateShardResponse) shardResponse;
if (shardResults == null) {
shardResults = newArrayList();
}
if (percolateShardResponse.percolatorTypeId() != 0x00) {
percolatorTypeId = percolateShardResponse.percolatorTypeId();
}
if (!percolateShardResponse.isEmpty()) {
nonEmptyResponses++;
}
shardResults.add(percolateShardResponse);
successfulShards++;
if (!percolateShardResponse.isEmpty()) {
if (shardResults == null) {
percolatorTypeId = percolateShardResponse.percolatorTypeId();
shardResults = newArrayList();
}
shardResults.add(percolateShardResponse);
}
}
}
if (shardResults == null || percolatorTypeId == 0x00 || nonEmptyResponses == 0) {
if (shardResults == null) {
long tookInMillis = System.currentTimeMillis() - request.startTime;
return new PercolateResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures, tookInMillis);
} else {

View File

@ -330,27 +330,32 @@ public class RecoveryPercolatorTests extends AbstractNodesTests {
}
}
String preference = "_prefer_node:" + (randomBoolean() ? node2Id : node3Id);
String preference;
if (node2Id == null && node3Id == null) {
preference = "_local";
} else {
preference = "_prefer_node:" + (randomBoolean() ? node2Id : node3Id);
}
if (multiPercolate) {
MultiPercolateRequestBuilder builder = client
.prepareMultiPercolate();
int numPercolateRequest = randomIntBetween(50, 100);
for (int i = 0; i < numPercolateRequest / 2; i++) {
builder.add(
client.preparePercolate()
.setPreference(preference)
.setIndices("test").setDocumentType("type")
.setPercolateDoc(docBuilder().setDoc(doc)));
}
for (int i = numPercolateRequest / 2; i < numPercolateRequest; i++) {
builder.add(
client.preparePercolate()
.setPreference(preference)
.setGetRequest(Requests.getRequest("test").type("type").id("1"))
.setIndices("test").setDocumentType("type")
);
for (int i = 0; i < numPercolateRequest; i++) {
if (randomBoolean()) {
builder.add(
client.preparePercolate()
.setPreference(preference)
.setGetRequest(Requests.getRequest("test").type("type").id("1"))
.setIndices("test").setDocumentType("type")
);
} else {
builder.add(
client.preparePercolate()
.setPreference(preference)
.setIndices("test").setDocumentType("type")
.setPercolateDoc(docBuilder().setDoc(doc)));
}
}
MultiPercolateResponse response = builder.execute().actionGet();