Skip to content

Commit 6e9f490

Browse files
committed
elastic#27073: Dangling indices living in non-data nodes are detected and auto-imported. Some test cases are failing. Need to check further.
1 parent 0519fa2 commit 6e9f490

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

core/src/main/java/org/elasticsearch/env/NodeEnvironment.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ public NodeEnvironment(Settings settings, Environment environment) throws IOExce
249249
this.nodeLockId = nodeLockId;
250250
this.locks = locks;
251251
this.nodePaths = nodePaths;
252-
252+
if(!DiscoveryNode.isDataNode(settings) && !availableIndexFolders().isEmpty()) {
253+
throw new IllegalStateException("Non Data node cannot have dangling indices");
254+
}
253255
if (logger.isDebugEnabled()) {
254256
logger.debug("using node location [{}], local_lock_id [{}]", nodePaths, nodeLockId);
255257
}

core/src/test/java/org/elasticsearch/env/NodeEnvironmentTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.index.Index;
3131
import org.elasticsearch.index.IndexSettings;
3232
import org.elasticsearch.index.shard.ShardId;
33+
import org.elasticsearch.node.Node;
3334
import org.elasticsearch.test.ESTestCase;
3435
import org.elasticsearch.test.IndexSettingsModule;
3536

@@ -450,6 +451,32 @@ public void testExistingTempFiles() throws IOException {
450451
}
451452
}
452453

454+
public void testIfNodeEnvironmentInitiationFails() throws IOException {
455+
// simulate some previous left over temp files
456+
Settings settings = buildEnvSettings(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());
457+
458+
List<String> dataPaths = Environment.PATH_DATA_SETTING.get(settings);
459+
460+
461+
final Path nodePath = NodeEnvironment.resolveNodePath(PathUtils.get(dataPaths.get(0)), 0);
462+
final Path indicesPath = nodePath.resolve(NodeEnvironment.INDICES_FOLDER);
463+
464+
Files.createDirectories(indicesPath.resolve("index-uuid"));
465+
try {
466+
467+
NodeEnvironment env = new NodeEnvironment(settings, TestEnvironment.newEnvironment(settings));
468+
Path nodepatt = env.nodePaths()[0].indicesPath;
469+
env.close();
470+
fail("Node environment instantiation should have failed for non data node" + nodepatt + " " + indicesPath +
471+
env.availableIndexFolders());
472+
} catch (IllegalStateException e) {
473+
// that's OK :)
474+
}
475+
476+
for (String path: dataPaths) {
477+
Files.deleteIfExists(indicesPath.resolve("index-uuid"));
478+
}
479+
}
453480
/** Converts an array of Strings to an array of Paths, adding an additional child if specified */
454481
private Path[] stringsToPaths(String[] strings, String additional) {
455482
Path[] locations = new Path[strings.length];

0 commit comments

Comments
 (0)