Search in sources :

Example 1 with Response

use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.

the class TestLindenUpdate method updateNonexistentDoc.

@Test
public void updateNonexistentDoc() throws Exception {
    Response response = handleRequest("{\"type\": \"update\", \"content\": {\"id\":6, \"title\":\"lucene 6\"}}");
    Assert.assertFalse(response.isSuccess());
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) Test(org.junit.Test)

Example 2 with Response

use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.

the class CoreLindenServiceImpl method handleClusterBqlRequest.

@Override
public Future<LindenResult> handleClusterBqlRequest(final String bql) {
    final Stopwatch sw = Stopwatch.createStarted();
    return clusterExecutorPool.apply(new Function0<LindenResult>() {

        @Override
        public LindenResult apply() {
            LindenResult result = null;
            String logTag = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: clusterExecutorPool took " + eps + "ms to start handleClusterBqlRequest.");
                    if (eps > clusterFuturePoolWaitTimeout) {
                        result = buildLindenFailedResult("Waiting time is too long, " + eps + "ms in cluster future pool");
                        logTag = "poolWaitTimeout";
                        return result;
                    }
                }
                LindenRequest request = bqlCompiler.compile(bql);
                if (request.isSetSearchRequest()) {
                    LindenSearchRequest searchRequest = request.getSearchRequest();
                    searchRequest.setOriginQuery(bql);
                    result = lindenCluster.search(searchRequest);
                    if (result.isSuccess()) {
                        logTag = "search";
                    } else {
                        logTag = "failureSearch";
                    }
                } else if (request.isSetDeleteRequest()) {
                    Response response = lindenCluster.delete(request.getDeleteRequest());
                    result = new LindenResult().setSuccess(response.isSuccess()).setError(response.getError());
                    if (result.isSuccess()) {
                        logTag = "delete";
                    } else {
                        logTag = "failureDelete";
                    }
                } else {
                    result = buildLindenFailedResult("unsupported Bql");
                    logTag = "unsupportedBql";
                }
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                result = buildLindenFailedResult(errorStackInfo);
                logTag = "exceptionalBql";
            } finally {
                metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
                result.setCost((int) sw.elapsed(TimeUnit.MILLISECONDS));
                if (result.isSuccess()) {
                    LOGGER.info("Cluster request succeeded bql: {}, hits: {}, cost: {} ms.", bql, result.getHitsSize(), result.getCost());
                } else {
                    LOGGER.error("Cluster request failed bql: {}, error: {}, cost: {} ms.", bql, result.getError(), result.getCost());
                }
                return result;
            }
        }
    });
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenRequest(com.xiaomi.linden.thrift.common.LindenRequest) Stopwatch(com.google.common.base.Stopwatch) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) IOException(java.io.IOException)

Example 3 with Response

use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.

the class CoreLindenServiceImpl method handleClusterDeleteRequest.

@Override
public Future<Response> handleClusterDeleteRequest(final String bql) {
    final Stopwatch sw = Stopwatch.createStarted();
    return clusterExecutorPool.apply(new Function0<Response>() {

        @Override
        public Response apply() {
            Response response = null;
            String logTag = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: clusterExecutorPool took " + eps + "ms to start handleClusterDeleteRequest.");
                    if (eps > clusterFuturePoolWaitTimeout) {
                        response = ResponseUtils.buildFailedResponse("Waiting time is too long, " + eps + "ms in cluster future pool");
                        return response;
                    }
                }
                LindenRequest request = bqlCompiler.compile(bql);
                if (request.isSetDeleteRequest()) {
                    response = lindenCluster.delete(request.getDeleteRequest());
                    if (response.isSuccess()) {
                        logTag = "delete";
                    } else {
                        logTag = "failureDelete";
                    }
                } else {
                    response = ResponseUtils.buildFailedResponse("invalid delete Bql");
                    logTag = "invalidDeleteBql";
                }
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                response = ResponseUtils.buildFailedResponse(errorStackInfo);
                logTag = "exceptionalDeleteBql";
            } finally {
                metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
                if (response.isSuccess()) {
                    LOGGER.info("Cluster delete succeeded bql: {}, cost: {} ms.", bql, sw.elapsed(TimeUnit.MILLISECONDS));
                } else {
                    LOGGER.error("Cluster delete failed bql: {}, cost: {} ms.", bql, sw.elapsed(TimeUnit.MILLISECONDS));
                }
                return response;
            }
        }
    });
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) LindenRequest(com.xiaomi.linden.thrift.common.LindenRequest) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException)

Example 4 with Response

use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.

the class CoreLindenServiceImpl method handleBqlRequest.

// handle single instance request called warmer
@Override
public Future<LindenResult> handleBqlRequest(final String bql) {
    final Stopwatch sw = Stopwatch.createStarted();
    return instanceExecutorPool.apply(new Function0<LindenResult>() {

        @Override
        public LindenResult apply() {
            LindenResult result = null;
            String logTag = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: instanceExecutorPool took " + eps + "ms to start handleBqlRequest.");
                    if (eps > instanceFuturePoolWaitTimeout) {
                        result = buildLindenFailedResult("Waiting time is too long, " + eps + "ms in instance future pool");
                        return result;
                    }
                }
                LindenRequest lindenRequest = bqlCompiler.compile(bql);
                if (lindenRequest.isSetSearchRequest()) {
                    LindenSearchRequest searchRequest = lindenRequest.getSearchRequest();
                    searchRequest.setOriginQuery(bql);
                    result = lindenCore.search(searchRequest);
                    if (result.isSuccess()) {
                        logTag = "singleInstanceSearch";
                    } else {
                        logTag = "failureSingleInstanceSearch";
                    }
                } else if (lindenRequest.isSetDeleteRequest()) {
                    Response response = lindenCore.delete(lindenRequest.getDeleteRequest());
                    result = new LindenResult().setSuccess(response.isSuccess()).setError(response.getError());
                    if (result.isSuccess()) {
                        logTag = "singleInstanceDelete";
                    } else {
                        logTag = "failureSingleInstanceDelete";
                    }
                } else {
                    result = buildLindenFailedResult("unsupported Bql");
                    logTag = "unsupportedSingleInstanceBql";
                }
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                result = buildLindenFailedResult(errorStackInfo);
                logTag = "exceptionalSingleInstanceRequest";
            } finally {
                metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
                result.setCost((int) sw.elapsed(TimeUnit.MILLISECONDS));
                if (result.isSuccess()) {
                    LOGGER.info("Single instance request succeeded bql: {}, hits: {}, cost: {} ms.", bql, result.getHitsSize(), result.getCost());
                } else {
                    LOGGER.error("Single instance request failed bql: {}, error: {}, cost: {} ms.", bql, result.getError(), result.getCost());
                }
                return result;
            }
        }
    });
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) LindenRequest(com.xiaomi.linden.thrift.common.LindenRequest) Stopwatch(com.google.common.base.Stopwatch) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) IOException(java.io.IOException)

Example 5 with Response

use of com.xiaomi.linden.thrift.common.Response in project linden by XiaoMi.

the class CoreLindenServiceImpl method executeCommand.

@Override
public Future<Response> executeCommand(final String command) {
    final Stopwatch sw = Stopwatch.createStarted();
    return instanceExecutorPool.apply(new Function0<Response>() {

        @Override
        public Response apply() {
            LOGGER.info("Receive command {}", command);
            Response response = null;
            try {
                long eps = sw.elapsed(TimeUnit.MILLISECONDS);
                if (eps > 10) {
                    LOGGER.warn("Warning: instanceExecutorPool took " + eps + "ms to start executeCommand.");
                    if (eps > instanceFuturePoolWaitTimeout) {
                        response = ResponseUtils.buildFailedResponse("Waiting time is too long, " + eps + "ms in instance future pool");
                        return response;
                    }
                }
                response = lindenCore.executeCommand(command);
            } catch (Exception e) {
                String errorStackInfo = Throwables.getStackTraceAsString(e);
                response = ResponseUtils.buildFailedResponse(errorStackInfo);
            } finally {
                if (response.isSuccess()) {
                    LOGGER.info("executeCommand succeeded, command: {}, cost: {} ms.", command, sw.elapsed(TimeUnit.MILLISECONDS));
                } else {
                    LOGGER.error("executeCommand failed, content: {}, cost: {} ms.", command, sw.elapsed(TimeUnit.MILLISECONDS));
                }
                return response;
            }
        }
    });
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException)

Aggregations

Response (com.xiaomi.linden.thrift.common.Response)18 IOException (java.io.IOException)14 Stopwatch (com.google.common.base.Stopwatch)8 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Future (com.twitter.util.Future)3 FutureTransformer (com.twitter.util.FutureTransformer)3 LindenRequest (com.xiaomi.linden.thrift.common.LindenRequest)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ExecutionException (java.util.concurrent.ExecutionException)3 LindenIndexRequest (com.xiaomi.linden.thrift.common.LindenIndexRequest)2 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)2 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)2 TException (org.apache.thrift.TException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 JSONObject (com.alibaba.fastjson.JSONObject)1 DocNumLimitMultiIndexStrategy (com.xiaomi.linden.core.indexing.DocNumLimitMultiIndexStrategy)1 TimeLimitMultiIndexStrategy (com.xiaomi.linden.core.indexing.TimeLimitMultiIndexStrategy)1