Skip to content

Commit

Permalink
TESTS: Relax Assertion About Deleting Shard Dir
Browse files Browse the repository at this point in the history
* Allow empty state directory to prevent test from failing
* Closes elastic#32686
  • Loading branch information
original-brownbear committed Sep 27, 2018
1 parent 37be3e7 commit ecbe85e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 18 additions & 1 deletion server/src/main/java/org/elasticsearch/env/NodeEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.env;

import java.util.Iterator;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.message.ParameterizedMessage;
Expand Down Expand Up @@ -485,13 +486,29 @@ public void deleteShardDirectoryUnderLock(ShardLock lock, IndexSettings indexSet
assert assertPathsDoNotExist(paths);
}

private static boolean assertPathsDoNotExist(final Path[] paths) {
private static boolean assertPathsDoNotExist(final Path[] paths) throws IOException {
Set<Path> existingPaths = new HashSet<>();
for (Path path : paths) {
if (FileSystemUtils.exists(path)) {
existingPaths.add(path);
}
}
// Relaxed assertion for the special case where only the empty state directory exists after deleting
// the shard directory because it was created again as a result of a metadata read action concurrently.
if (existingPaths.size() == 1) {
Path leftOver = existingPaths.iterator().next();
try (DirectoryStream<Path> children = Files.newDirectoryStream(leftOver)) {
Iterator<Path> iter = children.iterator();
assert iter.hasNext();
Path maybeState = iter.next();
assert iter.hasNext() == false;
assert maybeState.equals(leftOver.resolve(MetaDataStateFormat.STATE_DIR_NAME));
try (DirectoryStream<Path> stateChildren = Files.newDirectoryStream(maybeState)) {
assert stateChildren.iterator().hasNext() == false;
}
}
existingPaths.clear();
}
assert existingPaths.size() == 0 : "Paths exist that should have been deleted: " + existingPaths;
return existingPaths.size() == 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ public void testReplicaRecovery() throws Exception {
validateIndexRecoveryState(nodeBRecoveryState.getIndex());
}

@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/32686")
@TestLogging(
"_root:DEBUG,"
+ "org.elasticsearch.cluster.service:TRACE,"
Expand Down

0 comments on commit ecbe85e

Please sign in to comment.