Skip to content

Commit 8cf26de

Browse files
committed
Fail index creation using custom data path
Custom per-index data paths were deprecated in 7.14. This commit blocks creation of indices in 8.0 from configuring custom data paths. relates elastic#73168
1 parent d409122 commit 8cf26de

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

docs/reference/migration/migrate_8_0/indices.asciidoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,18 @@ index setting].
116116
Accept the new behaviour, or specify `?wait_for_active_shards=0` to preserve
117117
the old behaviour if needed.
118118
====
119+
120+
.The setting `index.data_path` is not longer allowed on new indices.
121+
[%collapsible]
122+
====
123+
*Details* +
124+
Creating an index relative to the node level `path.shared_data` setting was
125+
previously used with shadow replicas prior to their removal in 6.0. The
126+
per-index data path in `index.data_path` was deprecated in 7.14.0. In 8.0,
127+
creating new indices with `index.data_path` is no longer supported.
128+
129+
*Impact* +
130+
Discontinue use of the `index.data_path` setting. Creating new indices with
131+
this setting will return an error.
132+
====
119133
//end::notable-breaking-changes[]

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4949
import org.elasticsearch.common.xcontent.XContentHelper;
5050
import org.elasticsearch.core.Nullable;
51-
import org.elasticsearch.core.PathUtils;
5251
import org.elasticsearch.env.Environment;
5352
import org.elasticsearch.index.Index;
5453
import org.elasticsearch.index.IndexModule;
@@ -69,7 +68,6 @@
6968

7069
import java.io.IOException;
7170
import java.io.UnsupportedEncodingException;
72-
import java.nio.file.Path;
7371
import java.time.Instant;
7472
import java.util.ArrayList;
7573
import java.util.Arrays;
@@ -1047,7 +1045,7 @@ public void validateIndexSettings(String indexName, final Settings settings, fin
10471045
}
10481046

10491047
List<String> getIndexSettingsValidationErrors(final Settings settings, final boolean forbidPrivateIndexSettings) {
1050-
List<String> validationErrors = validateIndexCustomPath(settings, env.sharedDataFile());
1048+
List<String> validationErrors = validateNoCustomPath(settings);
10511049
if (forbidPrivateIndexSettings) {
10521050
validationErrors.addAll(validatePrivateSettingsNotExplicitlySet(settings, indexScopedSettings));
10531051
}
@@ -1068,27 +1066,17 @@ private static List<String> validatePrivateSettingsNotExplicitlySet(Settings set
10681066
}
10691067

10701068
/**
1071-
* Validates that the configured index data path (if any) is a sub-path of the configured shared data path (if any)
1069+
* Validates an index data path is not specified.
10721070
*
10731071
* @param settings the index configured settings
1074-
* @param sharedDataPath the configured `path.shared_data` (if any)
1075-
* @return a list containing validaton errors or an empty list if there aren't any errors
1072+
* @return a list containing validation errors or an empty list if there aren't any errors
10761073
*/
1077-
private static List<String> validateIndexCustomPath(Settings settings, @Nullable Path sharedDataPath) {
1078-
String customPath = IndexMetadata.INDEX_DATA_PATH_SETTING.get(settings);
1079-
List<String> validationErrors = new ArrayList<>();
1080-
if (Strings.isEmpty(customPath) == false) {
1081-
if (sharedDataPath == null) {
1082-
validationErrors.add("path.shared_data must be set in order to use custom data paths");
1083-
} else {
1084-
Path resolvedPath = PathUtils.get(new Path[]{sharedDataPath}, customPath);
1085-
if (resolvedPath == null) {
1086-
validationErrors.add("custom path [" + customPath +
1087-
"] is not a sub-path of path.shared_data [" + sharedDataPath + "]");
1088-
}
1089-
}
1074+
static List<String> validateNoCustomPath(Settings settings) {
1075+
if (IndexMetadata.INDEX_DATA_PATH_SETTING.exists(settings)) {
1076+
return List.of("per-index custom data path using setting ["
1077+
+ IndexMetadata.INDEX_DATA_PATH_SETTING.getKey() + "] is no longer supported on new indices");
10901078
}
1091-
return validationErrors;
1079+
return List.of();
10921080
}
10931081

10941082
/**

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataCreateIndexServiceTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494

9595
import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING;
9696
import static org.elasticsearch.indices.ShardLimitValidatorTests.createTestShardLimitService;
97+
import static org.hamcrest.Matchers.contains;
98+
import static org.hamcrest.Matchers.containsString;
99+
import static org.hamcrest.Matchers.empty;
97100
import static org.hamcrest.Matchers.endsWith;
98101
import static org.hamcrest.Matchers.equalTo;
99102
import static org.hamcrest.Matchers.hasKey;
@@ -281,6 +284,15 @@ public void testValidateSplitIndex() {
281284
Settings.builder().put("index.number_of_shards", targetShards).build());
282285
}
283286

287+
public void testValidateNoCustomPath() {
288+
Settings indexSettings = Settings.builder().put(IndexMetadata.INDEX_DATA_PATH_SETTING.getKey(), "some/path").build();
289+
List<String> validationErrors = MetadataCreateIndexService.validateNoCustomPath(indexSettings);
290+
assertThat(validationErrors, contains(containsString("per-index custom data path")));
291+
292+
List<String> noErrors = MetadataCreateIndexService.validateNoCustomPath(Settings.EMPTY);
293+
assertThat(noErrors, empty());
294+
}
295+
284296
public void testPrepareResizeIndexSettings() {
285297
final List<Version> versions = Arrays.asList(VersionUtils.randomVersion(random()), VersionUtils.randomVersion(random()));
286298
versions.sort(Comparator.comparingLong(l -> l.id));

0 commit comments

Comments
 (0)