public IndexService newIndexService(
     NodeEnvironment environment,
     IndexService.ShardStoreDeleter shardStoreDeleter,
     NodeServicesProvider servicesProvider,
     MapperRegistry mapperRegistry,
     IndexingOperationListener... listeners)
     throws IOException {
   IndexSearcherWrapperFactory searcherWrapperFactory =
       indexSearcherWrapper.get() == null ? (shard) -> null : indexSearcherWrapper.get();
   IndexEventListener eventListener = freeze();
   final String storeType = indexSettings.getValue(INDEX_STORE_TYPE_SETTING);
   final IndexStore store;
   if (Strings.isEmpty(storeType) || isBuiltinType(storeType)) {
     store = new IndexStore(indexSettings, indexStoreConfig);
   } else {
     BiFunction<IndexSettings, IndexStoreConfig, IndexStore> factory = storeTypes.get(storeType);
     if (factory == null) {
       throw new IllegalArgumentException("Unknown store type [" + storeType + "]");
     }
     store = factory.apply(indexSettings, indexStoreConfig);
     if (store == null) {
       throw new IllegalStateException("store must not be null");
     }
   }
   indexSettings
       .getScopedSettings()
       .addSettingsUpdateConsumer(
           IndexStore.INDEX_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING, store::setMaxRate);
   indexSettings
       .getScopedSettings()
       .addSettingsUpdateConsumer(IndexStore.INDEX_STORE_THROTTLE_TYPE_SETTING, store::setType);
   final String queryCacheType = indexSettings.getValue(INDEX_QUERY_CACHE_TYPE_SETTING);
   final BiFunction<IndexSettings, IndicesQueryCache, QueryCache> queryCacheProvider =
       queryCaches.get(queryCacheType);
   final QueryCache queryCache =
       queryCacheProvider.apply(indexSettings, servicesProvider.getIndicesQueryCache());
   return new IndexService(
       indexSettings,
       environment,
       new SimilarityService(indexSettings, similarities),
       shardStoreDeleter,
       analysisRegistry,
       engineFactory.get(),
       servicesProvider,
       queryCache,
       store,
       eventListener,
       searcherWrapperFactory,
       mapperRegistry,
       listeners);
 }
 /**
  * Returns true if this single info is already fully merged (has no pending deletes, is in the
  * same dir as the writer, and matches the current compound file setting
  */
 protected final boolean isMerged(SegmentInfos infos, SegmentCommitInfo info) throws IOException {
   IndexWriter w = writer.get();
   assert w != null;
   boolean hasDeletions = w.numDeletedDocs(info) > 0;
   return !hasDeletions
       && !info.info.hasSeparateNorms()
       && info.info.dir == w.getDirectory()
       && useCompoundFile(infos, info) == info.info.getUseCompoundFile();
 }
 /**
  * Return the byte size of the provided {@link SegmentCommitInfo}, pro-rated by percentage of
  * non-deleted documents is set.
  */
 protected long size(SegmentCommitInfo info) throws IOException {
   long byteSize = info.sizeInBytes();
   int delCount = writer.get().numDeletedDocs(info);
   double delRatio =
       (info.info.getDocCount() <= 0
           ? 0.0f
           : ((float) delCount / (float) info.info.getDocCount()));
   assert delRatio <= 1.0;
   return (info.info.getDocCount() <= 0 ? byteSize : (long) (byteSize * (1.0 - delRatio)));
 }
Пример #4
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);
 }