Search in sources :

Example 11 with IndexEventListener

use of org.elasticsearch.index.shard.IndexEventListener in project elasticsearch by elastic.

the class IndexModule method newIndexService.

public IndexService newIndexService(NodeEnvironment environment, NamedXContentRegistry xContentRegistry, IndexService.ShardStoreDeleter shardStoreDeleter, CircuitBreakerService circuitBreakerService, BigArrays bigArrays, ThreadPool threadPool, ScriptService scriptService, ClusterService clusterService, Client client, IndicesQueryCache indicesQueryCache, MapperRegistry mapperRegistry, Consumer<ShardId> globalCheckpointSyncer, IndicesFieldDataCache indicesFieldDataCache) throws IOException {
    final IndexEventListener eventListener = freeze();
    IndexSearcherWrapperFactory searcherWrapperFactory = indexSearcherWrapper.get() == null ? (shard) -> null : indexSearcherWrapper.get();
    eventListener.beforeIndexCreated(indexSettings.getIndex(), indexSettings.getSettings());
    final String storeType = indexSettings.getValue(INDEX_STORE_TYPE_SETTING);
    final IndexStore store;
    if (Strings.isEmpty(storeType) || isBuiltinType(storeType)) {
        store = new IndexStore(indexSettings);
    } else {
        Function<IndexSettings, IndexStore> factory = storeTypes.get(storeType);
        if (factory == null) {
            throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
        }
        store = factory.apply(indexSettings);
        if (store == null) {
            throw new IllegalStateException("store must not be null");
        }
    }
    final QueryCache queryCache;
    if (indexSettings.getValue(INDEX_QUERY_CACHE_ENABLED_SETTING)) {
        BiFunction<IndexSettings, IndicesQueryCache, QueryCache> queryCacheProvider = forceQueryCacheProvider.get();
        if (queryCacheProvider == null) {
            queryCache = new IndexQueryCache(indexSettings, indicesQueryCache);
        } else {
            queryCache = queryCacheProvider.apply(indexSettings, indicesQueryCache);
        }
    } else {
        queryCache = new DisabledQueryCache(indexSettings);
    }
    return new IndexService(indexSettings, environment, xContentRegistry, new SimilarityService(indexSettings, similarities), shardStoreDeleter, analysisRegistry, engineFactory.get(), circuitBreakerService, bigArrays, threadPool, scriptService, clusterService, client, queryCache, store, eventListener, searcherWrapperFactory, mapperRegistry, indicesFieldDataCache, globalCheckpointSyncer, searchOperationListeners, indexOperationListeners);
}
Also used : IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) IndicesQueryCache(org.elasticsearch.indices.IndicesQueryCache) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) QueryCache(org.elasticsearch.index.cache.query.QueryCache) IndexQueryCache(org.elasticsearch.index.cache.query.IndexQueryCache) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) IndexStore(org.elasticsearch.index.store.IndexStore) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache)

Example 12 with IndexEventListener

use of org.elasticsearch.index.shard.IndexEventListener in project crate by crate.

the class IndicesService method createIndexService.

/**
 * This creates a new IndexService without registering itcreateIndex
 */
private synchronized IndexService createIndexService(IndexCreationContext indexCreationContext, IndexMetadata indexMetadata, IndicesQueryCache indicesQueryCache, List<IndexEventListener> builtInListeners, IndexingOperationListener... indexingOperationListeners) throws IOException {
    final IndexSettings idxSettings = new IndexSettings(indexMetadata, this.settings, indexScopedSettings);
    // we ignore private settings since they are not registered settings
    indexScopedSettings.validate(indexMetadata.getSettings(), true, true, true);
    LOGGER.debug("creating Index [{}], shards [{}]/[{}] - reason [{}]", indexMetadata.getIndex(), idxSettings.getNumberOfShards(), idxSettings.getNumberOfReplicas(), indexCreationContext);
    final IndexModule indexModule = new IndexModule(idxSettings, analysisRegistry, getEngineFactory(idxSettings), directoryFactories);
    for (IndexingOperationListener operationListener : indexingOperationListeners) {
        indexModule.addIndexOperationListener(operationListener);
    }
    pluginsService.onIndexModule(indexModule);
    for (IndexEventListener listener : builtInListeners) {
        indexModule.addIndexEventListener(listener);
    }
    return indexModule.newIndexService(indexCreationContext, nodeEnv, xContentRegistry, this, circuitBreakerService, bigArrays, threadPool, indicesQueryCache, mapperRegistry);
}
Also used : IndexingOperationListener(org.elasticsearch.index.shard.IndexingOperationListener) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IndexSettings(org.elasticsearch.index.IndexSettings) IndexModule(org.elasticsearch.index.IndexModule)

Example 13 with IndexEventListener

use of org.elasticsearch.index.shard.IndexEventListener in project crate by crate.

the class IndicesService method createIndex.

/**
 * Creates a new {@link IndexService} for the given metadata.
 *
 * @param indexMetadata          the index metadata to create the index for
 * @param builtInListeners       a list of built-in lifecycle {@link IndexEventListener} that should should be used along side with the
 *                               per-index listeners
 * @throws ResourceAlreadyExistsException if the index already exists.
 */
@Override
public synchronized IndexService createIndex(final IndexMetadata indexMetadata, final List<IndexEventListener> builtInListeners, final boolean writeDanglingIndices) throws IOException {
    ensureChangesAllowed();
    if (indexMetadata.getIndexUUID().equals(IndexMetadata.INDEX_UUID_NA_VALUE)) {
        throw new IllegalArgumentException("index must have a real UUID found value: [" + indexMetadata.getIndexUUID() + "]");
    }
    final Index index = indexMetadata.getIndex();
    if (hasIndex(index)) {
        throw new ResourceAlreadyExistsException(index);
    }
    List<IndexEventListener> finalListeners = new ArrayList<>(builtInListeners);
    final IndexEventListener onStoreClose = new IndexEventListener() {

        @Override
        public void onStoreCreated(ShardId shardId) {
            indicesRefCount.incRef();
        }

        @Override
        public void onStoreClosed(ShardId shardId) {
            try {
                indicesRefCount.decRef();
            } finally {
                indicesQueryCache.onClose(shardId);
            }
        }
    };
    finalListeners.add(onStoreClose);
    final IndexService indexService = createIndexService(IndexCreationContext.CREATE_INDEX, indexMetadata, indicesQueryCache, finalListeners, indexingMemoryController);
    boolean success = false;
    try {
        if (writeDanglingIndices && nodeWriteDanglingIndicesInfo) {
            indexService.addMetadataListener(imd -> updateDanglingIndicesInfo(index));
        }
        indexService.getIndexEventListener().afterIndexCreated(indexService);
        indices = newMapBuilder(indices).put(index.getUUID(), indexService).immutableMap();
        if (writeDanglingIndices) {
            if (nodeWriteDanglingIndicesInfo) {
                updateDanglingIndicesInfo(index);
            } else {
                indexService.deleteDanglingIndicesInfo();
            }
        }
        success = true;
        return indexService;
    } finally {
        if (success == false) {
            indexService.close("plugins_failed", true);
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) IndexService(org.elasticsearch.index.IndexService) ArrayList(java.util.ArrayList) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) Index(org.elasticsearch.index.Index)

Aggregations

IndexEventListener (org.elasticsearch.index.shard.IndexEventListener)13 IndexSettings (org.elasticsearch.index.IndexSettings)6 Index (org.elasticsearch.index.Index)5 IndexService (org.elasticsearch.index.IndexService)5 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)4 ShardId (org.elasticsearch.index.shard.ShardId)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 Settings (org.elasticsearch.common.settings.Settings)3 IndexShard (org.elasticsearch.index.shard.IndexShard)3 MockIndexEventListener (org.elasticsearch.test.MockIndexEventListener)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)2 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)2 Nullable (org.elasticsearch.common.Nullable)2