From d933ecd26cc443b1160e3fa7cab0fc4382893585 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 27 Apr 2021 08:29:12 -0700 Subject: [PATCH] Convert path.data to String setting instead of List (#72282) Since multiple data path support has been removed, the Setting no longer needs to support multiple values. This commit converts the PATH_DATA_SETTING to a String setting from List. relates #71205 --- .../fs/AvailableIndexFoldersBenchmark.java | 3 +- .../azure/AzureRepositorySettingsTests.java | 2 +- .../bootstrap/EvilSecurityTests.java | 31 +- .../env/NodeEnvironmentEvilTests.java | 16 +- .../elasticsearch/env/NodeEnvironmentIT.java | 4 +- .../IndexFoldersDeletionListenerIT.java | 2 +- .../cluster/coordination/JoinHelper.java | 7 +- .../org/elasticsearch/env/Environment.java | 25 +- .../java/org/elasticsearch/node/Node.java | 4 +- .../elasticsearch/env/EnvironmentTests.java | 5 +- .../env/NodeEnvironmentTests.java | 80 ++-- .../PersistedClusterStateServiceTests.java | 326 +--------------- .../index/shard/NewPathForShardTests.java | 363 ------------------ .../RemoveCorruptedShardDataCommandTests.java | 2 +- .../repositories/fs/FsRepositoryTests.java | 2 +- .../org/elasticsearch/test/ESTestCase.java | 5 - .../cache/shared/FrozenCacheService.java | 11 - .../AbstractSearchableSnapshotsTestCase.java | 2 +- .../cache/full/PersistentCacheTests.java | 2 +- .../cache/shared/FrozenCacheServiceTests.java | 26 -- .../SearchableSnapshotDirectoryTests.java | 2 +- 21 files changed, 72 insertions(+), 848 deletions(-) delete mode 100644 server/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/fs/AvailableIndexFoldersBenchmark.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/fs/AvailableIndexFoldersBenchmark.java index ff9e25d0e464c..80ca0baf6e86a 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/fs/AvailableIndexFoldersBenchmark.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/fs/AvailableIndexFoldersBenchmark.java @@ -44,13 +44,12 @@ public class AvailableIndexFoldersBenchmark { @Setup public void setup() throws IOException { Path path = Files.createTempDirectory("test"); - String[] paths = new String[] { path.toString() }; nodePath = new NodeEnvironment.NodePath(path); LogConfigurator.setNodeName("test"); Settings settings = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), path) - .putList(Environment.PATH_DATA_SETTING.getKey(), paths) + .put(Environment.PATH_DATA_SETTING.getKey(), path.resolve("data")) .build(); nodeEnv = new NodeEnvironment(settings, new Environment(settings, null)); diff --git a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java index 2a9f11724ca57..1c0f4d7eb6e3c 100644 --- a/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java +++ b/plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureRepositorySettingsTests.java @@ -30,7 +30,7 @@ public class AzureRepositorySettingsTests extends ESTestCase { private AzureRepository azureRepository(Settings settings) { Settings internalSettings = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tmpPaths()) + .put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath()) .put(settings) .build(); final AzureRepository azureRepository = new AzureRepository(new RepositoryMetadata("foo", "azure", internalSettings), diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java index fbc02fbc24354..149908d8724c1 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/bootstrap/EvilSecurityTests.java @@ -24,9 +24,6 @@ import java.security.Permissions; import java.util.Set; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasToString; - @SuppressForbidden(reason = "modifies system properties and attempts to create symbolic links intentionally") public class EvilSecurityTests extends ESTestCase { @@ -70,8 +67,7 @@ public void testEnvironmentPaths() throws Exception { Settings.Builder settingsBuilder = Settings.builder(); settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(), esHome.resolve("home").toString()); - settingsBuilder.putList(Environment.PATH_DATA_SETTING.getKey(), esHome.resolve("data1").toString(), - esHome.resolve("data2").toString()); + settingsBuilder.put(Environment.PATH_DATA_SETTING.getKey(), esHome.resolve("data1").toString()); settingsBuilder.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), esHome.resolve("custom").toString()); settingsBuilder.put(Environment.PATH_LOGS_SETTING.getKey(), esHome.resolve("logs").toString()); settingsBuilder.put(Environment.NODE_PIDFILE_SETTING.getKey(), esHome.resolve("test.pid").toString()); @@ -124,31 +120,6 @@ public void testEnvironmentPaths() throws Exception { assertExactPermissions(new FilePermission(environment.pidFile().toString(), "delete"), permissions); } - public void testDuplicateDataPaths() throws IOException { - assumeFalse("https://github.com/elastic/elasticsearch/issues/44558", Constants.WINDOWS); - final Path path = createTempDir(); - final Path home = path.resolve("home"); - final Path data = path.resolve("data"); - final Path duplicate; - if (randomBoolean()) { - duplicate = data; - } else { - duplicate = createTempDir().toAbsolutePath().resolve("link"); - Files.createSymbolicLink(duplicate, data); - } - - final Settings settings = - Settings - .builder() - .put(Environment.PATH_HOME_SETTING.getKey(), home.toString()) - .putList(Environment.PATH_DATA_SETTING.getKey(), data.toString(), duplicate.toString()) - .build(); - - final Environment environment = TestEnvironment.newEnvironment(settings); - final IllegalStateException e = expectThrows(IllegalStateException.class, () -> Security.createPermissions(environment)); - assertThat(e, hasToString(containsString("path [" + duplicate.toRealPath() + "] is duplicated by [" + duplicate + "]"))); - } - public void testEnsureSymlink() throws IOException { Path p = createTempDir(); diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/env/NodeEnvironmentEvilTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/env/NodeEnvironmentEvilTests.java index 233af7905083d..8d24dd1bc2339 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/env/NodeEnvironmentEvilTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/env/NodeEnvironmentEvilTests.java @@ -7,7 +7,6 @@ */ package org.elasticsearch.env; -import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.PosixPermissionsResetter; @@ -32,14 +31,13 @@ public static void checkPosix() throws IOException { public void testMissingWritePermission() throws IOException { assumeTrue("posix filesystem", isPosix); - final String[] tempPaths = tmpPaths(); - Path path = PathUtils.get(randomFrom(tempPaths)); + Path path = createTempDir(); try (PosixPermissionsResetter attr = new PosixPermissionsResetter(path)) { attr.setPermissions(new HashSet<>(Arrays.asList(PosixFilePermission.OTHERS_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OWNER_READ))); Settings build = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build(); + .put(Environment.PATH_DATA_SETTING.getKey(), path).build(); IllegalStateException exception = expectThrows(IllegalStateException.class, () -> { new NodeEnvironment(build, TestEnvironment.newEnvironment(build)); }); @@ -50,8 +48,7 @@ public void testMissingWritePermission() throws IOException { public void testMissingWritePermissionOnIndex() throws IOException { assumeTrue("posix filesystem", isPosix); - final String[] tempPaths = tmpPaths(); - Path path = PathUtils.get(randomFrom(tempPaths)); + Path path = createTempDir(); Path fooIndex = path.resolve(NodeEnvironment.INDICES_FOLDER) .resolve("foo"); Files.createDirectories(fooIndex); @@ -60,7 +57,7 @@ public void testMissingWritePermissionOnIndex() throws IOException { PosixFilePermission.OWNER_READ))); Settings build = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build(); + .put(Environment.PATH_DATA_SETTING.getKey(), path).build(); IOException ioException = expectThrows(IOException.class, () -> { new NodeEnvironment(build, TestEnvironment.newEnvironment(build)); }); @@ -70,8 +67,7 @@ public void testMissingWritePermissionOnIndex() throws IOException { public void testMissingWritePermissionOnShard() throws IOException { assumeTrue("posix filesystem", isPosix); - final String[] tempPaths = tmpPaths(); - Path path = PathUtils.get(randomFrom(tempPaths)); + Path path = createTempDir(); Path fooIndex = path.resolve(NodeEnvironment.INDICES_FOLDER) .resolve("foo"); Path fooShard = fooIndex.resolve("0"); @@ -85,7 +81,7 @@ public void testMissingWritePermissionOnShard() throws IOException { PosixFilePermission.OWNER_READ))); Settings build = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build(); + .put(Environment.PATH_DATA_SETTING.getKey(), path).build(); IOException ioException = expectThrows(IOException.class, () -> { new NodeEnvironment(build, TestEnvironment.newEnvironment(build)); }); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java index 6cb5dfc1cec1c..aaa175f686a20 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/env/NodeEnvironmentIT.java @@ -28,7 +28,6 @@ import java.nio.file.StandardCopyOption; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.test.NodeRoles.nonDataNode; @@ -137,8 +136,7 @@ public void testUpgradeDataFolder() throws IOException, InterruptedException { internalCluster().stopRandomDataNode(); // simulate older data path layout by moving data under "nodes/0" folder - final List dataPaths = Environment.PATH_DATA_SETTING.get(dataPathSettings) - .stream().map(PathUtils::get).collect(Collectors.toList()); + final List dataPaths = List.of(PathUtils.get(Environment.PATH_DATA_SETTING.get(dataPathSettings))); dataPaths.forEach(path -> { final Path targetPath = path.resolve("nodes").resolve("0"); try { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/plugins/IndexFoldersDeletionListenerIT.java b/server/src/internalClusterTest/java/org/elasticsearch/plugins/IndexFoldersDeletionListenerIT.java index c84caf6aaa6db..7f44fe47a19b9 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/plugins/IndexFoldersDeletionListenerIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/plugins/IndexFoldersDeletionListenerIT.java @@ -235,7 +235,7 @@ public void testListenersInvokedWhenIndexHasLeftOverShard() throws Exception { final Path dataDirWithLeftOverShards = createTempDir(); String dataNode = internalCluster().startDataOnlyNode( Settings.builder() - .putList(Environment.PATH_DATA_SETTING.getKey(), List.of(dataDirWithLeftOverShards.toAbsolutePath().toString())) + .put(Environment.PATH_DATA_SETTING.getKey(), dataDirWithLeftOverShards.toAbsolutePath().toString()) .putNull(Environment.PATH_SHARED_DATA_SETTING.getKey()) .build() ); diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinHelper.java b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinHelper.java index ad3828b35ea11..e422e2358300a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinHelper.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinHelper.java @@ -123,7 +123,7 @@ public ClusterTasksResult execute(ClusterState currentSta channel.sendResponse(Empty.INSTANCE); }); - final List dataPaths = Environment.PATH_DATA_SETTING.get(settings); + final String dataPath = Environment.PATH_DATA_SETTING.get(settings); transportService.registerRequestHandler(VALIDATE_JOIN_ACTION_NAME, ThreadPool.Names.GENERIC, ValidateJoinRequest::new, (request, channel, task) -> { @@ -134,9 +134,8 @@ public ClusterTasksResult execute(ClusterState currentSta localState.metadata().clusterUUID() + "] and is now trying to join a different cluster with UUID [" + request.getState().metadata().clusterUUID() + "]. This is forbidden and usually indicates an incorrect " + "discovery or cluster bootstrapping configuration. Note that the cluster UUID persists across restarts and " + - "can only be changed by deleting the contents of the node's data " + - (dataPaths.size() == 1 ? "path " : "paths ") + dataPaths + - " which will also remove any data held by this node."); + "can only be changed by deleting the contents of the node's data path [" + dataPath + + "] which will also remove any data held by this node."); } joinValidators.forEach(action -> action.accept(transportService.getLocalNode(), request.getState())); channel.sendResponse(Empty.INSTANCE); diff --git a/server/src/main/java/org/elasticsearch/env/Environment.java b/server/src/main/java/org/elasticsearch/env/Environment.java index 00581e07a8b15..33ad72358205a 100644 --- a/server/src/main/java/org/elasticsearch/env/Environment.java +++ b/server/src/main/java/org/elasticsearch/env/Environment.java @@ -40,8 +40,8 @@ public class Environment { private static final Path[] EMPTY_PATH_ARRAY = new Path[0]; public static final Setting PATH_HOME_SETTING = Setting.simpleString("path.home", Property.NodeScope); - public static final Setting> PATH_DATA_SETTING = - Setting.listSetting("path.data", Collections.emptyList(), Function.identity(), Property.NodeScope); + public static final Setting PATH_DATA_SETTING = + Setting.simpleString("path.data", Property.NodeScope); public static final Setting PATH_LOGS_SETTING = new Setting<>("path.logs", "", Function.identity(), Property.NodeScope); public static final Setting> PATH_REPO_SETTING = @@ -51,7 +51,7 @@ public class Environment { private final Settings settings; - private final Path[] dataFiles; + private final Path dataFile; private final Path[] repoFiles; @@ -100,14 +100,10 @@ public Environment(final Settings settings, final Path configPath) { pluginsFile = homeFile.resolve("plugins"); - List dataPaths = PATH_DATA_SETTING.get(settings); - if (dataPaths.isEmpty() == false) { - dataFiles = new Path[dataPaths.size()]; - for (int i = 0; i < dataPaths.size(); i++) { - dataFiles[i] = PathUtils.get(dataPaths.get(i)).toAbsolutePath().normalize(); - } + if (PATH_DATA_SETTING.exists(settings)) { + dataFile = PathUtils.get(PATH_DATA_SETTING.get(settings)).toAbsolutePath().normalize(); } else { - dataFiles = new Path[]{homeFile.resolve("data")}; + dataFile = homeFile.resolve("data"); } if (PATH_SHARED_DATA_SETTING.exists(settings)) { sharedDataFile = PathUtils.get(PATH_SHARED_DATA_SETTING.get(settings)).toAbsolutePath().normalize(); @@ -143,12 +139,7 @@ public Environment(final Settings settings, final Path configPath) { final Settings.Builder finalSettings = Settings.builder().put(settings); if (PATH_DATA_SETTING.exists(settings)) { - if (dataFiles.length == 1) { - finalSettings.put(PATH_DATA_SETTING.getKey(), dataFiles[0].toString()); - } else { - finalSettings.putList(PATH_DATA_SETTING.getKey(), - Arrays.stream(dataFiles).map(Path::toString).collect(Collectors.toList())); - } + finalSettings.put(PATH_DATA_SETTING.getKey(), dataFile.toString()); } finalSettings.put(PATH_HOME_SETTING.getKey(), homeFile); finalSettings.put(PATH_LOGS_SETTING.getKey(), logsFile.toString()); @@ -179,7 +170,7 @@ public Settings settings() { * The data location. */ public Path[] dataFiles() { - return dataFiles; + return new Path[] { dataFile }; } /** diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index 839ea855615c9..066888b71d0dd 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -306,9 +306,7 @@ protected Node(final Environment initialEnvironment, Build.CURRENT.getQualifiedVersion()); } - if (initialEnvironment.dataFiles().length > 1) { - throw new IllegalArgumentException("Multiple [path.data] values found. Specify a single data path."); - } else if (Environment.dataPathUsesList(tmpSettings)) { + if (Environment.dataPathUsesList(tmpSettings)) { throw new IllegalArgumentException("[path.data] is a list. Specify as a string value."); } diff --git a/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java index dac558f1a50a5..b3327ac31ce75 100644 --- a/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/EnvironmentTests.java @@ -140,9 +140,8 @@ public void testPathNormalization() throws IOException { final Path home = PathUtils.get(homePath); - final List dataPaths = Environment.PATH_DATA_SETTING.get(environment.settings()); - assertThat(dataPaths, hasSize(1)); - assertPath(dataPaths.get(0), home.resolve("data")); + final String dataPath = Environment.PATH_DATA_SETTING.get(environment.settings()); + assertPath(dataPath, home.resolve("data")); final String logPath = Environment.PATH_LOGS_SETTING.get(environment.settings()); assertPath(logPath, home.resolve("logs")); diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 7ddf90b2dec65..b03f376ab2209 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -41,7 +41,6 @@ import static org.elasticsearch.test.NodeRoles.nonDataNode; import static org.elasticsearch.test.NodeRoles.nonMasterNode; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.startsWith; @@ -53,7 +52,7 @@ public class NodeEnvironmentTests extends ESTestCase { public void testNodeLock() throws IOException { final Settings settings = buildEnvSettings(Settings.EMPTY); NodeEnvironment env = newNodeEnvironment(settings); - List dataPaths = Environment.PATH_DATA_SETTING.get(settings); + String dataPath = Environment.PATH_DATA_SETTING.get(settings); // Reuse the same location and attempt to lock again IllegalStateException ex = expectThrows(IllegalStateException.class, () -> @@ -63,11 +62,8 @@ public void testNodeLock() throws IOException { // Close the environment that holds the lock and make sure we can get the lock after release env.close(); env = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings)); - assertThat(env.nodeDataPaths(), arrayWithSize(dataPaths.size())); + assertThat(env.nodeDataPaths()[0], equalTo(PathUtils.get(dataPath))); - for (int i = 0; i < dataPaths.size(); i++) { - assertTrue(env.nodeDataPaths()[i].startsWith(PathUtils.get(dataPaths.get(i)))); - } env.close(); assertThat(env.lockedShards(), empty()); } @@ -350,8 +346,8 @@ public void run() { } public void testCustomDataPaths() throws Exception { - String[] dataPaths = tmpPaths(); - NodeEnvironment env = newNodeEnvironment(dataPaths, "/tmp", Settings.EMPTY); + Path dataPath = createTempDir(); + NodeEnvironment env = newNodeEnvironment(dataPath.toAbsolutePath().toString(), "/tmp", Settings.EMPTY); Index index = new Index("myindex", "myindexUUID"); ShardId sid = new ShardId(index, 0); @@ -361,53 +357,47 @@ public void testCustomDataPaths() throws Exception { equalTo(PathUtils.get("/tmp/foo/0/" + index.getUUID() + "/0").toAbsolutePath())); assertThat("shard paths with a custom data_path should contain only regular paths", - env.availableShardPaths(sid), - equalTo(stringsToPaths(dataPaths, "indices/" + index.getUUID() + "/0"))); + env.availableShardPaths(sid)[0], + equalTo(dataPath.resolve("indices/" + index.getUUID() + "/0"))); assertThat("index paths uses the regular template", - env.indexPaths(index), equalTo(stringsToPaths(dataPaths, "indices/" + index.getUUID()))); + env.indexPaths(index)[0], equalTo(dataPath.resolve("indices/" + index.getUUID()))); assertThat(env.availableShardPaths(sid), equalTo(env.availableShardPaths(sid))); assertThat(env.resolveCustomLocation("/tmp/foo", sid).toAbsolutePath(), equalTo(PathUtils.get("/tmp/foo/0/" + index.getUUID() + "/0").toAbsolutePath())); assertThat("shard paths with a custom data_path should contain only regular paths", - env.availableShardPaths(sid), - equalTo(stringsToPaths(dataPaths, "indices/" + index.getUUID() + "/0"))); + env.availableShardPaths(sid)[0], + equalTo(dataPath.resolve("indices/" + index.getUUID() + "/0"))); assertThat("index paths uses the regular template", - env.indexPaths(index), equalTo(stringsToPaths(dataPaths, "indices/" + index.getUUID()))); + env.indexPaths(index)[0], equalTo(dataPath.resolve("indices/" + index.getUUID()))); env.close(); } public void testExistingTempFiles() throws IOException { - String[] paths = tmpPaths(); + Path nodePath = createTempDir(); // simulate some previous left over temp files - for (String path : randomSubsetOf(randomIntBetween(1, paths.length), paths)) { - final Path nodePath = PathUtils.get(path); - Files.createDirectories(nodePath); - Files.createFile(nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME)); - if (randomBoolean()) { - Files.createFile(nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".tmp")); - } - if (randomBoolean()) { - Files.createFile(nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".final")); - } + Files.createDirectories(nodePath); + Files.createFile(nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME)); + if (randomBoolean()) { + Files.createFile(nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".tmp")); } - NodeEnvironment env = newNodeEnvironment(paths, Settings.EMPTY); + if (randomBoolean()) { + Files.createFile(nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".final")); + } + NodeEnvironment env = newNodeEnvironment(nodePath.toAbsolutePath().toString(), Settings.EMPTY); env.close(); // check we clean up - for (String path : paths) { - final Path nodePath = PathUtils.get(path); - final Path tempFile = nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME); - assertFalse(tempFile + " should have been cleaned", Files.exists(tempFile)); - final Path srcTempFile = nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".src"); - assertFalse(srcTempFile + " should have been cleaned", Files.exists(srcTempFile)); - final Path targetTempFile = nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".target"); - assertFalse(targetTempFile + " should have been cleaned", Files.exists(targetTempFile)); - } + final Path tempFile = nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME); + assertFalse(tempFile + " should have been cleaned", Files.exists(tempFile)); + final Path srcTempFile = nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".src"); + assertFalse(srcTempFile + " should have been cleaned", Files.exists(srcTempFile)); + final Path targetTempFile = nodePath.resolve(NodeEnvironment.TEMP_FILE_NAME + ".target"); + assertFalse(targetTempFile + " should have been cleaned", Files.exists(targetTempFile)); } public void testEnsureNoShardDataOrIndexMetadata() throws IOException { @@ -499,16 +489,6 @@ private Path[] stringsToPaths(String[] strings, String additional) { return locations; } - @Override - public String[] tmpPaths() { - final int numPaths = randomIntBetween(1, 3); - final String[] absPaths = new String[numPaths]; - for (int i = 0; i < numPaths; i++) { - absPaths[i] = createTempDir().toAbsolutePath().toString(); - } - return absPaths; - } - @Override public NodeEnvironment newNodeEnvironment() throws IOException { return newNodeEnvironment(Settings.EMPTY); @@ -523,24 +503,24 @@ public NodeEnvironment newNodeEnvironment(Settings settings) throws IOException public Settings buildEnvSettings(Settings settings) { return Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tmpPaths()) + .put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) .put(settings).build(); } - public NodeEnvironment newNodeEnvironment(String[] dataPaths, Settings settings) throws IOException { + public NodeEnvironment newNodeEnvironment(String dataPath, Settings settings) throws IOException { Settings build = Settings.builder() .put(settings) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) - .putList(Environment.PATH_DATA_SETTING.getKey(), dataPaths).build(); + .put(Environment.PATH_DATA_SETTING.getKey(), dataPath).build(); return new NodeEnvironment(build, TestEnvironment.newEnvironment(build)); } - public NodeEnvironment newNodeEnvironment(String[] dataPaths, String sharedDataPath, Settings settings) throws IOException { + public NodeEnvironment newNodeEnvironment(String dataPath, String sharedDataPath, Settings settings) throws IOException { Settings build = Settings.builder() .put(settings) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) .put(Environment.PATH_SHARED_DATA_SETTING.getKey(), sharedDataPath) - .putList(Environment.PATH_DATA_SETTING.getKey(), dataPaths).build(); + .put(Environment.PATH_DATA_SETTING.getKey(), dataPath).build(); return new NodeEnvironment(build, TestEnvironment.newEnvironment(build)); } } diff --git a/server/src/test/java/org/elasticsearch/gateway/PersistedClusterStateServiceTests.java b/server/src/test/java/org/elasticsearch/gateway/PersistedClusterStateServiceTests.java index ae64778534a80..25cf1d3e723f2 100644 --- a/server/src/test/java/org/elasticsearch/gateway/PersistedClusterStateServiceTests.java +++ b/server/src/test/java/org/elasticsearch/gateway/PersistedClusterStateServiceTests.java @@ -12,7 +12,6 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FilterDirectory; import org.apache.lucene.store.IOContext; @@ -33,10 +32,8 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.MockBigArrays; import org.elasticsearch.common.util.MockPageCacheRecycler; -import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.env.NodeMetadata; import org.elasticsearch.gateway.PersistedClusterStateService.Writer; import org.elasticsearch.index.Index; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; @@ -48,14 +45,10 @@ import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; -import java.util.stream.Stream; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; @@ -72,7 +65,7 @@ private PersistedClusterStateService newPersistedClusterStateService(NodeEnviron } public void testPersistsAndReloadsTerm() throws IOException { - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = newPersistedClusterStateService(nodeEnvironment); final long newTerm = randomNonNegativeLong(); @@ -87,7 +80,7 @@ public void testPersistsAndReloadsTerm() throws IOException { } public void testPersistsAndReloadsGlobalMetadata() throws IOException { - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = newPersistedClusterStateService(nodeEnvironment); final String clusterUUID = UUIDs.randomBase64UUID(random()); final long version = randomLongBetween(1L, Long.MAX_VALUE); @@ -131,216 +124,10 @@ private static void writeState(Writer writer, long currentTerm, ClusterState clu } } - public void testLoadsFreshestState() throws IOException { - final Path[] dataPaths = createDataPaths(); - final long freshTerm = randomLongBetween(1L, Long.MAX_VALUE); - final long staleTerm = randomBoolean() ? freshTerm : randomLongBetween(1L, freshTerm); - final long freshVersion = randomLongBetween(2L, Long.MAX_VALUE); - final long staleVersion = staleTerm == freshTerm ? randomLongBetween(1L, freshVersion - 1) : randomLongBetween(1L, Long.MAX_VALUE); - - final HashSet unimportantPaths = Arrays.stream(dataPaths).collect(Collectors.toCollection(HashSet::new)); - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths)) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - writeState(writer, staleTerm, - ClusterState.builder(clusterState).version(staleVersion) - .metadata(Metadata.builder(clusterState.metadata()).coordinationMetadata( - CoordinationMetadata.builder(clusterState.coordinationMetadata()).term(staleTerm).build())).build(), - clusterState); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(new Path[]{randomFrom(dataPaths)})) { - unimportantPaths.remove(nodeEnvironment.nodeDataPaths()[0]); - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - writeState(writer, freshTerm, - ClusterState.builder(clusterState).version(freshVersion) - .metadata(Metadata.builder(clusterState.metadata()).coordinationMetadata( - CoordinationMetadata.builder(clusterState.coordinationMetadata()).term(freshTerm).build())).build(), - clusterState); - } - } - - if (randomBoolean() && unimportantPaths.isEmpty() == false) { - IOUtils.rm(randomFrom(unimportantPaths)); - } - - // verify that the freshest state is chosen - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths)) { - final PersistedClusterStateService.OnDiskState onDiskState = newPersistedClusterStateService(nodeEnvironment) - .loadBestOnDiskState(); - final ClusterState clusterState = clusterStateFromMetadata(onDiskState.lastAcceptedVersion, onDiskState.metadata); - assertThat(clusterState.term(), equalTo(freshTerm)); - assertThat(clusterState.version(), equalTo(freshVersion)); - } - } - - public void testFailsOnMismatchedNodeIds() throws IOException { - final Path[] dataPaths1 = createDataPaths(); - final Path[] dataPaths2 = createDataPaths(); - - final String[] nodeIds = new String[2]; - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths1)) { - nodeIds[0] = nodeEnvironment.nodeId(); - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - writer.writeFullStateAndCommit(0L, - ClusterState.builder(clusterState).version(randomLongBetween(1L, Long.MAX_VALUE)).build()); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths2)) { - nodeIds[1] = nodeEnvironment.nodeId(); - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - writer.writeFullStateAndCommit(0L, - ClusterState.builder(clusterState).version(randomLongBetween(1L, Long.MAX_VALUE)).build()); - } - } - - NodeMetadata.FORMAT.cleanupOldFiles(Long.MAX_VALUE, dataPaths2); - - final Path[] combinedPaths = Stream.concat(Arrays.stream(dataPaths1), Arrays.stream(dataPaths2)).toArray(Path[]::new); - - final String failure = expectThrows(IllegalStateException.class, () -> newNodeEnvironment(combinedPaths)).getMessage(); - assertThat(failure, - allOf(containsString("unexpected node ID in metadata"), containsString(nodeIds[0]), containsString(nodeIds[1]))); - assertTrue("[" + failure + "] should match " + Arrays.toString(dataPaths2), - Arrays.stream(dataPaths2).anyMatch(p -> failure.contains(p.toString()))); - - // verify that loadBestOnDiskState has same check - final String message = expectThrows(IllegalStateException.class, - () -> new PersistedClusterStateService(combinedPaths, nodeIds[0], xContentRegistry(), BigArrays.NON_RECYCLING_INSTANCE, - new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), - () -> 0L).loadBestOnDiskState()).getMessage(); - assertThat(message, - allOf(containsString("unexpected node ID in metadata"), containsString(nodeIds[0]), containsString(nodeIds[1]))); - assertTrue("[" + message + "] should match " + Arrays.toString(dataPaths2), - Arrays.stream(dataPaths2).anyMatch(p -> message.contains(p.toString()))); - } - - public void testFailsOnMismatchedCommittedClusterUUIDs() throws IOException { - final Path[] dataPaths1 = createDataPaths(); - final Path[] dataPaths2 = createDataPaths(); - final Path[] combinedPaths = Stream.concat(Arrays.stream(dataPaths1), Arrays.stream(dataPaths2)).toArray(Path[]::new); - - final String clusterUUID1 = UUIDs.randomBase64UUID(random()); - final String clusterUUID2 = UUIDs.randomBase64UUID(random()); - - // first establish consistent node IDs and write initial metadata - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(combinedPaths)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - assertFalse(clusterState.metadata().clusterUUIDCommitted()); - writer.writeFullStateAndCommit(0L, clusterState); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths1)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - assertFalse(clusterState.metadata().clusterUUIDCommitted()); - writer.writeFullStateAndCommit(0L, ClusterState.builder(clusterState) - .metadata(Metadata.builder(clusterState.metadata()) - .clusterUUID(clusterUUID1) - .clusterUUIDCommitted(true) - .version(1)) - .incrementVersion().build()); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths2)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - assertFalse(clusterState.metadata().clusterUUIDCommitted()); - writer.writeFullStateAndCommit(0L, ClusterState.builder(clusterState) - .metadata(Metadata.builder(clusterState.metadata()) - .clusterUUID(clusterUUID2) - .clusterUUIDCommitted(true) - .version(1)) - .incrementVersion().build()); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(combinedPaths)) { - final String message = expectThrows(IllegalStateException.class, - () -> newPersistedClusterStateService(nodeEnvironment).loadBestOnDiskState()).getMessage(); - assertThat(message, - allOf(containsString("mismatched cluster UUIDs in metadata"), containsString(clusterUUID1), containsString(clusterUUID2))); - assertTrue("[" + message + "] should match " + Arrays.toString(dataPaths1), - Arrays.stream(dataPaths1).anyMatch(p -> message.contains(p.toString()))); - assertTrue("[" + message + "] should match " + Arrays.toString(dataPaths2), - Arrays.stream(dataPaths2).anyMatch(p -> message.contains(p.toString()))); - } - } - - public void testFailsIfFreshestStateIsInStaleTerm() throws IOException { - final Path[] dataPaths1 = createDataPaths(); - final Path[] dataPaths2 = createDataPaths(); - final Path[] combinedPaths = Stream.concat(Arrays.stream(dataPaths1), Arrays.stream(dataPaths2)).toArray(Path[]::new); - - final long staleCurrentTerm = randomLongBetween(1L, Long.MAX_VALUE - 1); - final long freshCurrentTerm = randomLongBetween(staleCurrentTerm + 1, Long.MAX_VALUE); - - final long freshTerm = randomLongBetween(1L, Long.MAX_VALUE); - final long staleTerm = randomBoolean() ? freshTerm : randomLongBetween(1L, freshTerm); - final long freshVersion = randomLongBetween(2L, Long.MAX_VALUE); - final long staleVersion = staleTerm == freshTerm ? randomLongBetween(1L, freshVersion - 1) : randomLongBetween(1L, Long.MAX_VALUE); - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(combinedPaths)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - assertFalse(clusterState.metadata().clusterUUIDCommitted()); - writeState(writer, staleCurrentTerm, ClusterState.builder(clusterState) - .metadata(Metadata.builder(clusterState.metadata()).version(1) - .coordinationMetadata(CoordinationMetadata.builder(clusterState.coordinationMetadata()).term(staleTerm).build())) - .version(staleVersion) - .build(), - clusterState); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths1)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - writeState(writer, freshCurrentTerm, clusterState, clusterState); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(dataPaths2)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final PersistedClusterStateService.OnDiskState onDiskState = newPersistedClusterStateService(nodeEnvironment) - .loadBestOnDiskState(); - final ClusterState clusterState = clusterStateFromMetadata(onDiskState.lastAcceptedVersion, onDiskState.metadata); - writeState(writer, onDiskState.currentTerm, ClusterState.builder(clusterState) - .metadata(Metadata.builder(clusterState.metadata()).version(2) - .coordinationMetadata(CoordinationMetadata.builder(clusterState.coordinationMetadata()).term(freshTerm).build())) - .version(freshVersion) - .build(), clusterState); - } - } - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(combinedPaths)) { - final String message = expectThrows(IllegalStateException.class, - () -> newPersistedClusterStateService(nodeEnvironment).loadBestOnDiskState()).getMessage(); - assertThat(message, allOf( - containsString("inconsistent terms found"), - containsString(Long.toString(staleCurrentTerm)), - containsString(Long.toString(freshCurrentTerm)))); - assertTrue("[" + message + "] should match " + Arrays.toString(dataPaths1), - Arrays.stream(dataPaths1).anyMatch(p -> message.contains(p.toString()))); - assertTrue("[" + message + "] should match " + Arrays.toString(dataPaths2), - Arrays.stream(dataPaths2).anyMatch(p -> message.contains(p.toString()))); - } - } - public void testFailsGracefullyOnExceptionDuringFlush() throws IOException { final AtomicBoolean throwException = new AtomicBoolean(); - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), getBigArrays(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L) { @@ -378,7 +165,7 @@ public IndexOutput createOutput(String name, IOContext context) throws IOExcepti public void testClosesWriterOnFatalError() throws IOException { final AtomicBoolean throwException = new AtomicBoolean(); - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), getBigArrays(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L) { @@ -424,7 +211,7 @@ public void sync(Collection names) { public void testCrashesWithIOErrorOnCommitFailure() throws IOException { final AtomicBoolean throwException = new AtomicBoolean(); - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), getBigArrays(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), () -> 0L) { @@ -473,7 +260,7 @@ public void testFailsIfGlobalMetadataIsMissing() throws IOException { // if someone attempted surgery on the metadata index by hand, e.g. deleting broken segments, then maybe the global metadata // isn't there any more - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); writeState(writer, 0L, ClusterState.builder(clusterState).version(randomLongBetween(1L, Long.MAX_VALUE)).build(), @@ -495,89 +282,8 @@ public void testFailsIfGlobalMetadataIsMissing() throws IOException { } } - public void testFailsIfGlobalMetadataIsDuplicated() throws IOException { - // if someone attempted surgery on the metadata index by hand, e.g. deleting broken segments, then maybe the global metadata - // is duplicated - - final Path[] dataPaths1 = createDataPaths(); - final Path[] dataPaths2 = createDataPaths(); - final Path[] combinedPaths = Stream.concat(Arrays.stream(dataPaths1), Arrays.stream(dataPaths2)).toArray(Path[]::new); - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(combinedPaths)) { - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - writeState(writer, 0L, ClusterState.builder(clusterState).version(randomLongBetween(1L, Long.MAX_VALUE)).build(), - clusterState); - } - - final Path brokenPath = randomFrom(nodeEnvironment.nodeDataPaths()); - final Path dupPath = randomValueOtherThan(brokenPath, () -> randomFrom(nodeEnvironment.nodeDataPaths())); - try (Directory directory = new SimpleFSDirectory(brokenPath.resolve(PersistedClusterStateService.METADATA_DIRECTORY_NAME)); - Directory dupDirectory = new SimpleFSDirectory(dupPath.resolve(PersistedClusterStateService.METADATA_DIRECTORY_NAME))) { - try (IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig())) { - indexWriter.addIndexes(dupDirectory); - indexWriter.commit(); - } - } - - final String message = expectThrows(IllegalStateException.class, - () -> newPersistedClusterStateService(nodeEnvironment).loadBestOnDiskState()).getMessage(); - assertThat(message, allOf(containsString("duplicate global metadata found"), containsString(brokenPath.toString()))); - } - } - - public void testFailsIfIndexMetadataIsDuplicated() throws IOException { - // if someone attempted surgery on the metadata index by hand, e.g. deleting broken segments, then maybe some index metadata - // is duplicated - - final Path[] dataPaths1 = createDataPaths(); - final Path[] dataPaths2 = createDataPaths(); - final Path[] combinedPaths = Stream.concat(Arrays.stream(dataPaths1), Arrays.stream(dataPaths2)).toArray(Path[]::new); - - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(combinedPaths)) { - final String indexUUID = UUIDs.randomBase64UUID(random()); - final String indexName = randomAlphaOfLength(10); - - try (Writer writer = newPersistedClusterStateService(nodeEnvironment).createWriter()) { - final ClusterState clusterState = loadPersistedClusterState(newPersistedClusterStateService(nodeEnvironment)); - writeState(writer, 0L, ClusterState.builder(clusterState) - .metadata(Metadata.builder(clusterState.metadata()) - .version(1L) - .coordinationMetadata(CoordinationMetadata.builder(clusterState.coordinationMetadata()).term(1L).build()) - .put(IndexMetadata.builder(indexName) - .version(1L) - .settings(Settings.builder() - .put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1) - .put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0) - .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) - .put(IndexMetadata.SETTING_INDEX_UUID, indexUUID)))) - .incrementVersion().build(), - clusterState); - } - - final Path brokenPath = randomFrom(nodeEnvironment.nodeDataPaths()); - final Path dupPath = randomValueOtherThan(brokenPath, () -> randomFrom(nodeEnvironment.nodeDataPaths())); - try (Directory directory = new SimpleFSDirectory(brokenPath.resolve(PersistedClusterStateService.METADATA_DIRECTORY_NAME)); - Directory dupDirectory = new SimpleFSDirectory(dupPath.resolve(PersistedClusterStateService.METADATA_DIRECTORY_NAME))) { - try (IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig())) { - indexWriter.deleteDocuments(new Term("type", "global")); // do not duplicate global metadata - indexWriter.addIndexes(dupDirectory); - indexWriter.commit(); - } - } - - final String message = expectThrows(IllegalStateException.class, - () -> newPersistedClusterStateService(nodeEnvironment).loadBestOnDiskState()).getMessage(); - assertThat(message, allOf( - containsString("duplicate metadata found"), - containsString(brokenPath.toString()), - containsString(indexName), - containsString(indexUUID))); - } - } - public void testPersistsAndReloadsIndexMetadataIffVersionOrTermChanges() throws IOException { - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = newPersistedClusterStateService(nodeEnvironment); final long globalVersion = randomLongBetween(1L, Long.MAX_VALUE); final String indexUUID = UUIDs.randomBase64UUID(random()); @@ -654,7 +360,7 @@ public void testPersistsAndReloadsIndexMetadataIffVersionOrTermChanges() throws } public void testPersistsAndReloadsIndexMetadataForMultipleIndices() throws IOException { - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = newPersistedClusterStateService(nodeEnvironment); final long term = randomLongBetween(1L, Long.MAX_VALUE); @@ -726,7 +432,7 @@ public void testPersistsAndReloadsIndexMetadataForMultipleIndices() throws IOExc } public void testReloadsMetadataAcrossMultipleSegments() throws IOException { - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { final PersistedClusterStateService persistedClusterStateService = newPersistedClusterStateService(nodeEnvironment); final int writes = between(5, 20); @@ -782,7 +488,7 @@ public void testSlowLogging() throws IOException, IllegalAccessException { final AtomicLong writeDurationMillis = new AtomicLong(slowWriteLoggingThresholdMillis); final ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); - try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createDataPaths())) { + try (NodeEnvironment nodeEnvironment = newNodeEnvironment(createTempDir())) { PersistedClusterStateService persistedClusterStateService = new PersistedClusterStateService(nodeEnvironment, xContentRegistry(), getBigArrays(), clusterSettings, () -> currentTime.getAndAdd(writeDurationMillis.get())); @@ -879,17 +585,9 @@ public Settings buildEnvSettings(Settings settings) { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()).build(); } - public static Path[] createDataPaths() { - final Path[] dataPaths = new Path[randomIntBetween(1, 4)]; - for (int i = 0; i < dataPaths.length; i++) { - dataPaths[i] = createTempDir(); - } - return dataPaths; - } - - private NodeEnvironment newNodeEnvironment(Path[] dataPaths) throws IOException { + private NodeEnvironment newNodeEnvironment(Path dataPath) throws IOException { return newNodeEnvironment(Settings.builder() - .putList(Environment.PATH_DATA_SETTING.getKey(), Arrays.stream(dataPaths).map(Path::toString).collect(Collectors.toList())) + .put(Environment.PATH_DATA_SETTING.getKey(), dataPath.toString()) .build()); } diff --git a/server/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java b/server/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java deleted file mode 100644 index 884dbadd22cab..0000000000000 --- a/server/src/test/java/org/elasticsearch/index/shard/NewPathForShardTests.java +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.index.shard; - - -import org.apache.lucene.mockfile.FilterFileSystemProvider; -import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.common.io.PathUtils; -import org.elasticsearch.common.io.PathUtilsForTesting; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.env.NodeEnvironment; -import org.elasticsearch.env.NodeEnvironment.NodePath; -import org.elasticsearch.env.TestEnvironment; -import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.test.IndexSettingsModule; -import org.junit.AfterClass; -import org.junit.BeforeClass; - -import java.io.IOException; -import java.nio.file.FileStore; -import java.nio.file.FileSystem; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.FileAttributeView; -import java.nio.file.attribute.FileStoreAttributeView; -import java.nio.file.spi.FileSystemProvider; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; - -/** Separate test class from ShardPathTests because we need static (BeforeClass) setup to install mock filesystems... */ -public class NewPathForShardTests extends ESTestCase { - - private static final IndexSettings INDEX_SETTINGS = IndexSettingsModule.newIndexSettings("index", Settings.EMPTY); - - // Sneakiness to install mock file stores so we can pretend how much free space we have on each path.data: - private static MockFileStore aFileStore = new MockFileStore("mocka"); - private static MockFileStore bFileStore = new MockFileStore("mockb"); - private static String aPathPart; - private static String bPathPart; - - @BeforeClass - public static void installMockUsableSpaceFS() throws Exception { - FileSystem current = PathUtils.getDefaultFileSystem(); - aPathPart = current.getSeparator() + 'a' + current.getSeparator(); - bPathPart = current.getSeparator() + 'b' + current.getSeparator(); - FileSystemProvider mock = new MockUsableSpaceFileSystemProvider(current); - PathUtilsForTesting.installMock(mock.getFileSystem(null)); - } - - @AfterClass - public static void removeMockUsableSpaceFS() throws Exception { - PathUtilsForTesting.teardown(); - aFileStore = null; - bFileStore = null; - } - - /** Mock file system that fakes usable space for each FileStore */ - static class MockUsableSpaceFileSystemProvider extends FilterFileSystemProvider { - - MockUsableSpaceFileSystemProvider(FileSystem inner) { - super("mockusablespace://", inner); - final List fileStores = new ArrayList<>(); - fileStores.add(aFileStore); - fileStores.add(bFileStore); - } - - @Override - public FileStore getFileStore(Path path) throws IOException { - if (path.toString().contains(aPathPart) || (path.toString() + path.getFileSystem().getSeparator()).contains(aPathPart)) { - return aFileStore; - } else { - return bFileStore; - } - } - } - - static class MockFileStore extends FileStore { - - public long usableSpace; - - private final String desc; - - MockFileStore(String desc) { - this.desc = desc; - } - - @Override - public String type() { - return "mock"; - } - - @Override - public String name() { - return desc; - } - - @Override - public String toString() { - return desc; - } - - @Override - public boolean isReadOnly() { - return false; - } - - @Override - public long getTotalSpace() throws IOException { - return usableSpace*3; - } - - @Override - public long getUsableSpace() throws IOException { - return usableSpace; - } - - @Override - public long getUnallocatedSpace() throws IOException { - return usableSpace*2; - } - - @Override - public boolean supportsFileAttributeView(Class type) { - return false; - } - - @Override - public boolean supportsFileAttributeView(String name) { - return false; - } - - @Override - public V getFileStoreAttributeView(Class type) { - return null; - } - - @Override - public Object getAttribute(String attribute) throws IOException { - return null; - } - } - - static void createFakeShard(ShardPath path) throws IOException { - Files.createDirectories(path.resolveIndex().getParent()); - } - - public void testSelectNewPathForShard() throws Exception { - Path path = PathUtils.get(createTempDir().toString()); - - // Use 2 data paths: - String[] paths = new String[] {path.resolve("a").toString(), - path.resolve("b").toString()}; - - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), path) - .putList(Environment.PATH_DATA_SETTING.getKey(), paths).build(); - NodeEnvironment nodeEnv = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings)); - - // Make sure all our mocking above actually worked: - NodePath[] nodePaths = nodeEnv.nodePaths(); - assertEquals(2, nodePaths.length); - - assertEquals("mocka", nodePaths[0].fileStore.name()); - assertEquals("mockb", nodePaths[1].fileStore.name()); - - // Path a has lots of free space, but b has little, so new shard should go to a: - aFileStore.usableSpace = 100000; - bFileStore.usableSpace = 1000; - - ShardId shardId = new ShardId("index", "_na_", 0); - ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.emptyMap()); - assertTrue(result.getDataPath().toString().contains(aPathPart)); - - // Test the reverse: b has lots of free space, but a has little, so new shard should go to b: - aFileStore.usableSpace = 1000; - bFileStore.usableSpace = 100000; - - shardId = new ShardId("index", "_na_", 0); - result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.emptyMap()); - assertTrue(result.getDataPath().toString().contains(bPathPart)); - - // Now a and be have equal usable space; we allocate two shards to the node, and each should go to different paths: - aFileStore.usableSpace = 100000; - bFileStore.usableSpace = 100000; - - Map dataPathToShardCount = new HashMap<>(); - ShardPath result1 = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); - createFakeShard(result1); - dataPathToShardCount.put(NodeEnvironment.shardStatePathToDataPath(result1.getDataPath()), 1); - ShardPath result2 = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); - createFakeShard(result2); - - // #11122: this was the original failure: on a node with 2 disks that have nearly equal - // free space, we would always allocate all N incoming shards to the one path that - // had the most free space, never using the other drive unless new shards arrive - // after the first shards started using storage: - assertNotEquals(result1.getDataPath(), result2.getDataPath()); - - nodeEnv.close(); - } - - public void testSelectNewPathForShardEvenly() throws Exception { - Path path = PathUtils.get(createTempDir().toString()); - - // Use 2 data paths: - String[] paths = new String[] {path.resolve("a").toString(), - path.resolve("b").toString()}; - - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), path) - .putList(Environment.PATH_DATA_SETTING.getKey(), paths).build(); - NodeEnvironment nodeEnv = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings)); - - // Make sure all our mocking above actually worked: - NodePath[] nodePaths = nodeEnv.nodePaths(); - assertEquals(2, nodePaths.length); - - assertEquals("mocka", nodePaths[0].fileStore.name()); - assertEquals("mockb", nodePaths[1].fileStore.name()); - - // Path a has lots of free space, but b has little, so new shard should go to a: - aFileStore.usableSpace = 100000; - bFileStore.usableSpace = 10000; - - ShardId shardId = new ShardId("index", "uid1", 0); - ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.emptyMap()); - createFakeShard(result); - // First shard should go to a - assertThat(result.getDataPath().toString(), containsString(aPathPart)); - - shardId = new ShardId("index", "uid1", 1); - result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, Collections.emptyMap()); - createFakeShard(result); - // Second shard should go to b - assertThat(result.getDataPath().toString(), containsString(bPathPart)); - - Map dataPathToShardCount = new HashMap<>(); - shardId = new ShardId("index2", "uid2", 0); - IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index2", - Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build()); - ShardPath result1 = ShardPath.selectNewPathForShard(nodeEnv, shardId, idxSettings, 100, dataPathToShardCount); - createFakeShard(result1); - dataPathToShardCount.put(NodeEnvironment.shardStatePathToDataPath(result1.getDataPath()), 1); - shardId = new ShardId("index2", "uid2", 1); - ShardPath result2 = ShardPath.selectNewPathForShard(nodeEnv, shardId, idxSettings, 100, dataPathToShardCount); - createFakeShard(result2); - dataPathToShardCount.put(NodeEnvironment.shardStatePathToDataPath(result2.getDataPath()), 1); - shardId = new ShardId("index2", "uid2", 2); - ShardPath result3 = ShardPath.selectNewPathForShard(nodeEnv, shardId, idxSettings, 100, dataPathToShardCount); - createFakeShard(result3); - // 2 shards go to 'a' and 1 to 'b' - assertThat(result1.getDataPath().toString(), containsString(aPathPart)); - assertThat(result2.getDataPath().toString(), containsString(bPathPart)); - assertThat(result3.getDataPath().toString(), containsString(aPathPart)); - - nodeEnv.close(); - } - - public void testGettingPathWithMostFreeSpace() throws Exception { - Path path = PathUtils.get(createTempDir().toString()); - - // Use 2 data paths: - String[] paths = new String[] {path.resolve("a").toString(), - path.resolve("b").toString()}; - - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), path) - .putList(Environment.PATH_DATA_SETTING.getKey(), paths).build(); - NodeEnvironment nodeEnv = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings)); - - aFileStore.usableSpace = 100000; - bFileStore.usableSpace = 1000; - - assertThat(ShardPath.getPathWithMostFreeSpace(nodeEnv), equalTo(nodeEnv.nodePaths()[0])); - - aFileStore.usableSpace = 10000; - bFileStore.usableSpace = 20000; - - assertThat(ShardPath.getPathWithMostFreeSpace(nodeEnv), equalTo(nodeEnv.nodePaths()[1])); - - nodeEnv.close(); - } - - public void testTieBreakWithMostShards() throws Exception { - Path path = PathUtils.get(createTempDir().toString()); - - // Use 2 data paths: - String[] paths = new String[] {path.resolve("a").toString(), - path.resolve("b").toString()}; - - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), path) - .putList(Environment.PATH_DATA_SETTING.getKey(), paths).build(); - NodeEnvironment nodeEnv = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings)); - - // Make sure all our mocking above actually worked: - NodePath[] nodePaths = nodeEnv.nodePaths(); - assertEquals(2, nodePaths.length); - - assertEquals("mocka", nodePaths[0].fileStore.name()); - assertEquals("mockb", nodePaths[1].fileStore.name()); - - // Path a has lots of free space, but b has little, so new shard should go to a: - aFileStore.usableSpace = 100000; - bFileStore.usableSpace = 10000; - - Map dataPathToShardCount = new HashMap<>(); - - ShardId shardId = new ShardId("index", "uid1", 0); - ShardPath result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); - createFakeShard(result); - // First shard should go to a - assertThat(result.getDataPath().toString(), containsString(aPathPart)); - dataPathToShardCount.compute(NodeEnvironment.shardStatePathToDataPath(result.getDataPath()), (k, v) -> v == null ? 1 : v + 1); - - shardId = new ShardId("index", "uid1", 1); - result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); - createFakeShard(result); - // Second shard should go to b - assertThat(result.getDataPath().toString(), containsString(bPathPart)); - dataPathToShardCount.compute(NodeEnvironment.shardStatePathToDataPath(result.getDataPath()), (k, v) -> v == null ? 1 : v + 1); - - shardId = new ShardId("index2", "uid3", 0); - result = ShardPath.selectNewPathForShard(nodeEnv, shardId, INDEX_SETTINGS, 100, dataPathToShardCount); - createFakeShard(result); - // Shard for new index should go to a - assertThat(result.getDataPath().toString(), containsString(aPathPart)); - dataPathToShardCount.compute(NodeEnvironment.shardStatePathToDataPath(result.getDataPath()), (k, v) -> v == null ? 1 : v + 1); - - shardId = new ShardId("index2", "uid2", 0); - IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index2", - Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build()); - ShardPath result1 = ShardPath.selectNewPathForShard(nodeEnv, shardId, idxSettings, 100, dataPathToShardCount); - createFakeShard(result1); - dataPathToShardCount.compute(NodeEnvironment.shardStatePathToDataPath(result1.getDataPath()), (k, v) -> v == null ? 1 : v + 1); - shardId = new ShardId("index2", "uid2", 1); - ShardPath result2 = ShardPath.selectNewPathForShard(nodeEnv, shardId, idxSettings, 100, dataPathToShardCount); - createFakeShard(result2); - dataPathToShardCount.compute(NodeEnvironment.shardStatePathToDataPath(result2.getDataPath()), (k, v) -> v == null ? 1 : v + 1); - shardId = new ShardId("index2", "uid2", 2); - ShardPath result3 = ShardPath.selectNewPathForShard(nodeEnv, shardId, idxSettings, 100, dataPathToShardCount); - createFakeShard(result3); - // 2 shards go to 'b' and 1 to 'a' - assertThat(result1.getDataPath().toString(), containsString(bPathPart)); - assertThat(result2.getDataPath().toString(), containsString(aPathPart)); - assertThat(result3.getDataPath().toString(), containsString(bPathPart)); - - nodeEnv.close(); - } -} diff --git a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java index 480570e34ab04..b5875faf465cf 100644 --- a/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java +++ b/server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java @@ -99,7 +99,7 @@ public void setup() throws IOException { environment = TestEnvironment.newEnvironment(Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), dataDir) - .putList(Environment.PATH_DATA_SETTING.getKey(), dataDir.toAbsolutePath().toString()).build()); + .put(Environment.PATH_DATA_SETTING.getKey(), dataDir.toAbsolutePath().toString()).build()); // create same directory structure as prod does Files.createDirectories(dataDir); diff --git a/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java b/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java index 8bafa4031421e..9ae34f371e611 100644 --- a/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java +++ b/server/src/test/java/org/elasticsearch/repositories/fs/FsRepositoryTests.java @@ -79,7 +79,7 @@ public void testSnapshotAndRestore() throws IOException, InterruptedException { Settings settings = Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()) .put(Environment.PATH_REPO_SETTING.getKey(), repo.toAbsolutePath()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tmpPaths()) + .put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath()) .put("location", repo) .put("compress", randomBoolean()) .put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES).build(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java index 72980e630454e..7a88fa8614de9 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java @@ -1041,11 +1041,6 @@ public Path getDataPath(String relativePath) { } } - /** Returns a random number of temporary paths. */ - public String[] tmpPaths() { - return new String[] { createTempDir().toAbsolutePath().toString() }; - } - public NodeEnvironment newNodeEnvironment() throws IOException { return newNodeEnvironment(Settings.EMPTY); } diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java index 9e4c19c62fa8b..a34fe620c9730 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheService.java @@ -128,17 +128,6 @@ public void validate(final RelativeByteSizeValue value, final Map, Ob roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining(",")) ); } - - @SuppressWarnings("unchecked") - final List dataPaths = (List) settings.get(Environment.PATH_DATA_SETTING); - if (dataPaths.size() > 1) { - throw new SettingsException( - "setting [{}={}] is not permitted on nodes with multiple data paths [{}]", - SNAPSHOT_CACHE_SIZE_SETTING.getKey(), - value.getStringRep(), - String.join(",", dataPaths) - ); - } } } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java index 43f97dcb37b67..113ce4224b5cb 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/AbstractSearchableSnapshotsTestCase.java @@ -191,7 +191,7 @@ protected FrozenCacheService createFrozenCacheService(final ByteSizeValue cacheS private NodeEnvironment newSinglePathNodeEnvironment() throws IOException { Settings build = Settings.builder() .put(buildEnvSettings(Settings.EMPTY)) - .putList(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) + .put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath().toString()) .build(); return new NodeEnvironment(build, TestEnvironment.newEnvironment(build)); } diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java index 47da7fe96d668..cf5483e95c295 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/full/PersistentCacheTests.java @@ -210,7 +210,7 @@ public void testFSyncDoesNotAddDocumentsBackInPersistentCacheWhenShardIsEvicted( nodeEnvironment = newNodeEnvironment( Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tmpPaths()) + .put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath()) .build() ); diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java index 4caa8fc38d870..7c60fe3d47647 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/cache/shared/FrozenCacheServiceTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.env.Environment; import org.elasticsearch.common.unit.RatioValue; import org.elasticsearch.common.unit.RelativeByteSizeValue; import org.elasticsearch.common.util.set.Sets; @@ -27,7 +26,6 @@ import org.elasticsearch.xpack.searchablesnapshots.cache.shared.FrozenCacheService.CacheFileRegion; import java.io.IOException; -import java.util.List; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -232,30 +230,6 @@ public void testCacheSizeRejectedOnNonFrozenNodes() { ); } - public void testMultipleDataPathsRejectedOnFrozenNodes() { - final Settings settings = Settings.builder() - .put(FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey(), new ByteSizeValue(size(500)).getStringRep()) - .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE.roleName()) - .putList(Environment.PATH_DATA_SETTING.getKey(), List.of("a", "b")) - .build(); - final IllegalArgumentException e = expectThrows( - IllegalArgumentException.class, - () -> FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.get(settings) - ); - assertThat(e.getCause(), notNullValue()); - assertThat(e.getCause(), instanceOf(SettingsException.class)); - assertThat( - e.getCause().getMessage(), - is( - "setting [" - + FrozenCacheService.SNAPSHOT_CACHE_SIZE_SETTING.getKey() - + "=" - + new ByteSizeValue(size(500)).getStringRep() - + "] is not permitted on nodes with multiple data paths [a,b]" - ) - ); - } - public void testDedicateFrozenCacheSizeDefaults() { final Settings settings = Settings.builder() .putList(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE.roleName()) diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java index f00b5656dd08d..661ada1d24895 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/xpack/searchablesnapshots/store/SearchableSnapshotDirectoryTests.java @@ -584,7 +584,7 @@ private void testDirectories( Settings.builder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath()) .put(Environment.PATH_REPO_SETTING.getKey(), repositoryPath.toAbsolutePath()) - .putList(Environment.PATH_DATA_SETTING.getKey(), tmpPaths()) + .put(Environment.PATH_DATA_SETTING.getKey(), createTempDir().toAbsolutePath()) .build(), null ),