Move ensureAtomicMoveSupported to NodeEnvironment (#36975)

Atomic move support is needed not only for GatewayMetaState to work correctly
This commit is contained in:
Andrey Ershov 2018-12-27 22:18:47 +01:00 committed by GitHub
parent 6aae7c8516
commit 6259ccb1cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 15 deletions

View File

@ -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");

View File

@ -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();
}

View File

@ -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);