2010-02-08 15:30:06 +02:00
|
|
|
/*
|
2011-12-06 02:42:25 +02:00
|
|
|
* Licensed to ElasticSearch and Shay Banon under one
|
2010-02-08 15:30:06 +02:00
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
2011-12-06 02:42:25 +02:00
|
|
|
* regarding copyright ownership. ElasticSearch licenses this
|
2010-02-08 15:30:06 +02:00
|
|
|
* file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2010-02-25 20:20:54 +02:00
|
|
|
package org.elasticsearch.index.service;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
import com.google.common.collect.UnmodifiableIterator;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.ElasticSearchException;
|
2011-02-01 23:10:15 +02:00
|
|
|
import org.elasticsearch.ElasticSearchIllegalStateException;
|
2010-07-19 02:17:59 +03:00
|
|
|
import org.elasticsearch.ElasticSearchInterruptedException;
|
2013-09-25 17:05:11 +02:00
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
2011-06-10 03:48:43 +03:00
|
|
|
import org.elasticsearch.common.Nullable;
|
2011-12-06 02:42:25 +02:00
|
|
|
import org.elasticsearch.common.inject.*;
|
2010-06-15 16:51:38 +03:00
|
|
|
import org.elasticsearch.common.settings.Settings;
|
2010-11-03 15:34:30 +02:00
|
|
|
import org.elasticsearch.env.NodeEnvironment;
|
2011-12-06 02:42:25 +02:00
|
|
|
import org.elasticsearch.index.*;
|
2011-05-21 19:53:17 -04:00
|
|
|
import org.elasticsearch.index.aliases.IndexAliasesService;
|
2010-11-21 17:33:35 +02:00
|
|
|
import org.elasticsearch.index.analysis.AnalysisService;
|
2010-04-01 12:25:51 +03:00
|
|
|
import org.elasticsearch.index.cache.IndexCache;
|
2013-04-05 20:02:22 +02:00
|
|
|
import org.elasticsearch.index.cache.filter.ShardFilterCacheModule;
|
|
|
|
import org.elasticsearch.index.cache.id.ShardIdCacheModule;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.deletionpolicy.DeletionPolicyModule;
|
|
|
|
import org.elasticsearch.index.engine.Engine;
|
|
|
|
import org.elasticsearch.index.engine.EngineModule;
|
2010-05-19 20:41:29 +03:00
|
|
|
import org.elasticsearch.index.engine.IndexEngine;
|
2013-01-18 14:12:01 +01:00
|
|
|
import org.elasticsearch.index.fielddata.IndexFieldDataService;
|
2013-04-07 18:30:24 -07:00
|
|
|
import org.elasticsearch.index.fielddata.ShardFieldDataModule;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.gateway.IndexGateway;
|
|
|
|
import org.elasticsearch.index.gateway.IndexShardGatewayModule;
|
|
|
|
import org.elasticsearch.index.gateway.IndexShardGatewayService;
|
2011-08-30 19:53:07 +03:00
|
|
|
import org.elasticsearch.index.get.ShardGetModule;
|
2011-08-24 11:24:52 +03:00
|
|
|
import org.elasticsearch.index.indexing.ShardIndexingModule;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.mapper.MapperService;
|
|
|
|
import org.elasticsearch.index.merge.policy.MergePolicyModule;
|
2011-03-08 21:53:33 +02:00
|
|
|
import org.elasticsearch.index.merge.policy.MergePolicyProvider;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.merge.scheduler.MergeSchedulerModule;
|
2013-07-16 16:00:28 +02:00
|
|
|
import org.elasticsearch.index.percolator.PercolatorQueriesRegistry;
|
|
|
|
import org.elasticsearch.index.percolator.PercolatorShardModule;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.query.IndexQueryParserService;
|
2011-09-04 23:55:35 +03:00
|
|
|
import org.elasticsearch.index.search.stats.ShardSearchModule;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.settings.IndexSettings;
|
Store Throttling (node level and/or index level) with options on merge or all, closes #2041.
Allow to configure store throttling (only applied on file system based storage), which allows to control the maximum bytes per sec written to the file system. It can be configured to only apply while merging, or on all output operations. The setting can eb set on the node level (in which case the throttling is done across all shards allocated on the node), or index level, in which case it only applied to that index.
The node level settings are indices.store.throttle.type to set the type, with values of none, merge and all (defaults to none). And, also, indices.store.throttle.max_bytes_per_sec (defaults to 0), which can be set to something like 1mb.
The index level settings is index.store.throttle.type for the type, with values of node, none, merge, and all. Defaults to node which will use the "shared" throttling on the node level. And, index.store.throttle.max_bytes_per_sec (defaults to 0).
2012-06-21 21:20:18 +02:00
|
|
|
import org.elasticsearch.index.settings.IndexSettingsService;
|
2011-08-14 14:51:04 +03:00
|
|
|
import org.elasticsearch.index.shard.IndexShardCreationException;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.shard.IndexShardModule;
|
|
|
|
import org.elasticsearch.index.shard.ShardId;
|
2010-02-25 18:40:29 +02:00
|
|
|
import org.elasticsearch.index.shard.service.IndexShard;
|
2010-12-23 10:56:37 +02:00
|
|
|
import org.elasticsearch.index.shard.service.InternalIndexShard;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.similarity.SimilarityService;
|
2013-11-08 19:20:43 -05:00
|
|
|
import org.elasticsearch.index.snapshots.IndexShardSnapshotModule;
|
2010-06-23 07:47:18 +03:00
|
|
|
import org.elasticsearch.index.store.IndexStore;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.store.Store;
|
|
|
|
import org.elasticsearch.index.store.StoreModule;
|
Multi term vector request
--------------------------
This feature allows to retrieve [term vectors](https://github.com/elasticsearch/elasticsearch/issues/3114) for a list of documents. The json request has exactly the same [format](https://github.com/elasticsearch/elasticsearch/issues/3484) as the ```_termvectors``` endpoint
It use it, call
```
curl -XGET 'http://localhost:9200/index/type/_mtermvectors' -d '{
"fields": [
"field1",
"field2",
...
],
"ids": [
"docId1",
"docId2",
...
],
"offsets": false|true,
"payloads": false|true,
"positions": false|true,
"term_statistics": false|true,
"field_statistics": false|true
}'
```
The return format is an array, each entry of which conatins the term vector response for one document:
```
{
"docs": [
{
"_index": "index",
"_type": "type",
"_id": "docId1",
"_version": 1,
"exists": true,
"term_vectors": {
...
}
},
{
"_index": "index",
"_type": "type",
"_id": "docId2",
"_version": 1,
"exists": true,
"term_vectors": {
...
}
}
]
}
```
Note that, like term vectors, the mult term vectors request will silenty skip over documents that have no term vectors stored in the index and will simply return an empty response in this case.
Closes #3536
2013-08-23 18:32:22 +02:00
|
|
|
import org.elasticsearch.index.termvectors.ShardTermVectorModule;
|
2010-07-05 14:13:55 +03:00
|
|
|
import org.elasticsearch.index.translog.Translog;
|
2010-02-08 15:30:06 +02:00
|
|
|
import org.elasticsearch.index.translog.TranslogModule;
|
2010-08-11 12:54:00 +03:00
|
|
|
import org.elasticsearch.index.translog.TranslogService;
|
2010-04-07 21:22:43 +03:00
|
|
|
import org.elasticsearch.indices.IndicesLifecycle;
|
|
|
|
import org.elasticsearch.indices.InternalIndicesLifecycle;
|
2010-03-27 23:43:59 +03:00
|
|
|
import org.elasticsearch.plugins.PluginsService;
|
|
|
|
import org.elasticsearch.plugins.ShardsPluginsModule;
|
2010-07-19 02:17:59 +03:00
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
2010-07-19 02:17:59 +03:00
|
|
|
import java.util.concurrent.CountDownLatch;
|
2011-06-10 03:48:43 +03:00
|
|
|
import java.util.concurrent.Executor;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
import static com.google.common.collect.Maps.newHashMap;
|
|
|
|
import static org.elasticsearch.common.collect.MapBuilder.newMapBuilder;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
|
|
|
/**
|
2011-12-06 02:42:25 +02:00
|
|
|
*
|
2010-02-08 15:30:06 +02:00
|
|
|
*/
|
|
|
|
public class InternalIndexService extends AbstractIndexComponent implements IndexService {
|
|
|
|
|
|
|
|
private final Injector injector;
|
|
|
|
|
|
|
|
private final Settings indexSettings;
|
|
|
|
|
2010-07-19 02:17:59 +03:00
|
|
|
private final ThreadPool threadPool;
|
|
|
|
|
2010-03-27 23:43:59 +03:00
|
|
|
private final PluginsService pluginsService;
|
|
|
|
|
2010-04-07 21:22:43 +03:00
|
|
|
private final InternalIndicesLifecycle indicesLifecycle;
|
|
|
|
|
2010-11-21 17:33:35 +02:00
|
|
|
private final AnalysisService analysisService;
|
|
|
|
|
2010-02-08 15:30:06 +02:00
|
|
|
private final MapperService mapperService;
|
|
|
|
|
|
|
|
private final IndexQueryParserService queryParserService;
|
|
|
|
|
|
|
|
private final SimilarityService similarityService;
|
|
|
|
|
2011-05-21 19:53:17 -04:00
|
|
|
private final IndexAliasesService aliasesService;
|
|
|
|
|
2010-04-01 12:25:51 +03:00
|
|
|
private final IndexCache indexCache;
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2013-01-18 14:12:01 +01:00
|
|
|
private final IndexFieldDataService indexFieldData;
|
|
|
|
|
2010-05-19 20:41:29 +03:00
|
|
|
private final IndexEngine indexEngine;
|
|
|
|
|
2010-06-24 00:32:05 +03:00
|
|
|
private final IndexGateway indexGateway;
|
|
|
|
|
|
|
|
private final IndexStore indexStore;
|
|
|
|
|
Store Throttling (node level and/or index level) with options on merge or all, closes #2041.
Allow to configure store throttling (only applied on file system based storage), which allows to control the maximum bytes per sec written to the file system. It can be configured to only apply while merging, or on all output operations. The setting can eb set on the node level (in which case the throttling is done across all shards allocated on the node), or index level, in which case it only applied to that index.
The node level settings are indices.store.throttle.type to set the type, with values of none, merge and all (defaults to none). And, also, indices.store.throttle.max_bytes_per_sec (defaults to 0), which can be set to something like 1mb.
The index level settings is index.store.throttle.type for the type, with values of node, none, merge, and all. Defaults to node which will use the "shared" throttling on the node level. And, index.store.throttle.max_bytes_per_sec (defaults to 0).
2012-06-21 21:20:18 +02:00
|
|
|
private final IndexSettingsService settingsService;
|
|
|
|
|
2010-02-08 15:30:06 +02:00
|
|
|
private volatile ImmutableMap<Integer, Injector> shardsInjectors = ImmutableMap.of();
|
|
|
|
|
|
|
|
private volatile ImmutableMap<Integer, IndexShard> shards = ImmutableMap.of();
|
|
|
|
|
2011-02-01 23:10:15 +02:00
|
|
|
private volatile boolean closed = false;
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Inject
|
|
|
|
public InternalIndexService(Injector injector, Index index, @IndexSettings Settings indexSettings, NodeEnvironment nodeEnv, ThreadPool threadPool,
|
2013-07-16 16:00:28 +02:00
|
|
|
AnalysisService analysisService, MapperService mapperService, IndexQueryParserService queryParserService,
|
|
|
|
SimilarityService similarityService, IndexAliasesService aliasesService, IndexCache indexCache, IndexEngine indexEngine,
|
|
|
|
IndexGateway indexGateway, IndexStore indexStore, IndexSettingsService settingsService, IndexFieldDataService indexFieldData) {
|
2010-02-08 15:30:06 +02:00
|
|
|
super(index, indexSettings);
|
|
|
|
this.injector = injector;
|
2010-07-19 02:17:59 +03:00
|
|
|
this.threadPool = threadPool;
|
2010-02-08 15:30:06 +02:00
|
|
|
this.indexSettings = indexSettings;
|
2010-11-21 17:33:35 +02:00
|
|
|
this.analysisService = analysisService;
|
2010-02-08 15:30:06 +02:00
|
|
|
this.mapperService = mapperService;
|
|
|
|
this.queryParserService = queryParserService;
|
|
|
|
this.similarityService = similarityService;
|
2011-05-21 19:53:17 -04:00
|
|
|
this.aliasesService = aliasesService;
|
2010-04-01 12:25:51 +03:00
|
|
|
this.indexCache = indexCache;
|
2013-01-18 14:12:01 +01:00
|
|
|
this.indexFieldData = indexFieldData;
|
2010-05-19 20:41:29 +03:00
|
|
|
this.indexEngine = indexEngine;
|
2010-06-24 00:32:05 +03:00
|
|
|
this.indexGateway = indexGateway;
|
|
|
|
this.indexStore = indexStore;
|
Store Throttling (node level and/or index level) with options on merge or all, closes #2041.
Allow to configure store throttling (only applied on file system based storage), which allows to control the maximum bytes per sec written to the file system. It can be configured to only apply while merging, or on all output operations. The setting can eb set on the node level (in which case the throttling is done across all shards allocated on the node), or index level, in which case it only applied to that index.
The node level settings are indices.store.throttle.type to set the type, with values of none, merge and all (defaults to none). And, also, indices.store.throttle.max_bytes_per_sec (defaults to 0), which can be set to something like 1mb.
The index level settings is index.store.throttle.type for the type, with values of node, none, merge, and all. Defaults to node which will use the "shared" throttling on the node level. And, index.store.throttle.max_bytes_per_sec (defaults to 0).
2012-06-21 21:20:18 +02:00
|
|
|
this.settingsService = settingsService;
|
2010-03-27 23:43:59 +03:00
|
|
|
|
|
|
|
this.pluginsService = injector.getInstance(PluginsService.class);
|
2010-04-07 21:22:43 +03:00
|
|
|
this.indicesLifecycle = (InternalIndicesLifecycle) injector.getInstance(IndicesLifecycle.class);
|
2013-04-05 20:02:22 +02:00
|
|
|
|
|
|
|
// inject workarounds for cyclic dep
|
|
|
|
indexCache.filter().setIndexService(this);
|
|
|
|
indexCache.idCache().setIndexService(this);
|
2013-04-07 18:30:24 -07:00
|
|
|
indexFieldData.setIndexService(this);
|
2010-02-08 15:30:06 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public int numberOfShards() {
|
2010-02-08 15:30:06 +02:00
|
|
|
return shards.size();
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public UnmodifiableIterator<IndexShard> iterator() {
|
2010-02-08 15:30:06 +02:00
|
|
|
return shards.values().iterator();
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasShard(int shardId) {
|
2010-02-08 15:30:06 +02:00
|
|
|
return shards.containsKey(shardId);
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexShard shard(int shardId) {
|
2010-02-08 15:30:06 +02:00
|
|
|
return shards.get(shardId);
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexShard shardSafe(int shardId) throws IndexShardMissingException {
|
2010-02-08 15:30:06 +02:00
|
|
|
IndexShard indexShard = shard(shardId);
|
|
|
|
if (indexShard == null) {
|
|
|
|
throw new IndexShardMissingException(new ShardId(index, shardId));
|
|
|
|
}
|
|
|
|
return indexShard;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public ImmutableSet<Integer> shardIds() {
|
2013-07-05 16:59:54 +02:00
|
|
|
return shards.keySet();
|
2010-02-08 15:30:06 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public Injector injector() {
|
2010-02-08 15:30:06 +02:00
|
|
|
return injector;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexGateway gateway() {
|
2010-07-05 14:13:55 +03:00
|
|
|
return indexGateway;
|
|
|
|
}
|
|
|
|
|
Store Throttling (node level and/or index level) with options on merge or all, closes #2041.
Allow to configure store throttling (only applied on file system based storage), which allows to control the maximum bytes per sec written to the file system. It can be configured to only apply while merging, or on all output operations. The setting can eb set on the node level (in which case the throttling is done across all shards allocated on the node), or index level, in which case it only applied to that index.
The node level settings are indices.store.throttle.type to set the type, with values of none, merge and all (defaults to none). And, also, indices.store.throttle.max_bytes_per_sec (defaults to 0), which can be set to something like 1mb.
The index level settings is index.store.throttle.type for the type, with values of node, none, merge, and all. Defaults to node which will use the "shared" throttling on the node level. And, index.store.throttle.max_bytes_per_sec (defaults to 0).
2012-06-21 21:20:18 +02:00
|
|
|
@Override
|
|
|
|
public IndexSettingsService settingsService() {
|
|
|
|
return this.settingsService;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexStore store() {
|
2010-06-27 18:19:12 +03:00
|
|
|
return indexStore;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexCache cache() {
|
2010-04-01 12:25:51 +03:00
|
|
|
return indexCache;
|
2010-02-08 15:30:06 +02:00
|
|
|
}
|
|
|
|
|
2013-01-18 14:12:01 +01:00
|
|
|
@Override
|
|
|
|
public IndexFieldDataService fieldData() {
|
|
|
|
return indexFieldData;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public AnalysisService analysisService() {
|
2010-11-21 17:33:35 +02:00
|
|
|
return this.analysisService;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public MapperService mapperService() {
|
2010-02-08 15:30:06 +02:00
|
|
|
return mapperService;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexQueryParserService queryParserService() {
|
2010-02-08 15:30:06 +02:00
|
|
|
return queryParserService;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public SimilarityService similarityService() {
|
2010-02-08 15:30:06 +02:00
|
|
|
return similarityService;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexAliasesService aliasesService() {
|
2011-05-21 19:53:17 -04:00
|
|
|
return aliasesService;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public IndexEngine engine() {
|
2010-05-19 20:41:29 +03:00
|
|
|
return indexEngine;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:41:19 -08:00
|
|
|
public void close(final String reason, @Nullable Executor executor) {
|
2011-02-01 23:10:15 +02:00
|
|
|
synchronized (this) {
|
|
|
|
closed = true;
|
|
|
|
}
|
2011-04-09 14:20:18 +03:00
|
|
|
Set<Integer> shardIds = shardIds();
|
|
|
|
final CountDownLatch latch = new CountDownLatch(shardIds.size());
|
|
|
|
for (final int shardId : shardIds) {
|
2012-03-09 20:32:33 +02:00
|
|
|
executor = executor == null ? threadPool.generic() : executor;
|
2011-06-10 03:48:43 +03:00
|
|
|
executor.execute(new Runnable() {
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2011-04-09 14:20:18 +03:00
|
|
|
try {
|
2013-03-04 20:41:19 -08:00
|
|
|
removeShard(shardId, reason);
|
2013-08-12 17:38:30 +02:00
|
|
|
} catch (Throwable e) {
|
2013-03-04 20:41:19 -08:00
|
|
|
logger.warn("failed to close shard", e);
|
2011-04-09 14:20:18 +03:00
|
|
|
} finally {
|
|
|
|
latch.countDown();
|
2010-07-19 02:17:59 +03:00
|
|
|
}
|
2011-04-09 14:20:18 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
latch.await();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
throw new ElasticSearchInterruptedException("interrupted closing index [ " + index().name() + "]", e);
|
2010-02-08 15:30:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public Injector shardInjector(int shardId) throws ElasticSearchException {
|
2010-02-08 15:30:06 +02:00
|
|
|
return shardsInjectors.get(shardId);
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public Injector shardInjectorSafe(int shardId) throws IndexShardMissingException {
|
2010-02-08 15:30:06 +02:00
|
|
|
Injector shardInjector = shardInjector(shardId);
|
|
|
|
if (shardInjector == null) {
|
|
|
|
throw new IndexShardMissingException(new ShardId(index, shardId));
|
|
|
|
}
|
|
|
|
return shardInjector;
|
|
|
|
}
|
|
|
|
|
2013-09-25 17:05:11 +02:00
|
|
|
@Override
|
|
|
|
public String indexUUID() {
|
2013-09-26 16:39:13 +02:00
|
|
|
return indexSettings.get(IndexMetaData.SETTING_UUID, IndexMetaData.INDEX_UUID_NA_VALUE);
|
2013-09-25 17:05:11 +02:00
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public synchronized IndexShard createShard(int sShardId) throws ElasticSearchException {
|
2013-08-13 16:50:16 +02:00
|
|
|
/*
|
|
|
|
* TODO: we execute this in parallel but it's a synced method. Yet, we might
|
|
|
|
* be able to serialize the execution via the cluster state in the future. for now we just
|
|
|
|
* keep it synced.
|
|
|
|
*/
|
2011-02-01 23:10:15 +02:00
|
|
|
if (closed) {
|
|
|
|
throw new ElasticSearchIllegalStateException("Can't create shard [" + index.name() + "][" + sShardId + "], closed");
|
|
|
|
}
|
2010-02-08 15:30:06 +02:00
|
|
|
ShardId shardId = new ShardId(index, sShardId);
|
|
|
|
if (shardsInjectors.containsKey(shardId.id())) {
|
|
|
|
throw new IndexShardAlreadyExistsException(shardId + " already exists");
|
|
|
|
}
|
|
|
|
|
2010-04-07 21:22:43 +03:00
|
|
|
indicesLifecycle.beforeIndexShardCreated(shardId);
|
|
|
|
|
2010-06-24 00:32:05 +03:00
|
|
|
logger.debug("creating shard_id [{}]", shardId.id());
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2010-08-22 10:42:25 +03:00
|
|
|
ModulesBuilder modules = new ModulesBuilder();
|
2010-04-27 23:54:30 +03:00
|
|
|
modules.add(new ShardsPluginsModule(indexSettings, pluginsService));
|
2012-02-05 18:52:56 +02:00
|
|
|
modules.add(new IndexShardModule(indexSettings, shardId));
|
2011-08-24 11:24:52 +03:00
|
|
|
modules.add(new ShardIndexingModule());
|
2011-09-04 23:55:35 +03:00
|
|
|
modules.add(new ShardSearchModule());
|
2011-08-30 19:53:07 +03:00
|
|
|
modules.add(new ShardGetModule());
|
2010-06-23 07:47:18 +03:00
|
|
|
modules.add(new StoreModule(indexSettings, injector.getInstance(IndexStore.class)));
|
2010-04-27 23:54:30 +03:00
|
|
|
modules.add(new DeletionPolicyModule(indexSettings));
|
|
|
|
modules.add(new MergePolicyModule(indexSettings));
|
|
|
|
modules.add(new MergeSchedulerModule(indexSettings));
|
2013-04-05 20:02:22 +02:00
|
|
|
modules.add(new ShardFilterCacheModule());
|
2013-04-07 18:30:24 -07:00
|
|
|
modules.add(new ShardFieldDataModule());
|
2013-04-05 20:02:22 +02:00
|
|
|
modules.add(new ShardIdCacheModule());
|
2010-04-27 23:54:30 +03:00
|
|
|
modules.add(new TranslogModule(indexSettings));
|
|
|
|
modules.add(new EngineModule(indexSettings));
|
|
|
|
modules.add(new IndexShardGatewayModule(injector.getInstance(IndexGateway.class)));
|
2013-07-16 16:00:28 +02:00
|
|
|
modules.add(new PercolatorShardModule());
|
Multi term vector request
--------------------------
This feature allows to retrieve [term vectors](https://github.com/elasticsearch/elasticsearch/issues/3114) for a list of documents. The json request has exactly the same [format](https://github.com/elasticsearch/elasticsearch/issues/3484) as the ```_termvectors``` endpoint
It use it, call
```
curl -XGET 'http://localhost:9200/index/type/_mtermvectors' -d '{
"fields": [
"field1",
"field2",
...
],
"ids": [
"docId1",
"docId2",
...
],
"offsets": false|true,
"payloads": false|true,
"positions": false|true,
"term_statistics": false|true,
"field_statistics": false|true
}'
```
The return format is an array, each entry of which conatins the term vector response for one document:
```
{
"docs": [
{
"_index": "index",
"_type": "type",
"_id": "docId1",
"_version": 1,
"exists": true,
"term_vectors": {
...
}
},
{
"_index": "index",
"_type": "type",
"_id": "docId2",
"_version": 1,
"exists": true,
"term_vectors": {
...
}
}
]
}
```
Note that, like term vectors, the mult term vectors request will silenty skip over documents that have no term vectors stored in the index and will simply return an empty response in this case.
Closes #3536
2013-08-23 18:32:22 +02:00
|
|
|
modules.add(new ShardTermVectorModule());
|
2013-11-08 19:20:43 -05:00
|
|
|
modules.add(new IndexShardSnapshotModule());
|
2010-04-27 23:54:30 +03:00
|
|
|
|
2011-08-14 14:51:04 +03:00
|
|
|
Injector shardInjector;
|
|
|
|
try {
|
|
|
|
shardInjector = modules.createChildInjector(injector);
|
|
|
|
} catch (CreationException e) {
|
|
|
|
throw new IndexShardCreationException(shardId, Injectors.getFirstErrorFailure(e));
|
2012-04-22 12:25:10 +03:00
|
|
|
} catch (Throwable e) {
|
|
|
|
throw new IndexShardCreationException(shardId, e);
|
2011-08-14 14:51:04 +03:00
|
|
|
}
|
2010-02-08 15:30:06 +02:00
|
|
|
|
|
|
|
shardsInjectors = newMapBuilder(shardsInjectors).put(shardId.id(), shardInjector).immutableMap();
|
|
|
|
|
|
|
|
IndexShard indexShard = shardInjector.getInstance(IndexShard.class);
|
|
|
|
|
2013-12-11 16:05:17 +01:00
|
|
|
indicesLifecycle.indexShardStateChanged(indexShard, null, "shard created");
|
2010-04-07 21:22:43 +03:00
|
|
|
indicesLifecycle.afterIndexShardCreated(indexShard);
|
|
|
|
|
2010-02-08 15:30:06 +02:00
|
|
|
shards = newMapBuilder(shards).put(shardId.id(), indexShard).immutableMap();
|
|
|
|
|
|
|
|
return indexShard;
|
|
|
|
}
|
|
|
|
|
2011-12-06 02:42:25 +02:00
|
|
|
@Override
|
|
|
|
public synchronized void removeShard(int shardId, String reason) throws ElasticSearchException {
|
2013-08-13 16:50:16 +02:00
|
|
|
final Injector shardInjector;
|
|
|
|
final IndexShard indexShard;
|
|
|
|
final ShardId sId = new ShardId(index, shardId);
|
|
|
|
Map<Integer, Injector> tmpShardInjectors = newHashMap(shardsInjectors);
|
|
|
|
shardInjector = tmpShardInjectors.remove(shardId);
|
|
|
|
if (shardInjector == null) {
|
|
|
|
return;
|
2010-07-19 02:17:59 +03:00
|
|
|
}
|
2013-08-13 16:50:16 +02:00
|
|
|
shardsInjectors = ImmutableMap.copyOf(tmpShardInjectors);
|
|
|
|
Map<Integer, IndexShard> tmpShardsMap = newHashMap(shards);
|
|
|
|
indexShard = tmpShardsMap.remove(shardId);
|
|
|
|
shards = ImmutableMap.copyOf(tmpShardsMap);
|
2013-03-04 20:41:19 -08:00
|
|
|
indicesLifecycle.beforeIndexShardClosed(sId, indexShard);
|
2010-03-31 22:45:46 +03:00
|
|
|
for (Class<? extends CloseableIndexComponent> closeable : pluginsService.shardServices()) {
|
2010-07-08 19:20:03 +03:00
|
|
|
try {
|
2013-03-04 20:41:19 -08:00
|
|
|
shardInjector.getInstance(closeable).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2010-07-08 19:20:03 +03:00
|
|
|
logger.debug("failed to clean plugin shard service [{}]", e, closeable);
|
|
|
|
}
|
2010-03-27 23:43:59 +03:00
|
|
|
}
|
2010-08-11 12:54:00 +03:00
|
|
|
try {
|
|
|
|
// now we can close the translog service, we need to close it before the we close the shard
|
|
|
|
shardInjector.getInstance(TranslogService.class).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2011-03-28 17:20:07 +02:00
|
|
|
logger.debug("failed to close translog service", e);
|
2010-08-11 12:54:00 +03:00
|
|
|
// ignore
|
|
|
|
}
|
2010-07-05 14:13:55 +03:00
|
|
|
// this logic is tricky, we want to close the engine so we rollback the changes done to it
|
|
|
|
// and close the shard so no operations are allowed to it
|
2010-07-08 19:20:03 +03:00
|
|
|
if (indexShard != null) {
|
2011-03-08 21:53:33 +02:00
|
|
|
try {
|
|
|
|
((InternalIndexShard) indexShard).close(reason);
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2011-03-28 17:20:07 +02:00
|
|
|
logger.debug("failed to close index shard", e);
|
2011-03-08 21:53:33 +02:00
|
|
|
// ignore
|
|
|
|
}
|
2010-07-08 19:20:03 +03:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
shardInjector.getInstance(Engine.class).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2011-03-28 17:20:07 +02:00
|
|
|
logger.debug("failed to close engine", e);
|
2010-07-08 19:20:03 +03:00
|
|
|
// ignore
|
|
|
|
}
|
2011-03-08 21:53:33 +02:00
|
|
|
try {
|
2013-03-04 20:41:19 -08:00
|
|
|
shardInjector.getInstance(MergePolicyProvider.class).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2011-03-28 17:20:07 +02:00
|
|
|
logger.debug("failed to close merge policy provider", e);
|
2011-03-08 21:53:33 +02:00
|
|
|
// ignore
|
|
|
|
}
|
2010-07-08 19:20:03 +03:00
|
|
|
try {
|
2013-03-04 20:41:19 -08:00
|
|
|
shardInjector.getInstance(IndexShardGatewayService.class).snapshotOnClose();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2013-03-04 20:41:19 -08:00
|
|
|
logger.debug("failed to snapshot index shard gateway on close", e);
|
2010-08-20 00:59:37 +03:00
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
try {
|
2013-03-04 20:41:19 -08:00
|
|
|
shardInjector.getInstance(IndexShardGatewayService.class).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2011-03-28 17:20:07 +02:00
|
|
|
logger.debug("failed to close index shard gateway", e);
|
2010-07-08 19:20:03 +03:00
|
|
|
// ignore
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// now we can close the translog
|
2013-03-04 20:41:19 -08:00
|
|
|
shardInjector.getInstance(Translog.class).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2011-03-28 17:20:07 +02:00
|
|
|
logger.debug("failed to close translog", e);
|
2010-07-08 19:20:03 +03:00
|
|
|
// ignore
|
|
|
|
}
|
2013-07-16 16:00:28 +02:00
|
|
|
try {
|
|
|
|
// now we can close the translog
|
|
|
|
shardInjector.getInstance(PercolatorQueriesRegistry.class).close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2013-07-16 16:00:28 +02:00
|
|
|
logger.debug("failed to close PercolatorQueriesRegistry", e);
|
|
|
|
// ignore
|
|
|
|
}
|
2010-02-08 15:30:06 +02:00
|
|
|
|
2010-05-16 03:57:26 +03:00
|
|
|
// call this before we close the store, so we can release resources for it
|
2013-03-04 20:41:19 -08:00
|
|
|
indicesLifecycle.afterIndexShardClosed(sId);
|
2010-06-24 00:32:05 +03:00
|
|
|
// if we delete or have no gateway or the store is not persistent, clean the store...
|
2010-02-08 15:30:06 +02:00
|
|
|
Store store = shardInjector.getInstance(Store.class);
|
2010-06-24 00:32:05 +03:00
|
|
|
// and close it
|
2010-02-08 15:30:06 +02:00
|
|
|
try {
|
|
|
|
store.close();
|
2013-08-13 16:50:16 +02:00
|
|
|
} catch (Throwable e) {
|
2010-06-24 00:32:05 +03:00
|
|
|
logger.warn("failed to close store on shard deletion", e);
|
2010-02-08 15:30:06 +02:00
|
|
|
}
|
|
|
|
Injectors.close(injector);
|
|
|
|
}
|
|
|
|
}
|