Simplified percolate reduce logic and the percolator recovery test
This commit is contained in:
parent
28e1744e79
commit
2c939847b4
|
@ -67,15 +67,6 @@ public class PercolateShardResponse extends BroadcastShardOperationResponse {
|
||||||
this.requestedSize = context.size;
|
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) {
|
public PercolateShardResponse(BytesRef[] matches, List<Map<String, HighlightField>> hls, long count, PercolateContext context, String index, int shardId) {
|
||||||
super(index, shardId);
|
super(index, shardId);
|
||||||
this.matches = matches;
|
this.matches = matches;
|
||||||
|
@ -127,7 +118,7 @@ public class PercolateShardResponse extends BroadcastShardOperationResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return matches.length == 0 && count == 0;
|
return percolatorTypeId == 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -131,7 +131,6 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
|
||||||
List<ShardOperationFailedException> shardFailures = null;
|
List<ShardOperationFailedException> shardFailures = null;
|
||||||
|
|
||||||
byte percolatorTypeId = 0x00;
|
byte percolatorTypeId = 0x00;
|
||||||
int nonEmptyResponses = 0;
|
|
||||||
for (int i = 0; i < shardsResponses.length(); i++) {
|
for (int i = 0; i < shardsResponses.length(); i++) {
|
||||||
Object shardResponse = shardsResponses.get(i);
|
Object shardResponse = shardsResponses.get(i);
|
||||||
if (shardResponse == null) {
|
if (shardResponse == null) {
|
||||||
|
@ -144,21 +143,18 @@ public class TransportPercolateAction extends TransportBroadcastOperationAction<
|
||||||
shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
|
shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
|
||||||
} else {
|
} else {
|
||||||
PercolateShardResponse percolateShardResponse = (PercolateShardResponse) shardResponse;
|
PercolateShardResponse percolateShardResponse = (PercolateShardResponse) shardResponse;
|
||||||
if (shardResults == null) {
|
|
||||||
shardResults = newArrayList();
|
|
||||||
}
|
|
||||||
if (percolateShardResponse.percolatorTypeId() != 0x00) {
|
|
||||||
percolatorTypeId = percolateShardResponse.percolatorTypeId();
|
|
||||||
}
|
|
||||||
if (!percolateShardResponse.isEmpty()) {
|
|
||||||
nonEmptyResponses++;
|
|
||||||
}
|
|
||||||
shardResults.add(percolateShardResponse);
|
|
||||||
successfulShards++;
|
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;
|
long tookInMillis = System.currentTimeMillis() - request.startTime;
|
||||||
return new PercolateResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures, tookInMillis);
|
return new PercolateResponse(shardsResponses.length(), successfulShards, failedShards, shardFailures, tookInMillis);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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) {
|
if (multiPercolate) {
|
||||||
MultiPercolateRequestBuilder builder = client
|
MultiPercolateRequestBuilder builder = client
|
||||||
.prepareMultiPercolate();
|
.prepareMultiPercolate();
|
||||||
int numPercolateRequest = randomIntBetween(50, 100);
|
int numPercolateRequest = randomIntBetween(50, 100);
|
||||||
|
|
||||||
for (int i = 0; i < numPercolateRequest / 2; i++) {
|
for (int i = 0; i < numPercolateRequest; i++) {
|
||||||
builder.add(
|
if (randomBoolean()) {
|
||||||
client.preparePercolate()
|
builder.add(
|
||||||
.setPreference(preference)
|
client.preparePercolate()
|
||||||
.setIndices("test").setDocumentType("type")
|
.setPreference(preference)
|
||||||
.setPercolateDoc(docBuilder().setDoc(doc)));
|
.setGetRequest(Requests.getRequest("test").type("type").id("1"))
|
||||||
}
|
.setIndices("test").setDocumentType("type")
|
||||||
|
);
|
||||||
for (int i = numPercolateRequest / 2; i < numPercolateRequest; i++) {
|
} else {
|
||||||
builder.add(
|
builder.add(
|
||||||
client.preparePercolate()
|
client.preparePercolate()
|
||||||
.setPreference(preference)
|
.setPreference(preference)
|
||||||
.setGetRequest(Requests.getRequest("test").type("type").id("1"))
|
.setIndices("test").setDocumentType("type")
|
||||||
.setIndices("test").setDocumentType("type")
|
.setPercolateDoc(docBuilder().setDoc(doc)));
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiPercolateResponse response = builder.execute().actionGet();
|
MultiPercolateResponse response = builder.execute().actionGet();
|
||||||
|
|
Loading…
Reference in New Issue