Skip to content

Commit a06aff9

Browse files
authored
Revert "Fail index creation using custom data path (#76792)" (#78031)
This reverts commit 79d91ed.
1 parent 2b6bf54 commit a06aff9

File tree

6 files changed

+32
-54
lines changed

6 files changed

+32
-54
lines changed

docs/reference/migration/migrate_8_0/indices.asciidoc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,4 @@ 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-
====
133119
//end::notable-breaking-changes[]

server/src/internalClusterTest/java/org/elasticsearch/index/shard/IndexShardIT.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.elasticsearch.test.ESSingleNodeTestCase;
6767
import org.elasticsearch.test.IndexSettingsModule;
6868
import org.elasticsearch.test.InternalSettingsPlugin;
69-
import org.elasticsearch.test.VersionUtils;
7069
import org.junit.Assert;
7170

7271
import java.io.IOException;
@@ -117,11 +116,6 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
117116
return pluginList(InternalSettingsPlugin.class);
118117
}
119118

120-
@Override
121-
protected boolean forbidPrivateIndexSettings() {
122-
return false;
123-
}
124-
125119
public void testLockTryingToDelete() throws Exception {
126120
createIndex("test");
127121
ensureGreen();
@@ -220,11 +214,8 @@ public void testIndexDirIsDeletedWhenShardRemoved() throws Exception {
220214
Environment env = getInstanceFromNode(Environment.class);
221215
Path idxPath = env.sharedDataFile().resolve(randomAlphaOfLength(10));
222216
logger.info("--> idxPath: [{}]", idxPath);
223-
Version createdVersion =
224-
VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion(Version.V_8_0_0));
225217
Settings idxSettings = Settings.builder()
226218
.put(IndexMetadata.SETTING_DATA_PATH, idxPath)
227-
.put(IndexMetadata.SETTING_VERSION_CREATED, createdVersion)
228219
.build();
229220
createIndex("test", idxSettings);
230221
ensureGreen("test");
@@ -262,14 +253,8 @@ public void testIndexCanChangeCustomDataPath() throws Exception {
262253
final Path sharedDataPath = getInstanceFromNode(Environment.class).sharedDataFile().resolve(randomAsciiLettersOfLength(10));
263254
final Path indexDataPath = sharedDataPath.resolve("start-" + randomAsciiLettersOfLength(10));
264255

265-
logger.info("--> creating legacy index [{}] with data_path [{}]", index, indexDataPath);
266-
Version createdVersion =
267-
VersionUtils.randomVersionBetween(random(), VersionUtils.getFirstVersion(), VersionUtils.getPreviousVersion(Version.V_8_0_0));
268-
Settings settings = Settings.builder()
269-
.put(IndexMetadata.SETTING_DATA_PATH, indexDataPath.toAbsolutePath().toString())
270-
.put(IndexMetadata.SETTING_VERSION_CREATED, createdVersion)
271-
.build();
272-
createIndex(index, settings);
256+
logger.info("--> creating index [{}] with data_path [{}]", index, indexDataPath);
257+
createIndex(index, Settings.builder().put(IndexMetadata.SETTING_DATA_PATH, indexDataPath.toAbsolutePath().toString()).build());
273258
client().prepareIndex(index).setId("1").setSource("foo", "bar").setRefreshPolicy(IMMEDIATE).get();
274259
ensureGreen(index);
275260

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
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;
5152
import org.elasticsearch.env.Environment;
5253
import org.elasticsearch.index.Index;
5354
import org.elasticsearch.index.IndexModule;
@@ -68,6 +69,7 @@
6869

6970
import java.io.IOException;
7071
import java.io.UnsupportedEncodingException;
72+
import java.nio.file.Path;
7173
import java.time.Instant;
7274
import java.util.ArrayList;
7375
import java.util.Arrays;
@@ -794,7 +796,6 @@ static Settings aggregateIndexSettings(ClusterState currentState, CreateIndexClu
794796
validateSoftDeleteSettings(indexSettings);
795797
validateTranslogRetentionSettings(indexSettings);
796798
validateStoreTypeSetting(indexSettings);
797-
validateNoCustomPath(indexSettings);
798799
return indexSettings;
799800
}
800801

@@ -1046,7 +1047,7 @@ public void validateIndexSettings(String indexName, final Settings settings, fin
10461047
}
10471048

10481049
List<String> getIndexSettingsValidationErrors(final Settings settings, final boolean forbidPrivateIndexSettings) {
1049-
List<String> validationErrors = new ArrayList<>();
1050+
List<String> validationErrors = validateIndexCustomPath(settings, env.sharedDataFile());
10501051
if (forbidPrivateIndexSettings) {
10511052
validationErrors.addAll(validatePrivateSettingsNotExplicitlySet(settings, indexScopedSettings));
10521053
}
@@ -1067,16 +1068,27 @@ private static List<String> validatePrivateSettingsNotExplicitlySet(Settings set
10671068
}
10681069

10691070
/**
1070-
* Validates an index data path is not specified.
1071+
* Validates that the configured index data path (if any) is a sub-path of the configured shared data path (if any)
10711072
*
10721073
* @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
10731076
*/
1074-
static void validateNoCustomPath(Settings settings) {
1075-
if (IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(settings).onOrAfter(Version.V_8_0_0) &&
1076-
IndexMetadata.INDEX_DATA_PATH_SETTING.exists(settings)) {
1077-
throw new IllegalArgumentException("per-index custom data path using setting ["
1078-
+ IndexMetadata.INDEX_DATA_PATH_SETTING.getKey() + "] is no longer supported on new indices");
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+
}
10791090
}
1091+
return validationErrors;
10801092
}
10811093

10821094
/**

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
import org.elasticsearch.common.settings.IndexScopedSettings;
3535
import org.elasticsearch.common.settings.Setting;
3636
import org.elasticsearch.common.settings.Settings;
37+
import org.elasticsearch.core.TimeValue;
3738
import org.elasticsearch.common.util.concurrent.ThreadContext;
3839
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
3940
import org.elasticsearch.common.xcontent.XContentFactory;
40-
import org.elasticsearch.core.TimeValue;
4141
import org.elasticsearch.index.Index;
4242
import org.elasticsearch.index.IndexModule;
4343
import org.elasticsearch.index.IndexNotFoundException;
@@ -91,9 +91,9 @@
9191
import static org.elasticsearch.cluster.metadata.MetadataCreateIndexService.getIndexNumberOfRoutingShards;
9292
import static org.elasticsearch.cluster.metadata.MetadataCreateIndexService.parseV1Mappings;
9393
import static org.elasticsearch.cluster.metadata.MetadataCreateIndexService.resolveAndValidateAliases;
94+
9495
import static org.elasticsearch.index.IndexSettings.INDEX_SOFT_DELETES_SETTING;
9596
import static org.elasticsearch.indices.ShardLimitValidatorTests.createTestShardLimitService;
96-
import static org.hamcrest.Matchers.containsString;
9797
import static org.hamcrest.Matchers.endsWith;
9898
import static org.hamcrest.Matchers.equalTo;
9999
import static org.hamcrest.Matchers.hasKey;
@@ -281,18 +281,6 @@ public void testValidateSplitIndex() {
281281
Settings.builder().put("index.number_of_shards", targetShards).build());
282282
}
283283

284-
public void testValidateNoCustomPath() {
285-
Settings indexSettings = Settings.builder()
286-
.put(SETTING_VERSION_CREATED, Version.V_8_0_0)
287-
.put(IndexMetadata.INDEX_DATA_PATH_SETTING.getKey(), "some/path")
288-
.build();
289-
var e = expectThrows(IllegalArgumentException.class,
290-
() -> MetadataCreateIndexService.validateNoCustomPath(indexSettings));
291-
assertThat(e.getMessage(), containsString("per-index custom data path"));
292-
293-
MetadataCreateIndexService.validateNoCustomPath(Settings.EMPTY);
294-
}
295-
296284
public void testPrepareResizeIndexSettings() {
297285
final List<Version> versions = Arrays.asList(VersionUtils.randomVersion(random()), VersionUtils.randomVersion(random()));
298286
versions.sort(Comparator.comparingLong(l -> l.id));

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,12 @@ public Settings indexSettings() {
686686
if (numberOfReplicas >= 0) {
687687
builder.put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
688688
}
689+
// 30% of the time
690+
if (randomInt(9) < 3) {
691+
final String dataPath = randomAlphaOfLength(10);
692+
logger.info("using custom data_path for index: [{}]", dataPath);
693+
builder.put(IndexMetadata.SETTING_DATA_PATH, dataPath);
694+
}
689695
// always default delayed allocation to 0 to make sure we have tests are not delayed
690696
builder.put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), 0);
691697
if (randomBoolean()) {

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/BaseSearchableSnapshotsIntegTestCase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,12 @@ protected void checkSoftDeletesNotEagerlyLoaded(String restoredIndexName) {
234234

235235
protected void assertShardFolders(String indexName, boolean snapshotDirectory) throws IOException {
236236
final Index restoredIndex = resolveIndex(indexName);
237+
final String customDataPath = resolveCustomDataPath(indexName);
237238
final ShardId shardId = new ShardId(restoredIndex, 0);
238239
boolean shardFolderFound = false;
239240
for (String node : internalCluster().getNodeNames()) {
240241
final NodeEnvironment service = internalCluster().getInstance(NodeEnvironment.class, node);
241-
final ShardPath shardPath = ShardPath.loadShardPath(logger, service, shardId, null);
242+
final ShardPath shardPath = ShardPath.loadShardPath(logger, service, shardId, customDataPath);
242243
if (shardPath != null && Files.exists(shardPath.getDataPath())) {
243244
shardFolderFound = true;
244245
assertEquals(snapshotDirectory, Files.notExists(shardPath.resolveIndex()));

0 commit comments

Comments
 (0)