TESTS: Relax Assertion About Deleting Shard Dir (#34120)

* TESTS: Relax Assertion About Deleting Shard Dir

* Allow empty state directory to prevent test from failing
* Closes #32686
This commit is contained in:
Armin Braun 2018-09-28 19:09:49 +02:00 committed by GitHub
parent 57052f617a
commit 76dd3948f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -19,6 +19,10 @@
package org.elasticsearch.env;
import java.io.UncheckedIOException;
import java.util.Iterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.message.ParameterizedMessage;
@ -486,12 +490,27 @@ public final class NodeEnvironment implements Closeable {
}
private static boolean assertPathsDoNotExist(final Path[] paths) {
Set<Path> existingPaths = new HashSet<>();
for (Path path : paths) {
if (FileSystemUtils.exists(path)) {
existingPaths.add(path);
}
}
Set<Path> existingPaths = Stream.of(paths)
.filter(FileSystemUtils::exists)
.filter(leftOver -> {
// 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.
try (DirectoryStream<Path> children = Files.newDirectoryStream(leftOver)) {
Iterator<Path> iter = children.iterator();
if (iter.hasNext() == false) {
return true;
}
Path maybeState = iter.next();
if (iter.hasNext() || maybeState.equals(leftOver.resolve(MetaDataStateFormat.STATE_DIR_NAME)) == false) {
return true;
}
try (DirectoryStream<Path> stateChildren = Files.newDirectoryStream(maybeState)) {
return stateChildren.iterator().hasNext();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).collect(Collectors.toSet());
assert existingPaths.size() == 0 : "Paths exist that should have been deleted: " + existingPaths;
return existingPaths.size() == 0;
}

View File

@ -246,7 +246,6 @@ public class IndexRecoveryIT extends ESIntegTestCase {
validateIndexRecoveryState(nodeBRecoveryState.getIndex());
}
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/32686")
@TestLogging(
"_root:DEBUG,"
+ "org.elasticsearch.cluster.service:TRACE,"