Skip to content

Commit b35377d

Browse files
original-brownbearDaveCTurner
authored andcommitted
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
1 parent a68d2ee commit b35377d

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
package org.elasticsearch.env;
2121

22+
import java.io.UncheckedIOException;
23+
import java.util.Iterator;
24+
import java.util.stream.Collectors;
25+
import java.util.stream.Stream;
2226
import org.apache.logging.log4j.Logger;
2327
import org.apache.logging.log4j.message.ParameterizedMessage;
2428
import org.apache.lucene.index.IndexWriter;
@@ -460,12 +464,27 @@ public void deleteShardDirectoryUnderLock(ShardLock lock, IndexSettings indexSet
460464
}
461465

462466
private static boolean assertPathsDoNotExist(final Path[] paths) {
463-
Set<Path> existingPaths = new HashSet<>();
464-
for (Path path : paths) {
465-
if (FileSystemUtils.exists(paths)) {
466-
existingPaths.add(path);
467-
}
468-
}
467+
Set<Path> existingPaths = Stream.of(paths)
468+
.filter(FileSystemUtils::exists)
469+
.filter(leftOver -> {
470+
// Relaxed assertion for the special case where only the empty state directory exists after deleting
471+
// the shard directory because it was created again as a result of a metadata read action concurrently.
472+
try (DirectoryStream<Path> children = Files.newDirectoryStream(leftOver)) {
473+
Iterator<Path> iter = children.iterator();
474+
if (iter.hasNext() == false) {
475+
return true;
476+
}
477+
Path maybeState = iter.next();
478+
if (iter.hasNext() || maybeState.equals(leftOver.resolve(MetaDataStateFormat.STATE_DIR_NAME)) == false) {
479+
return true;
480+
}
481+
try (DirectoryStream<Path> stateChildren = Files.newDirectoryStream(maybeState)) {
482+
return stateChildren.iterator().hasNext();
483+
}
484+
} catch (IOException e) {
485+
throw new UncheckedIOException(e);
486+
}
487+
}).collect(Collectors.toSet());
469488
assert existingPaths.size() == 0 : "Paths exist that should have been deleted: " + existingPaths;
470489
return existingPaths.size() == 0;
471490
}

server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ public void testReplicaRecovery() throws Exception {
241241
validateIndexRecoveryState(nodeBRecoveryState.getIndex());
242242
}
243243

244-
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/32686")
245244
@TestLogging(
246245
"_root:DEBUG,"
247246
+ "org.elasticsearch.cluster.service:TRACE,"

0 commit comments

Comments
 (0)