Search in sources :

Example 1 with LindenServiceInfo

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

the class TestMultiLindenCore method testDocNumDivision.

@Test
public void testDocNumDivision() throws Exception {
    String path = FilenameUtils.concat(INDEX_DIR, "size/");
    lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.HOTSWAP).setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.DOC_NUM).setMultiIndexDocNumLimit(100).setMultiIndexMaxLiveIndexNum(4);
    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(4, 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 + 400);
        content.put("title", "test " + i);
        json.put("content", content);
        handleRequest(json.toJSONString());
    }
    lindenCore.commit();
    lindenCore.refresh();
    LindenServiceInfo serviceInfo = lindenCore.getServiceInfo();
    Assert.assertEquals(4, serviceInfo.getIndexNamesSize());
    Assert.assertEquals(400, serviceInfo.getDocsNum());
    lindenCore.close();
}
Also used : LindenServiceInfo(com.xiaomi.linden.thrift.common.LindenServiceInfo) LindenResult(com.xiaomi.linden.thrift.common.LindenResult) JSONObject(com.alibaba.fastjson.JSONObject) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) MultiLindenCoreImpl(com.xiaomi.linden.core.search.MultiLindenCoreImpl) Test(org.junit.Test)

Example 2 with LindenServiceInfo

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

the class CoreLindenServiceImpl method getServiceInfo.

@Override
public Future<LindenServiceInfo> getServiceInfo() {
    return instanceExecutorPool.apply(new Function0<LindenServiceInfo>() {

        @Override
        public LindenServiceInfo apply() {
            LindenServiceInfo serviceInfo;
            try {
                serviceInfo = lindenCore.getServiceInfo();
                CacheInfo cacheInfo = lindenCluster.getCacheInfo();
                serviceInfo.setCacheInfo(cacheInfo);
            } catch (Exception e) {
                serviceInfo = new LindenServiceInfo();
                LOGGER.error("get service info failed : {}", Throwables.getStackTraceAsString(e));
            }
            return serviceInfo;
        }
    });
}
Also used : LindenServiceInfo(com.xiaomi.linden.thrift.common.LindenServiceInfo) CacheInfo(com.xiaomi.linden.thrift.common.CacheInfo) IOException(java.io.IOException)

Example 3 with LindenServiceInfo

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

the class HotSwapLindenCoreImpl method getServiceInfo.

@Override
public LindenServiceInfo getServiceInfo() throws IOException {
    LindenServiceInfo serviceInfo = currentLindenCore.getServiceInfo();
    List<String> indexNames = new ArrayList<>();
    for (Map.Entry<String, LindenCore> entry : lindenCoreMap.entrySet()) {
        indexNames.add(entry.getKey());
    }
    List<String> paths = new ArrayList<>();
    if (baseIndexDir != null) {
        paths.add(baseIndexDir);
    }
    if (lindenConfig.getLogPath() != null) {
        paths.add(lindenConfig.getLogPath());
    }
    List<FileDiskUsageInfo> fileUsedInfos = RuntimeInfoUtils.getRuntimeFileInfo(paths);
    serviceInfo.setIndexNames(indexNames).setFileUsedInfos(fileUsedInfos);
    return serviceInfo;
}
Also used : LindenServiceInfo(com.xiaomi.linden.thrift.common.LindenServiceInfo) FileDiskUsageInfo(com.xiaomi.linden.thrift.common.FileDiskUsageInfo) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map)

Example 4 with LindenServiceInfo

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

the class LindenCoreImpl method getServiceInfo.

@Override
public LindenServiceInfo getServiceInfo() throws IOException {
    int docNum = trackingIndexWriter.getIndexWriter().numDocs();
    List<String> paths = new ArrayList<>();
    if (config.getIndexDirectory() != null) {
        paths.add(config.getIndexDirectory());
    }
    if (config.getLogPath() != null) {
        paths.add(config.getLogPath());
    }
    List<FileDiskUsageInfo> fileDiskUsageInfos = RuntimeInfoUtils.getRuntimeFileInfo(paths);
    SearcherTaxonomyManager.SearcherAndTaxonomy searcherAndTaxonomy = lindenNRTSearcherManager.acquire();
    int segmentNum;
    try {
        segmentNum = searcherAndTaxonomy.searcher.getIndexReader().leaves().size();
    } catch (Exception e) {
        throw new IOException(e);
    } finally {
        lindenNRTSearcherManager.release(searcherAndTaxonomy);
    }
    List<Integer> segmentNums = new ArrayList<>();
    segmentNums.add(segmentNum);
    return new LindenServiceInfo().setDocsNum(docNum).setJvmInfo(RuntimeInfoUtils.getJVMInfo()).setFileUsedInfos(fileDiskUsageInfos).setSegmentNums(segmentNums);
}
Also used : LindenServiceInfo(com.xiaomi.linden.thrift.common.LindenServiceInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) SearcherTaxonomyManager(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager) FileDiskUsageInfo(com.xiaomi.linden.thrift.common.FileDiskUsageInfo)

Example 5 with LindenServiceInfo

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

the class MultiLindenCoreImpl method getServiceInfo.

@Override
public LindenServiceInfo getServiceInfo() throws IOException {
    int docsNum = 0;
    LindenServiceInfo serviceInfo = new LindenServiceInfo();
    List<String> indexNames = new ArrayList<>();
    List<Integer> segmentNums = new ArrayList<>();
    for (Map.Entry<String, LindenCore> entry : lindenCoreMap.entrySet()) {
        serviceInfo = entry.getValue().getServiceInfo();
        docsNum += serviceInfo.getDocsNum();
        indexNames.add(entry.getKey());
        segmentNums.add(serviceInfo.getSegmentNums().get(0));
    }
    List<String> paths = new ArrayList<>();
    if (baseIndexDir != null) {
        paths.add(baseIndexDir);
    }
    if (config.getLogPath() != null) {
        paths.add(config.getLogPath());
    }
    List<FileDiskUsageInfo> fileUsedInfos = RuntimeInfoUtils.getRuntimeFileInfo(paths);
    serviceInfo.setDocsNum(docsNum).setIndexNames(indexNames).setFileUsedInfos(fileUsedInfos).setSegmentNums(segmentNums);
    return serviceInfo;
}
Also used : LindenServiceInfo(com.xiaomi.linden.thrift.common.LindenServiceInfo) FileDiskUsageInfo(com.xiaomi.linden.thrift.common.FileDiskUsageInfo) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

LindenServiceInfo (com.xiaomi.linden.thrift.common.LindenServiceInfo)5 FileDiskUsageInfo (com.xiaomi.linden.thrift.common.FileDiskUsageInfo)3 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 JSONObject (com.alibaba.fastjson.JSONObject)1 MultiLindenCoreImpl (com.xiaomi.linden.core.search.MultiLindenCoreImpl)1 CacheInfo (com.xiaomi.linden.thrift.common.CacheInfo)1 LindenResult (com.xiaomi.linden.thrift.common.LindenResult)1 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)1 SearcherTaxonomyManager (org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager)1 Test (org.junit.Test)1