Skip to content

#27073: Dangling indices living in non-data nodes are detected and auto-imported. #27811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
this.nodeLockId = nodeLockId;
this.locks = locks;
this.nodePaths = nodePaths;

if(!DiscoveryNode.isDataNode(settings) && !availableIndexFolders().isEmpty()) {
throw new IllegalStateException("Non Data node cannot have dangling indices");
}
if (logger.isDebugEnabled()) {
logger.debug("using node location [{}], local_lock_id [{}]", nodePaths, nodeLockId);
}
Expand Down
27 changes: 27 additions & 0 deletions core/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.node.Node;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.IndexSettingsModule;

Expand Down Expand Up @@ -450,6 +451,32 @@ public void testExistingTempFiles() throws IOException {
}
}

public void testIfNodeEnvironmentInitiationFails() throws IOException {
// simulate some previous left over temp files
Settings settings = buildEnvSettings(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());

List<String> dataPaths = Environment.PATH_DATA_SETTING.get(settings);


final Path nodePath = NodeEnvironment.resolveNodePath(PathUtils.get(dataPaths.get(0)), 0);
final Path indicesPath = nodePath.resolve(NodeEnvironment.INDICES_FOLDER);

Files.createDirectories(indicesPath.resolve("index-uuid"));
try {

NodeEnvironment env = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings));
Path nodepatt = env.nodePaths()[0].indicesPath;
env.close();
fail("Node environment instantiation should have failed for non data node" + nodepatt + " " + indicesPath +
env.availableIndexFolders());
} catch (IllegalStateException e) {
// that's OK :)
}

for (String path: dataPaths) {
Files.deleteIfExists(indicesPath.resolve("index-uuid"));
}
}
/** Converts an array of Strings to an array of Paths, adding an additional child if specified */
private Path[] stringsToPaths(String[] strings, String additional) {
Path[] locations = new Path[strings.length];
Expand Down