use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestMultiLindenCore method testTimeDivision.
@Test
public void testTimeDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "time/");
lindenConfig.setIndexDirectory(path).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.TIME_HOUR).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexMaxLiveIndexNum(10);
Deencapsulation.setField(DocNumLimitMultiIndexStrategy.class, "INDEX_CHECK_INTERVAL_MILLISECONDS", -10);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + i);
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(8, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(400, lindenCore.getServiceInfo().getDocsNum());
String bql = "select * from linden source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(400, result.getTotalHits());
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + (400 + i));
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
result = lindenCore.search(request);
Assert.assertEquals(500, result.getTotalHits());
Assert.assertEquals(10, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(500, lindenCore.getServiceInfo().getDocsNum());
bql = "delete from linden where query is 'title:400 title:401'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(498, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class TestMultiLindenCore method testIndexNameDivision.
@Test
public void testIndexNameDivision() throws Exception {
String path = FilenameUtils.concat(INDEX_DIR, "name/");
lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.INDEX_NAME);
lindenCore = new MultiLindenCoreImpl(lindenConfig);
for (int i = 0; i < 400; ++i) {
JSONObject json = new JSONObject();
json.put("type", "index");
json.put("index", "multi_" + i / 50);
JSONObject content = new JSONObject();
content.put("id", i);
content.put("title", "test " + i);
json.put("content", content);
handleRequest(json.toJSONString());
}
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(8, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(400, lindenCore.getServiceInfo().getDocsNum());
String bql = "select * from linden source";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
LindenResult result = lindenCore.search(request);
Assert.assertEquals(400, result.getTotalHits());
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(50, result.getTotalHits());
bql = "select * from non-existed source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
bql = "select * from multi_1, multi_2 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertEquals(100, result.getTotalHits());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_0\"}");
bql = "select * from multi_0 source";
request = bqlCompiler.compile(bql).getSearchRequest();
result = lindenCore.search(request);
Assert.assertFalse(result.isSuccess());
handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_2\"}");
Assert.assertEquals(6, lindenCore.getServiceInfo().getIndexNamesSize());
Assert.assertEquals(300, lindenCore.getServiceInfo().getDocsNum());
// delete doc 50, 200, 300, 390, 397, doc 0 and doc 100 doesn't exist since multi_0 and multi_1 index are deleted
bql = "delete from linden where query is 'title:0 title:50 title:100 title:200 title:300 title:390 title:397'";
LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest();
lindenCore.delete(deleteRequest);
lindenCore.commit();
lindenCore.refresh();
Assert.assertEquals(295, lindenCore.getServiceInfo().getDocsNum());
lindenCore.close();
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class CoreLindenServiceImpl method search.
@Override
public Future<LindenResult> search(final LindenSearchRequest request) {
final Stopwatch sw = Stopwatch.createStarted();
return instanceExecutorPool.apply(new Function0<LindenResult>() {
@Override
public LindenResult apply() {
LindenResult result = null;
String logTag = null;
long eps = 0;
try {
eps = sw.elapsed(TimeUnit.MILLISECONDS);
if (eps > 10) {
LOGGER.warn("Warning: instanceExecutorPool took " + eps + "ms to start search.");
if (eps > instanceFuturePoolWaitTimeout) {
result = buildLindenFailedResult("Waiting time is too long, " + eps + "ms in instance future pool");
logTag = "instancePoolWaitTimeout";
return result;
}
}
result = lindenCore.search(request);
if (result.isSuccess()) {
logTag = "instanceSearch";
} else {
logTag = "instanceFailureSearch";
}
} catch (Exception e) {
String errorStackInfo = Throwables.getStackTraceAsString(e);
result = buildLindenFailedResult(errorStackInfo);
logTag = "instanceExceptionalSearch";
} finally {
metricsManager.time(sw.elapsed(TimeUnit.NANOSECONDS), logTag);
long cost = sw.elapsed(TimeUnit.MILLISECONDS);
result.setCost((int) cost);
if (result.isSuccess()) {
if (cost >= slowQueryThresholdMillis) {
SLOW_LOGGER.warn("Slow request: {}, totalHits: {}, waits: {} ms , cost: {} ms.", request.getOriginQuery(), result.getTotalHits(), eps, result.getCost());
} else {
LOGGER.info("Instance search request succeeded, request: {}, hits: {}, cost: {} ms.", request.getOriginQuery(), result.getHitsSize(), result.getCost());
}
} else {
LOGGER.error("Instance search request failed, request: {}, error: {}, cost: {} ms.", request.getOriginQuery(), result.getError(), result.getCost());
}
return result;
}
}
});
}
use of com.xiaomi.linden.thrift.common.LindenResult in project linden by XiaoMi.
the class LindenController method search.
@RequestMapping(value = "/search", method = RequestMethod.GET)
@ResponseBody
public String search(@RequestParam("bql") String bql) {
LindenResult result;
try {
Future<LindenResult> future = LindenAdmin.getService().handleClusterSearchRequest(bql);
result = Await.result(future, Duration.apply(30000, TimeUnit.MILLISECONDS));
} catch (Exception e) {
result = new LindenResult();
result.setSuccess(false).setError(Throwables.getStackTraceAsString(e));
}
return ThriftToJSON(result);
}
Aggregations