From ecbe85e8fb89b10cb19efe25e3a93233b3ae5717 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Thu, 27 Sep 2018 19:21:03 +0200 Subject: [PATCH] TESTS: Relax Assertion About Deleting Shard Dir * Allow empty state directory to prevent test from failing * Closes #32686 --- .../elasticsearch/env/NodeEnvironment.java | 19 ++++++++++++++++++- .../indices/recovery/IndexRecoveryIT.java | 1 - 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java index cd9df98284ff2..8c10244f0c1ba 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/elasticsearch/env/NodeEnvironment.java @@ -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; @@ -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 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 children = Files.newDirectoryStream(leftOver)) { + Iterator 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 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; } diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java index 324b32fa6a940..c24ba2f8612aa 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -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,"