Search in sources :

Example 1 with TimeLimitMultiIndexStrategy

use of com.xiaomi.linden.core.indexing.TimeLimitMultiIndexStrategy in project linden by XiaoMi.

the class MultiLindenCoreImpl method delete.

@Override
public Response delete(LindenDeleteRequest request) throws IOException {
    List<String> indexNames;
    // Only INDEX_NAME division type supports specified index name request
    if (multiIndexStrategy instanceof TimeLimitMultiIndexStrategy || multiIndexStrategy instanceof DocNumLimitMultiIndexStrategy) {
        indexNames = new ArrayList<>(lindenCoreMap.keySet());
    } else {
        if (request.getIndexNames() == null || (request.getIndexNamesSize() == 1 && request.getIndexNames().get(0).equals(LINDEN))) {
            indexNames = new ArrayList<>(lindenCoreMap.keySet());
        } else {
            indexNames = request.getIndexNames();
            for (int i = 0; i < indexNames.size(); ++i) {
                indexNames.set(i, MultiIndexStrategy.MULTI_INDEX_PREFIX_NAME + indexNames.get(i));
            }
        }
    }
    StringBuilder errorInfo = new StringBuilder();
    for (final String indexName : indexNames) {
        final LindenCore core = lindenCoreMap.get(indexName);
        if (core != null) {
            try {
                Response response = core.delete(request);
                if (!response.isSuccess()) {
                    errorInfo.append(indexName + ":" + response.getError() + ";");
                    LOGGER.error("Multi-index {} delete error: {}", indexName, response.error);
                }
            } catch (Exception e) {
                errorInfo.append(indexName + ":" + Throwables.getStackTraceAsString(e) + ";");
                LOGGER.error("Multi-index {} delete error: {}", indexName, Throwables.getStackTraceAsString(e));
            }
        } else {
            errorInfo.append(indexName + " doesn't exist");
            LOGGER.error("Multi-index {} delete error: " + indexName + " doesn't exist");
        }
    }
    if (errorInfo.length() > 0) {
        return ResponseUtils.buildFailedResponse("Multi-index delete error: " + errorInfo.toString());
    } else {
        return ResponseUtils.SUCCESS;
    }
}
Also used : Response(com.xiaomi.linden.thrift.common.Response) DocNumLimitMultiIndexStrategy(com.xiaomi.linden.core.indexing.DocNumLimitMultiIndexStrategy) TimeLimitMultiIndexStrategy(com.xiaomi.linden.core.indexing.TimeLimitMultiIndexStrategy) IOException(java.io.IOException)

Example 2 with TimeLimitMultiIndexStrategy

use of com.xiaomi.linden.core.indexing.TimeLimitMultiIndexStrategy in project linden by XiaoMi.

the class MultiLindenCoreImpl method deleteIndex.

private Response deleteIndex(LindenIndexRequest request) throws IOException {
    // Only INDEX_NAME division type supports index delete
    if (multiIndexStrategy instanceof TimeLimitMultiIndexStrategy || multiIndexStrategy instanceof DocNumLimitMultiIndexStrategy) {
        return ResponseUtils.buildFailedResponse("Index delete is not supported in current multi-index core");
    }
    if (request.getIndexName() == null) {
        return ResponseUtils.buildFailedResponse("Index name is not set in index delete request.");
    }
    String fullIndexName = MultiIndexStrategy.MULTI_INDEX_PREFIX_NAME + request.getIndexName();
    if (lindenCoreMap.containsKey(fullIndexName)) {
        LindenCore core = lindenCoreMap.remove(fullIndexName);
        if (core != null) {
            core.close();
        }
        if (config.getIndexType() != LindenConfig.IndexType.RAM) {
            String dir = FilenameUtils.concat(baseIndexDir, fullIndexName);
            String destDir = FilenameUtils.concat(baseIndexDir, "delete_" + fullIndexName);
            if (new File(dir).exists()) {
                FileUtils.moveDirectory(new File(dir), new File(destDir));
            }
        }
        return ResponseUtils.SUCCESS;
    }
    return ResponseUtils.buildFailedResponse("Index " + request.getIndexName() + " is not found.");
}
Also used : DocNumLimitMultiIndexStrategy(com.xiaomi.linden.core.indexing.DocNumLimitMultiIndexStrategy) TimeLimitMultiIndexStrategy(com.xiaomi.linden.core.indexing.TimeLimitMultiIndexStrategy) File(java.io.File)

Aggregations

DocNumLimitMultiIndexStrategy (com.xiaomi.linden.core.indexing.DocNumLimitMultiIndexStrategy)2 TimeLimitMultiIndexStrategy (com.xiaomi.linden.core.indexing.TimeLimitMultiIndexStrategy)2 Response (com.xiaomi.linden.thrift.common.Response)1 File (java.io.File)1 IOException (java.io.IOException)1