Skip to content

Commit fadad3c

Browse files
authored
Relax testStressMaybeFlushOrRollTranslogGeneration (#38918)
The predicate shouldPeriodicallyFlush is determined by the uncommitted translog size and the local checkpoint. The uncommitted translog size depends on the local checkpoint. The condition shouldPeriodicallyFlush can be true twice in in the test in the following scenario: 1. Index doc-0 and advances the local checkpoint to 0, the condition shouldPeriodicallyFlush remains false. 2. Index doc-1 and add it to translog, but the local checkpoint is not advanced yet (still 0). The condition shouldPeriodicallyFlush becomes true because the uncommitted translog size is 216bytes (2ops + gen-1 + gen-2) > 180bytes and the translog generation of the new index commit would advance from 1 to 2. > [2019-02-13T23:33:58,257][TRACE][o.e.i.e.Engine ] [node_s_0] > [test][0] committing writer with commit data [{local_checkpoint=0, > max_unsafe_auto_id_timestamp=-1, translog_uuid=fFp1Yqd4QiqKDD4ZrC8F-g, > min_retained_seq_no=0, history_uuid=cn31yrwVQk-Vs7qcg4bi_Q, > retention_leases=primary_term:1;version:0;, translog_generation=2, > max_seq_no=1}] 1. The shouldPeriodicallyFlush becomes true again after the local checkpoint is advanced to 1 because the uncommitted translog size is 216bytes (2ops + gen-2 + gen-3) > 180bytes and the translog generation of the new index commit would advance from 2 to 4. > [2019-02-13T23:33:58,264][TRACE][o.e.i.e.Engine ] [node_s_0] > [test][0] committing writer with commit data [{local_checkpoint=1, > max_unsafe_auto_id_timestamp=-1, translog_uuid=fFp1Yqd4QiqKDD4ZrC8F-g, > min_retained_seq_no=0, history_uuid=cn31yrwVQk-Vs7qcg4bi_Q, > retention_leases=primary_term:1;version:0;, translog_generation=4, > max_seq_no=1}] We need to relax the assertion in this test to cover this situation. Closes #31629
1 parent faa838c commit fadad3c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoSearchHits;
121121
import static org.hamcrest.Matchers.allOf;
122122
import static org.hamcrest.Matchers.containsString;
123+
import static org.hamcrest.Matchers.either;
123124
import static org.hamcrest.Matchers.equalTo;
124125
import static org.hamcrest.Matchers.greaterThan;
125126
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@ -474,18 +475,22 @@ public void testStressMaybeFlushOrRollTranslogGeneration() throws Exception {
474475
final FlushStats initialStats = shard.flushStats();
475476
client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
476477
check = () -> {
478+
assertFalse(shard.shouldPeriodicallyFlush());
477479
final FlushStats currentStats = shard.flushStats();
478480
String msg = String.format(Locale.ROOT, "flush stats: total=[%d vs %d], periodic=[%d vs %d]",
479481
initialStats.getTotal(), currentStats.getTotal(), initialStats.getPeriodic(), currentStats.getPeriodic());
480-
assertThat(msg, currentStats.getPeriodic(), equalTo(initialStats.getPeriodic() + 1));
481-
assertThat(msg, currentStats.getTotal(), equalTo(initialStats.getTotal() + 1));
482+
assertThat(msg, currentStats.getPeriodic(),
483+
either(equalTo(initialStats.getPeriodic() + 1)).or(equalTo(initialStats.getPeriodic() + 2)));
484+
assertThat(msg, currentStats.getTotal(),
485+
either(equalTo(initialStats.getTotal() + 1)).or(equalTo(initialStats.getTotal() + 2)));
482486
};
483487
} else {
484488
final long generation = getTranslog(shard).currentFileGeneration();
485489
client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
486-
check = () -> assertEquals(
487-
generation + 1,
488-
getTranslog(shard).currentFileGeneration());
490+
check = () -> {
491+
assertFalse(shard.shouldRollTranslogGeneration());
492+
assertEquals(generation + 1, getTranslog(shard).currentFileGeneration());
493+
};
489494
}
490495
assertBusy(check);
491496
running.set(false);

0 commit comments

Comments
 (0)