Skip to content

Commit 34d6913

Browse files
authored
Assert translog stats busily (#45809)
If soft-deletes is enabled, we will trim translog above the local checkpoint of the safe commit immediately. However, if the translog durability is async, the last commit might not be the safe commit as the local checkpoint won't advance until translog is synced. Therefore, we need to verify translog stats busily. Closes #45801 Relates #45473
1 parent 5493613 commit 34d6913

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ public void testOpenCloseIndexWithBlocks() {
352352
}
353353
}
354354

355-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45801")
356-
public void testTranslogStats() {
355+
public void testTranslogStats() throws Exception {
357356
final String indexName = "test";
358357
createIndex(indexName, Settings.builder()
359358
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
@@ -375,16 +374,20 @@ public void testTranslogStats() {
375374
}
376375
}
377376

378-
IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get();
379-
assertThat(stats.getIndex(indexName), notNullValue());
380-
assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo(
381-
softDeletesEnabled ? uncommittedOps : nbDocs));
382-
assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedOps));
377+
final int uncommittedTranslogOps = uncommittedOps;
378+
assertBusy(() -> {
379+
IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get();
380+
assertThat(stats.getIndex(indexName), notNullValue());
381+
assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo(
382+
softDeletesEnabled ? uncommittedTranslogOps : nbDocs));
383+
assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedTranslogOps));
384+
});
383385

384386
assertAcked(client().admin().indices().prepareClose("test"));
385387

386388
IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN;
387-
stats = client().admin().indices().prepareStats(indexName).setIndicesOptions(indicesOptions).clear().setTranslog(true).get();
389+
IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).setIndicesOptions(indicesOptions)
390+
.clear().setTranslog(true).get();
388391
assertThat(stats.getIndex(indexName), notNullValue());
389392
assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(),
390393
equalTo(softDeletesEnabled ? 0 : nbDocs));

0 commit comments

Comments
 (0)