From 6259ccb1cf4e98ff6eba6b87bc77df5dad7641d0 Mon Sep 17 00:00:00 2001 From: Andrey Ershov Date: Thu, 27 Dec 2018 22:18:47 +0100 Subject: [PATCH] Move ensureAtomicMoveSupported to NodeEnvironment (#36975) Atomic move support is needed not only for GatewayMetaState to work correctly --- .../main/java/org/elasticsearch/env/NodeEnvironment.java | 7 +++++-- .../java/org/elasticsearch/gateway/GatewayMetaState.java | 7 ------- .../java/org/elasticsearch/env/NodeEnvironmentTests.java | 7 +------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index 3cc7615b8ce..2d236b08f79 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -305,6 +305,10 @@ public final class NodeEnvironment implements Closeable { applySegmentInfosTrace(settings); assertCanWrite(); + + if (DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings)) { + ensureAtomicMoveSupported(nodePaths); + } success = true; } finally { if (success == false) { @@ -1003,8 +1007,7 @@ public final class NodeEnvironment implements Closeable { * not supported by the filesystem. This test is executed on each of the data directories. * This method cleans up all files even in the case of an error. */ - public void ensureAtomicMoveSupported() throws IOException { - final NodePath[] nodePaths = nodePaths(); + private static void ensureAtomicMoveSupported(final NodePath[] nodePaths) throws IOException { for (NodePath nodePath : nodePaths) { assert Files.isDirectory(nodePath.path) : nodePath.path + " is not a directory"; final Path src = nodePath.path.resolve(TEMP_FILE_NAME + ".tmp"); diff --git a/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java b/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java index 9576d522806..d380cd93c47 100644 --- a/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java +++ b/server/src/main/java/org/elasticsearch/gateway/GatewayMetaState.java @@ -102,7 +102,6 @@ public class GatewayMetaState implements ClusterStateApplier, CoordinationState. this.clusterService = clusterService; this.indicesService = indicesService; - ensureAtomicMoveSupported(); //TODO move this check to NodeEnvironment, because it's related to all types of metadata upgradeMetaData(metaDataIndexUpgradeService, metaDataUpgrader); initializeClusterState(ClusterName.CLUSTER_NAME_SETTING.get(settings)); incrementalWrite = false; @@ -194,12 +193,6 @@ public class GatewayMetaState implements ClusterStateApplier, CoordinationState. return DiscoveryNode.isMasterNode(settings) || DiscoveryNode.isDataNode(settings); } - private void ensureAtomicMoveSupported() throws IOException { - if (isMasterOrDataNode()) { - nodeEnv.ensureAtomicMoveSupported(); - } - } - public MetaData getMetaData() { return previousClusterState.metaData(); } diff --git a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java index 63635f5cbe7..55ab02c1dcf 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java @@ -35,7 +35,6 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; import java.io.IOException; -import java.nio.file.AtomicMoveNotSupportedException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -457,12 +456,8 @@ public class NodeEnvironmentTests extends ESTestCase { } } NodeEnvironment env = newNodeEnvironment(paths, Settings.EMPTY); - try { - env.ensureAtomicMoveSupported(); - } catch (AtomicMoveNotSupportedException e) { - // that's OK :) - } env.close(); + // check we clean up for (String path: paths) { final Path nodePath = NodeEnvironment.resolveNodePath(PathUtils.get(path), 0);