From 43f8b0bcdbd9a414e9a979c4db3504305457fffc Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 21 Aug 2019 12:47:35 -0400 Subject: [PATCH 1/3] Do not check translog stats if durability is async --- .../indices/state/OpenCloseIndexIT.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java index 9477978a04d48..195262c9df8fb 100644 --- a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java +++ b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java @@ -37,6 +37,7 @@ import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.translog.Translog; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESIntegTestCase; @@ -352,14 +353,14 @@ public void testOpenCloseIndexWithBlocks() { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45801") public void testTranslogStats() { final String indexName = "test"; createIndex(indexName, Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .build()); - boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get( - client().admin().indices().prepareGetSettings(indexName).get().getIndexToSettings().get(indexName)); + Settings indexSettings = client().admin().indices().prepareGetSettings(indexName).get().getIndexToSettings().get(indexName); + boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexSettings); + Translog.Durability translogDurability = IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.get(indexSettings); final int nbDocs = randomIntBetween(0, 50); int uncommittedOps = 0; @@ -377,8 +378,13 @@ public void testTranslogStats() { IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get(); assertThat(stats.getIndex(indexName), notNullValue()); - assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo( - softDeletesEnabled ? uncommittedOps : nbDocs)); + // 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. We can't check for translog stats in this case. + if (translogDurability != Translog.Durability.ASYNC || softDeletesEnabled == false) { + assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), + equalTo(softDeletesEnabled ? uncommittedOps : nbDocs)); + } assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedOps)); assertAcked(client().admin().indices().prepareClose("test")); From 690a61858a1891459630b20b513f90a63b441fff Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 21 Aug 2019 13:58:02 -0400 Subject: [PATCH 2/3] Revert "Do not check translog stats if durability is async" This reverts commit 43f8b0bcdbd9a414e9a979c4db3504305457fffc. --- .../indices/state/OpenCloseIndexIT.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java index 195262c9df8fb..9477978a04d48 100644 --- a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java +++ b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java @@ -37,7 +37,6 @@ import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.index.translog.Translog; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESIntegTestCase; @@ -353,14 +352,14 @@ public void testOpenCloseIndexWithBlocks() { } } + @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45801") public void testTranslogStats() { final String indexName = "test"; createIndex(indexName, Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .build()); - Settings indexSettings = client().admin().indices().prepareGetSettings(indexName).get().getIndexToSettings().get(indexName); - boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexSettings); - Translog.Durability translogDurability = IndexSettings.INDEX_TRANSLOG_DURABILITY_SETTING.get(indexSettings); + boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get( + client().admin().indices().prepareGetSettings(indexName).get().getIndexToSettings().get(indexName)); final int nbDocs = randomIntBetween(0, 50); int uncommittedOps = 0; @@ -378,13 +377,8 @@ public void testTranslogStats() { IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get(); assertThat(stats.getIndex(indexName), notNullValue()); - // 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. We can't check for translog stats in this case. - if (translogDurability != Translog.Durability.ASYNC || softDeletesEnabled == false) { - assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), - equalTo(softDeletesEnabled ? uncommittedOps : nbDocs)); - } + assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo( + softDeletesEnabled ? uncommittedOps : nbDocs)); assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedOps)); assertAcked(client().admin().indices().prepareClose("test")); From 2a63de94e4eeb662c71a3b23c1276d8828bff5f4 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Wed, 21 Aug 2019 13:59:33 -0400 Subject: [PATCH 3/3] await busy --- .../indices/state/OpenCloseIndexIT.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java index 9477978a04d48..27a597f63906b 100644 --- a/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java +++ b/server/src/test/java/org/elasticsearch/indices/state/OpenCloseIndexIT.java @@ -352,8 +352,7 @@ public void testOpenCloseIndexWithBlocks() { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/45801") - public void testTranslogStats() { + public void testTranslogStats() throws Exception { final String indexName = "test"; createIndex(indexName, Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) @@ -375,16 +374,20 @@ public void testTranslogStats() { } } - IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get(); - assertThat(stats.getIndex(indexName), notNullValue()); - assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo( - softDeletesEnabled ? uncommittedOps : nbDocs)); - assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedOps)); + final int uncommittedTranslogOps = uncommittedOps; + assertBusy(() -> { + IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).clear().setTranslog(true).get(); + assertThat(stats.getIndex(indexName), notNullValue()); + assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo( + softDeletesEnabled ? uncommittedTranslogOps : nbDocs)); + assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().getUncommittedOperations(), equalTo(uncommittedTranslogOps)); + }); assertAcked(client().admin().indices().prepareClose("test")); IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN; - stats = client().admin().indices().prepareStats(indexName).setIndicesOptions(indicesOptions).clear().setTranslog(true).get(); + IndicesStatsResponse stats = client().admin().indices().prepareStats(indexName).setIndicesOptions(indicesOptions) + .clear().setTranslog(true).get(); assertThat(stats.getIndex(indexName), notNullValue()); assertThat(stats.getIndex(indexName).getPrimaries().getTranslog().estimatedNumberOfOperations(), equalTo(softDeletesEnabled ? 0 : nbDocs));