Adapt TranslogTests.testWithRandomException to checkpoint syncing on trim
#25005 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 #25133
This commit is contained in:
parent
725f6b6983
commit
cfb5f6a5a6
|
@ -107,6 +107,7 @@ import java.util.stream.LongStream;
|
||||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomLongBetween;
|
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomLongBetween;
|
||||||
import static org.elasticsearch.common.util.BigArrays.NON_RECYCLING_INSTANCE;
|
import static org.elasticsearch.common.util.BigArrays.NON_RECYCLING_INSTANCE;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
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
|
* that we can, after we hit an exception, open and recover the translog successfully and retrieve all successfully synced operations
|
||||||
* from the transaction log.
|
* from the transaction log.
|
||||||
*/
|
*/
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/25133")
|
|
||||||
public void testWithRandomException() throws IOException {
|
public void testWithRandomException() throws IOException {
|
||||||
final int runs = randomIntBetween(5, 10);
|
final int runs = randomIntBetween(5, 10);
|
||||||
for (int run = 0; run < runs; run++) {
|
for (int run = 0; run < runs; run++) {
|
||||||
|
@ -2082,6 +2082,7 @@ public class TranslogTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
String generationUUID = null;
|
String generationUUID = null;
|
||||||
try {
|
try {
|
||||||
|
boolean committing = false;
|
||||||
final Translog failableTLog = getFailableTranslog(fail, config, randomBoolean(), false, generationUUID, new TranslogDeletionPolicy());
|
final Translog failableTLog = getFailableTranslog(fail, config, randomBoolean(), false, generationUUID, new TranslogDeletionPolicy());
|
||||||
try {
|
try {
|
||||||
LineFileDocs lineFileDocs = new LineFileDocs(random()); //writes pretty big docs so we cross buffer boarders regularly
|
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
|
failableTLog.sync(); // we have to sync here first otherwise we don't know if the sync succeeded if the commit fails
|
||||||
syncedDocs.addAll(unsynced);
|
syncedDocs.addAll(unsynced);
|
||||||
unsynced.clear();
|
unsynced.clear();
|
||||||
rollAndCommit(failableTLog);
|
failableTLog.rollGeneration();
|
||||||
|
committing = true;
|
||||||
|
failableTLog.getDeletionPolicy().setMinTranslogGenerationForRecovery(failableTLog.currentFileGeneration());
|
||||||
|
failableTLog.trimUnreferencedReaders();
|
||||||
|
committing = false;
|
||||||
syncedDocs.clear();
|
syncedDocs.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2118,6 +2123,11 @@ public class TranslogTests extends ESTestCase {
|
||||||
syncedDocs.addAll(unsynced); // failed in fsync but got fully written
|
syncedDocs.addAll(unsynced); // failed in fsync but got fully written
|
||||||
unsynced.clear();
|
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();
|
generationUUID = failableTLog.getTranslogUUID();
|
||||||
minGenForRecovery = failableTLog.getDeletionPolicy().getMinTranslogGenerationForRecovery();
|
minGenForRecovery = failableTLog.getDeletionPolicy().getMinTranslogGenerationForRecovery();
|
||||||
IOUtils.closeWhileHandlingException(failableTLog);
|
IOUtils.closeWhileHandlingException(failableTLog);
|
||||||
|
|
Loading…
Reference in New Issue