Skip to content

Commit a4e2230

Browse files
committed
Add index.data_path setting
This allows specifying the path an index will be at. `index.data_path` is specified in the settings when creating an index, and can not be dynamically changed. An example request would look like: POST /myindex { "settings": { "number_of_shards": 2, "data_path": "/tmp/myindex" } } And would put data in /tmp/myindex/0/index/0 and /tmp/myindex/0/index/1 Since this can be used to write data to arbitrary locations on disk, it requires enabling the `node.enable_custom_paths` setting in elasticsearch.yml on all nodes. Relates to #8976
1 parent 582d5e8 commit a4e2230

File tree

20 files changed

+546
-91
lines changed

20 files changed

+546
-91
lines changed

src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848

4949
import static com.google.common.collect.Maps.newHashMap;
5050
import static org.elasticsearch.action.ValidateActions.addValidationError;
51+
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
5152
import static org.elasticsearch.common.settings.ImmutableSettings.readSettingsFromStream;
5253
import static org.elasticsearch.common.settings.ImmutableSettings.writeSettingsToStream;
53-
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.EMPTY_SETTINGS;
5454

5555
/**
5656
* A request to create an index. Best created with {@link org.elasticsearch.client.Requests#createIndexRequest(String)}.

src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public static State fromString(String state) {
167167
public static final String SETTING_UUID = "index.uuid";
168168
public static final String SETTING_LEGACY_ROUTING_HASH_FUNCTION = "index.legacy.routing.hash.type";
169169
public static final String SETTING_LEGACY_ROUTING_USE_TYPE = "index.legacy.routing.use_type";
170+
public static final String SETTING_DATA_PATH = "index.data_path";
170171
public static final String INDEX_UUID_NA_VALUE = "_na_";
171172

172173
// hard-coded hash function as of 2.0

src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.collect.Maps;
2727
import org.apache.lucene.util.CollectionUtil;
2828
import org.elasticsearch.ElasticsearchException;
29+
import org.elasticsearch.ElasticsearchIllegalArgumentException;
2930
import org.elasticsearch.Version;
3031
import org.elasticsearch.action.ActionListener;
3132
import org.elasticsearch.action.ActionRunnable;
@@ -57,13 +58,15 @@
5758
import org.elasticsearch.common.xcontent.XContentHelper;
5859
import org.elasticsearch.common.xcontent.XContentParser;
5960
import org.elasticsearch.env.Environment;
61+
import org.elasticsearch.env.NodeEnvironment;
6062
import org.elasticsearch.index.Index;
6163
import org.elasticsearch.index.mapper.DocumentMapper;
6264
import org.elasticsearch.index.mapper.MapperParsingException;
6365
import org.elasticsearch.index.mapper.MapperService;
6466
import org.elasticsearch.index.query.IndexQueryParserService;
6567
import org.elasticsearch.index.IndexService;
6668
import org.elasticsearch.indices.IndexAlreadyExistsException;
69+
import org.elasticsearch.indices.IndexCreationException;
6770
import org.elasticsearch.indices.IndicesService;
6871
import org.elasticsearch.indices.InvalidIndexNameException;
6972
import org.elasticsearch.river.RiverIndexName;
@@ -101,11 +104,13 @@ public class MetaDataCreateIndexService extends AbstractComponent {
101104
private final String riverIndexName;
102105
private final AliasValidator aliasValidator;
103106
private final IndexTemplateFilter indexTemplateFilter;
107+
private final NodeEnvironment nodeEnv;
104108

105109
@Inject
106-
public MetaDataCreateIndexService(Settings settings, Environment environment, ThreadPool threadPool, ClusterService clusterService, IndicesService indicesService,
107-
AllocationService allocationService, MetaDataService metaDataService, Version version, @RiverIndexName String riverIndexName,
108-
AliasValidator aliasValidator, Set<IndexTemplateFilter> indexTemplateFilters) {
110+
public MetaDataCreateIndexService(Settings settings, Environment environment, ThreadPool threadPool, ClusterService clusterService,
111+
IndicesService indicesService, AllocationService allocationService, MetaDataService metaDataService,
112+
Version version, @RiverIndexName String riverIndexName, AliasValidator aliasValidator,
113+
Set<IndexTemplateFilter> indexTemplateFilters, NodeEnvironment nodeEnv) {
109114
super(settings);
110115
this.environment = environment;
111116
this.threadPool = threadPool;
@@ -116,6 +121,7 @@ public MetaDataCreateIndexService(Settings settings, Environment environment, Th
116121
this.version = version;
117122
this.riverIndexName = riverIndexName;
118123
this.aliasValidator = aliasValidator;
124+
this.nodeEnv = nodeEnv;
119125

120126
if (indexTemplateFilters.isEmpty()) {
121127
this.indexTemplateFilter = DEFAULT_INDEX_TEMPLATE_FILTER;
@@ -554,6 +560,11 @@ public int compare(IndexTemplateMetaData o1, IndexTemplateMetaData o2) {
554560

555561
private void validate(CreateIndexClusterStateUpdateRequest request, ClusterState state) throws ElasticsearchException {
556562
validateIndexName(request.index(), state);
563+
String customPath = request.settings().get(IndexMetaData.SETTING_DATA_PATH, null);
564+
if (customPath != null && nodeEnv.isCustomPathsEnabled() == false) {
565+
throw new IndexCreationException(new Index(request.index()),
566+
new ElasticsearchIllegalArgumentException("custom data_paths for indices is disabled"));
567+
}
557568
}
558569

559570
private static class DefaultIndexTemplateFilter implements IndexTemplateFilter {

0 commit comments

Comments
 (0)