Search in sources :

Example 1 with InternalQueryResponse

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();
}
Also used : InternalQueryResponse(io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse) IndexShardResponse(io.zulia.message.ZuliaQuery.IndexShardResponse) ZuliaIndex(io.zulia.server.index.ZuliaIndex)

Example 2 with InternalQueryResponse

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 + ">");
            }
        }
    }
}
Also used : ShardQueryResponse(io.zulia.message.ZuliaQuery.ShardQueryResponse) InternalQueryResponse(io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse) IndexShardResponse(io.zulia.message.ZuliaQuery.IndexShardResponse) ZuliaIndex(io.zulia.server.index.ZuliaIndex)

Example 3 with InternalQueryResponse

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");
    }
}
Also used : InternalQueryResponse(io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse) InternalQueryRequest(io.zulia.message.ZuliaServiceOuterClass.InternalQueryRequest) QueryRequest(io.zulia.message.ZuliaServiceOuterClass.QueryRequest) QueryResponse(io.zulia.message.ZuliaServiceOuterClass.QueryResponse) InternalQueryResponse(io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse) QueryCombiner(io.zulia.server.search.QueryCombiner) IOException(java.io.IOException)

Aggregations

InternalQueryResponse (io.zulia.message.ZuliaServiceOuterClass.InternalQueryResponse)3 IndexShardResponse (io.zulia.message.ZuliaQuery.IndexShardResponse)2 ZuliaIndex (io.zulia.server.index.ZuliaIndex)2 ShardQueryResponse (io.zulia.message.ZuliaQuery.ShardQueryResponse)1 InternalQueryRequest (io.zulia.message.ZuliaServiceOuterClass.InternalQueryRequest)1 QueryRequest (io.zulia.message.ZuliaServiceOuterClass.QueryRequest)1 QueryResponse (io.zulia.message.ZuliaServiceOuterClass.QueryResponse)1 QueryCombiner (io.zulia.server.search.QueryCombiner)1 IOException (java.io.IOException)1