use of io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse in project zuliasearch by zuliaio.
the class QueryRequestFederator method internalQuery.
public static InternalQueryResponse internalQuery(Collection<ZuliaIndex> indexes, InternalQueryRequest request, Map<String, Query> queryMap) throws Exception {
InternalQueryResponse.Builder internalQueryResponseBuilder = InternalQueryResponse.newBuilder();
for (ZuliaIndex index : indexes) {
IndexShardResponse isr = index.internalQuery(queryMap.get(index.getIndexName()), request);
internalQueryResponseBuilder.addIndexShardResponse(isr);
}
return internalQueryResponseBuilder.build();
}
use of io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse in project zuliasearch by zuliaio.
the class QueryCombiner method validate.
private void validate() throws Exception {
for (InternalQueryResponse iqr : responses) {
for (IndexShardResponse isr : iqr.getIndexShardResponseList()) {
String indexName = isr.getIndexName();
if (!indexToShardQueryResponseMap.containsKey(indexName)) {
indexToShardQueryResponseMap.put(indexName, new HashMap<>());
}
for (ShardQueryResponse sr : isr.getShardQueryResponseList()) {
int shardNumber = sr.getShardNumber();
Map<Integer, ShardQueryResponse> shardResponseMap = indexToShardQueryResponseMap.get(indexName);
if (shardResponseMap.containsKey(shardNumber)) {
throw new Exception("Shard <" + shardNumber + "> is repeated for <" + indexName + ">");
} else {
shardResponseMap.put(shardNumber, sr);
shardResponses.add(sr);
}
}
}
}
for (ZuliaIndex index : indexes) {
int numberOfShards = index.getNumberOfShards();
Map<Integer, ShardQueryResponse> shardResponseMap = indexToShardQueryResponseMap.get(index.getIndexName());
if (shardResponseMap == null) {
throw new Exception("Missing index <" + index.getIndexName() + "> in response");
}
if (shardResponseMap.size() != numberOfShards) {
throw new Exception("Found <" + shardResponseMap.size() + "> expected <" + numberOfShards + ">");
}
for (int shardNumber = 0; shardNumber < numberOfShards; shardNumber++) {
if (!shardResponseMap.containsKey(shardNumber)) {
throw new Exception("Missing shard <" + shardNumber + ">");
}
}
}
}
use of io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse in project zuliasearch by zuliaio.
the class QueryRequestFederator method getResponse.
public QueryResponse getResponse(QueryRequest request) throws Exception {
long queryId = queryNumber.getAndIncrement();
long start = System.currentTimeMillis();
String queryJson = JsonFormat.printer().print(request);
LOG.info("Running id <" + queryId + "> query <" + queryJson + ">");
List<InternalQueryResponse> results = send(request);
QueryCombiner queryCombiner = new QueryCombiner(indexes, request, results);
QueryResponse qr = queryCombiner.getQueryResponse();
if (!queryCombiner.isShort()) {
long end = System.currentTimeMillis();
LOG.info("Finished query id <" + queryId + "> in " + (end - start) + "ms");
return qr;
} else {
if (!request.getFetchFull()) {
QueryRequest newRequest = request.toBuilder().setFetchFull(true).build();
long end = System.currentTimeMillis();
LOG.info("Finished query id <" + queryId + "> in " + (end - start) + "ms");
return getResponse(newRequest);
}
throw new Exception("Full fetch request is short");
}
}
Aggregations