Skip to content

Commit

Permalink
Fixing unreferenced file cleanup flaky tests (opensearch-project#10801)
Browse files Browse the repository at this point in the history
Signed-off-by: RS146BIJAY <[email protected]>
  • Loading branch information
RS146BIJAY authored Oct 27, 2023
1 parent 0c9fc21 commit e9affea
Showing 1 changed file with 4 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.filter.RegexFilter;
import org.apache.lucene.codecs.LiveDocsFormat;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.KeywordField;
import org.apache.lucene.document.LongPoint;
Expand Down Expand Up @@ -3237,22 +3236,10 @@ public void testUnreferencedFileCleanUpOnSegmentMergeFailureWithCleanUpEnabled()
MockDirectoryWrapper wrapper = newMockDirectory();
final CountDownLatch cleanupCompleted = new CountDownLatch(1);
MockDirectoryWrapper.Failure fail = new MockDirectoryWrapper.Failure() {
public boolean didFail1;
public boolean didFail2;

@Override
public void eval(MockDirectoryWrapper dir) throws IOException {
if (!doFail) {
return;
}

// Fail segment merge with diskfull during merging terms.
if (callStackContainsAnyOf("mergeTerms") && !didFail1) {
didFail1 = true;
throw new IOException("No space left on device");
}
if (callStackContains(LiveDocsFormat.class, "writeLiveDocs") && !didFail2) {
didFail2 = true;
// Fail segment merge with diskfull during merging terms
if (callStackContainsAnyOf("mergeTerms")) {
throw new IOException("No space left on device");
}
}
Expand Down Expand Up @@ -3325,7 +3312,6 @@ public void onFailedEngine(String reason, Exception e) {
segments = engine.segments(false);
assertThat(segments.size(), equalTo(2));

fail.setDoFail();
// IndexWriter can throw either IOException or IllegalStateException depending on whether tragedy is set or not.
expectThrowsAnyOf(
Arrays.asList(IOException.class, IllegalStateException.class),
Expand All @@ -3345,20 +3331,10 @@ public void testUnreferencedFileCleanUpOnSegmentMergeFailureWithCleanUpDisabled(
MockDirectoryWrapper wrapper = newMockDirectory();
final CountDownLatch cleanupCompleted = new CountDownLatch(1);
MockDirectoryWrapper.Failure fail = new MockDirectoryWrapper.Failure() {
public boolean didFail1;
public boolean didFail2;

@Override
public void eval(MockDirectoryWrapper dir) throws IOException {
if (!doFail) {
return;
}
if (callStackContainsAnyOf("mergeTerms") && !didFail1) {
didFail1 = true;
throw new IOException("No space left on device");
}
if (callStackContains(LiveDocsFormat.class, "writeLiveDocs") && !didFail2) {
didFail2 = true;
if (callStackContainsAnyOf("mergeTerms")) {
throw new IOException("No space left on device");
}
}
Expand Down Expand Up @@ -3439,7 +3415,6 @@ public void onFailedEngine(String reason, Exception e) {
segments = engine.segments(false);
assertThat(segments.size(), equalTo(2));

fail.setDoFail();
// IndexWriter can throw either IOException or IllegalStateException depending on whether tragedy is set or not.
expectThrowsAnyOf(
Arrays.asList(IOException.class, IllegalStateException.class),
Expand All @@ -3459,20 +3434,10 @@ public void testUnreferencedFileCleanUpFailsOnSegmentMergeFailureWhenDirectoryCl
MockDirectoryWrapper wrapper = newMockDirectory();
final CountDownLatch cleanupCompleted = new CountDownLatch(1);
MockDirectoryWrapper.Failure fail = new MockDirectoryWrapper.Failure() {
public boolean didFail1;
public boolean didFail2;

@Override
public void eval(MockDirectoryWrapper dir) throws IOException {
if (!doFail) {
return;
}
if (callStackContainsAnyOf("mergeTerms") && !didFail1) {
didFail1 = true;
throw new IOException("No space left on device");
}
if (callStackContains(LiveDocsFormat.class, "writeLiveDocs") && !didFail2) {
didFail2 = true;
if (callStackContainsAnyOf("mergeTerms")) {
throw new IOException("No space left on device");
}
}
Expand Down Expand Up @@ -3537,7 +3502,6 @@ public void onFailedEngine(String reason, Exception e) {
segments = engine.segments(false);
assertThat(segments.size(), equalTo(2));

fail.setDoFail();
// Close the store so that unreferenced file cleanup will fail.
store.close();

Expand Down

0 comments on commit e9affea

Please sign in to comment.