Skip to content

Commit ce469cf

Browse files
authored
Fix testCorruptedIndex (#38161)
Folks at the Lucene project do not seem to be interested in classifying corruptions and distinguishing them from file-system exceptions (see https://issues.apache.org/jira/browse/LUCENE-8525), so we'll just cop out as well. Closes #34322
1 parent e18cac3 commit ce469cf

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

server/src/main/java/org/elasticsearch/index/translog/TruncateTranslogAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public Tuple<RemoveCorruptedShardDataCommand.CleanStatus, String> getCleanStatus
7171
commits = DirectoryReader.listCommits(indexDirectory);
7272
} catch (IndexNotFoundException infe) {
7373
throw new ElasticsearchException("unable to find a valid shard at [" + indexPath + "]", infe);
74+
} catch (IOException e) {
75+
throw new ElasticsearchException("unable to list commits at [" + indexPath + "]", e);
7476
}
7577

7678
// Retrieve the generation and UUID from the existing data

server/src/test/java/org/elasticsearch/index/shard/RemoveCorruptedShardDataCommandTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.regex.Pattern;
5757

5858
import static org.hamcrest.Matchers.containsString;
59+
import static org.hamcrest.Matchers.either;
5960
import static org.hamcrest.Matchers.equalTo;
6061
import static org.hamcrest.Matchers.instanceOf;
6162
import static org.hamcrest.Matchers.is;
@@ -174,7 +175,7 @@ public void testCorruptedIndex() throws Exception {
174175
fail();
175176
} catch (ElasticsearchException e) {
176177
if (corruptSegments) {
177-
assertThat(e.getMessage(), is("Index is unrecoverable"));
178+
assertThat(e.getMessage(), either(is("Index is unrecoverable")).or(startsWith("unable to list commits")));
178179
} else {
179180
assertThat(e.getMessage(), containsString("aborted by user"));
180181
}

0 commit comments

Comments
 (0)