Adapt TranslogTests.testWithRandomException to checkpoint syncing on trim
changed the translog dynamic to fsync the checkpoint before trimming a file. This changed the dynamics of potential failure modes which requires a change to testWithRandomException - it's now possible that we had an exception but the translog was trimmed.
Closes
@@ -107,6 +107,7 @@ import java.util.stream.LongStream;
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomLongBetween;
import static org.elasticsearch.common.util.BigArrays.NON_RECYCLING_INSTANCE;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -2065,7 +2066,6 @@ public class TranslogTests extends ESTestCase {
* that we can, after we hit an exception, open and recover the translog successfully and retrieve all successfully synced operations
* from the transaction log.
*/
- @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/25133")
public void testWithRandomException() throws IOException {
final int runs = randomIntBetween(5, 10);
for (int run = 0; run < runs; run++) {
@@ -2082,6 +2082,7 @@ public class TranslogTests extends ESTestCase {
}
String generationUUID = null;
try {
+ boolean committing = false;
final Translog failableTLog = getFailableTranslog(fail, config, randomBoolean(), false, generationUUID, new TranslogDeletionPolicy());
try {
LineFileDocs lineFileDocs = new LineFileDocs(random()); //writes pretty big docs so we cross buffer boarders regularly
@@ -2098,7 +2099,11 @@ public class TranslogTests extends ESTestCase {
failableTLog.sync(); // we have to sync here first otherwise we don't know if the sync succeeded if the commit fails
syncedDocs.addAll(unsynced);
unsynced.clear();
- rollAndCommit(failableTLog);
+ failableTLog.rollGeneration();
+ committing = true;
+ failableTLog.getDeletionPolicy().setMinTranslogGenerationForRecovery(failableTLog.currentFileGeneration());
+ failableTLog.trimUnreferencedReaders();
+ committing = false;
syncedDocs.clear();
}
}
@@ -2118,6 +2123,11 @@ public class TranslogTests extends ESTestCase {
syncedDocs.addAll(unsynced); // failed in fsync but got fully written
unsynced.clear();
}
+ if (committing && checkpoint.minTranslogGeneration == checkpoint.generation) {
+ // we were committing and blew up in one of the syncs, but they made it through
+ syncedDocs.clear();
+ assertThat(unsynced, empty());
+ }
generationUUID = failableTLog.getTranslogUUID();
minGenForRecovery = failableTLog.getDeletionPolicy().getMinTranslogGenerationForRecovery();
IOUtils.closeWhileHandlingException(failableTLog);
