Ejemplo n.º 1
0
 public synchronized void updateMetaData(final IndexMetaData metadata) {
   if (indexSettings.updateIndexMetaData(metadata)) {
     final Settings settings = indexSettings.getSettings();
     for (final IndexShard shard : this.shards.values()) {
       try {
         shard.onRefreshSettings(settings);
       } catch (Exception e) {
         logger.warn("[{}] failed to refresh shard settings", e, shard.shardId().id());
       }
     }
     try {
       indexStore.onRefreshSettings(settings);
     } catch (Exception e) {
       logger.warn("failed to refresh index store settings", e);
     }
     try {
       slowLog.onRefreshSettings(
           settings); // this will be refactored soon anyway so duplication is ok here
     } catch (Exception e) {
       logger.warn("failed to refresh slowlog settings", e);
     }
     if (refreshTask.getInterval().equals(indexSettings.getRefreshInterval()) == false) {
       rescheduleRefreshTasks();
     }
   }
 }
Ejemplo n.º 2
0
  public IndexService(
      IndexSettings indexSettings,
      NodeEnvironment nodeEnv,
      SimilarityService similarityService,
      ShardStoreDeleter shardStoreDeleter,
      AnalysisRegistry registry,
      @Nullable EngineFactory engineFactory,
      NodeServicesProvider nodeServicesProvider,
      QueryCache queryCache,
      IndexStore indexStore,
      IndexEventListener eventListener,
      IndexModule.IndexSearcherWrapperFactory wrapperFactory,
      MapperRegistry mapperRegistry,
      IndexingOperationListener... listenersIn)
      throws IOException {
    super(indexSettings);
    this.indexSettings = indexSettings;
    this.analysisService = registry.build(indexSettings);
    this.similarityService = similarityService;
    this.mapperService =
        new MapperService(
            indexSettings,
            analysisService,
            similarityService,
            mapperRegistry,
            IndexService.this::getQueryShardContext);
    this.indexFieldData =
        new IndexFieldDataService(
            indexSettings,
            nodeServicesProvider.getIndicesFieldDataCache(),
            nodeServicesProvider.getCircuitBreakerService(),
            mapperService);
    this.shardStoreDeleter = shardStoreDeleter;
    this.eventListener = eventListener;
    this.nodeEnv = nodeEnv;
    this.nodeServicesProvider = nodeServicesProvider;
    this.indexStore = indexStore;
    indexFieldData.setListener(new FieldDataCacheListener(this));
    this.bitsetFilterCache =
        new BitsetFilterCache(
            indexSettings, nodeServicesProvider.getWarmer(), new BitsetCacheListener(this));
    this.indexCache = new IndexCache(indexSettings, queryCache, bitsetFilterCache);
    this.engineFactory = engineFactory;
    // initialize this last -- otherwise if the wrapper requires any other member to be non-null we
    // fail with an NPE
    this.searcherWrapper = wrapperFactory.newWrapper(this);
    this.slowLog = new IndexingSlowLog(indexSettings.getSettings());

    // Add our slowLog to the incoming IndexingOperationListeners:
    this.listeners = new IndexingOperationListener[1 + listenersIn.length];
    this.listeners[0] = slowLog;
    System.arraycopy(listenersIn, 0, this.listeners, 1, listenersIn.length);
    // kick off async ops for the first shard in this index
    if (this.indexSettings.getTranslogSyncInterval().millis() != 0) {
      this.fsyncTask = new AsyncTranslogFSync(this);
    } else {
      this.fsyncTask = null;
    }
    this.refreshTask = new AsyncRefreshTask(this);
  }
Ejemplo n.º 3
0
 private void onShardClose(ShardLock lock, boolean ownsShard) {
   if (deleted.get()) { // we remove that shards content if this index has been deleted
     try {
       if (ownsShard) {
         try {
           eventListener.beforeIndexShardDeleted(lock.getShardId(), indexSettings.getSettings());
         } finally {
           shardStoreDeleter.deleteShardStore("delete index", lock, indexSettings);
           eventListener.afterIndexShardDeleted(lock.getShardId(), indexSettings.getSettings());
         }
       }
     } catch (IOException e) {
       shardStoreDeleter.addPendingDelete(lock.getShardId(), indexSettings);
       logger.debug(
           "[{}] failed to delete shard content - scheduled a retry", e, lock.getShardId().id());
     }
   }
 }
Ejemplo n.º 4
0
 public IndexService(
     IndexSettings indexSettings,
     NodeEnvironment nodeEnv,
     SimilarityService similarityService,
     ShardStoreDeleter shardStoreDeleter,
     AnalysisRegistry registry,
     @Nullable EngineFactory engineFactory,
     NodeServicesProvider nodeServicesProvider,
     QueryCache queryCache,
     IndexStore indexStore,
     IndexEventListener eventListener,
     IndexModule.IndexSearcherWrapperFactory wrapperFactory,
     MapperRegistry mapperRegistry,
     IndicesFieldDataCache indicesFieldDataCache,
     List<SearchOperationListener> searchOperationListeners,
     List<IndexingOperationListener> indexingOperationListeners)
     throws IOException {
   super(indexSettings);
   this.indexSettings = indexSettings;
   this.analysisService = registry.build(indexSettings);
   this.similarityService = similarityService;
   this.mapperService =
       new MapperService(
           indexSettings,
           analysisService,
           similarityService,
           mapperRegistry,
           IndexService.this::newQueryShardContext);
   this.indexFieldData =
       new IndexFieldDataService(
           indexSettings,
           indicesFieldDataCache,
           nodeServicesProvider.getCircuitBreakerService(),
           mapperService);
   this.shardStoreDeleter = shardStoreDeleter;
   this.bigArrays = nodeServicesProvider.getBigArrays();
   this.threadPool = nodeServicesProvider.getThreadPool();
   this.eventListener = eventListener;
   this.nodeEnv = nodeEnv;
   this.nodeServicesProvider = nodeServicesProvider;
   this.indexStore = indexStore;
   indexFieldData.setListener(new FieldDataCacheListener(this));
   this.bitsetFilterCache = new BitsetFilterCache(indexSettings, new BitsetCacheListener(this));
   this.warmer =
       new IndexWarmer(
           indexSettings.getSettings(), threadPool, bitsetFilterCache.createListener(threadPool));
   this.indexCache = new IndexCache(indexSettings, queryCache, bitsetFilterCache);
   this.engineFactory = engineFactory;
   // initialize this last -- otherwise if the wrapper requires any other member to be non-null we
   // fail with an NPE
   this.searcherWrapper = wrapperFactory.newWrapper(this);
   this.indexingOperationListeners = Collections.unmodifiableList(indexingOperationListeners);
   this.searchOperationListeners = Collections.unmodifiableList(searchOperationListeners);
   // kick off async ops for the first shard in this index
   this.refreshTask = new AsyncRefreshTask(this);
   rescheduleFsyncTask(indexSettings.getTranslogDurability());
 }
Ejemplo n.º 5
0
 public IndexService newIndexService(
     NodeEnvironment environment,
     IndexService.ShardStoreDeleter shardStoreDeleter,
     NodeServicesProvider servicesProvider)
     throws IOException {
   final IndexSettings settings = indexSettings.newWithListener(settingsConsumers);
   IndexSearcherWrapperFactory searcherWrapperFactory =
       indexSearcherWrapper.get() == null ? (shard) -> null : indexSearcherWrapper.get();
   IndexEventListener eventListener = freeze();
   final String storeType = settings.getSettings().get(STORE_TYPE);
   final IndexStore store;
   if (storeType == null || isBuiltinType(storeType)) {
     store = new IndexStore(settings, indexStoreConfig);
   } else {
     BiFunction<IndexSettings, IndexStoreConfig, IndexStore> factory = storeTypes.get(storeType);
     if (factory == null) {
       throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
     }
     store = factory.apply(settings, indexStoreConfig);
     if (store == null) {
       throw new IllegalStateException("store must not be null");
     }
   }
   final String queryCacheType =
       settings.getSettings().get(IndexModule.QUERY_CACHE_TYPE, IndexModule.INDEX_QUERY_CACHE);
   final BiFunction<IndexSettings, IndicesQueryCache, QueryCache> queryCacheProvider =
       queryCaches.get(queryCacheType);
   final QueryCache queryCache =
       queryCacheProvider.apply(settings, servicesProvider.getIndicesQueryCache());
   return new IndexService(
       settings,
       environment,
       new SimilarityService(settings, similarities),
       shardStoreDeleter,
       analysisRegistry,
       engineFactory.get(),
       servicesProvider,
       queryCache,
       store,
       eventListener,
       searcherWrapperFactory);
 }
Ejemplo n.º 6
0
 /** Returns the index {@link Settings} for this index */
 public Settings getSettings() {
   return indexSettings.getSettings();
 }