Skip to content

Commit 8dda827

Browse files
authored
Don't refresh on _flush _force_merge and _upgrade (#27000)
Today all these API calls have a sideeffect of making documents visible to search requests. While this is sometimes desired it's an unnecessary sideeffect and now that we have an internal (engine-private) index reader (#26972) we artificially add a refresh call for bwc. This change removes this sideeffect in 7.0.
1 parent 277637f commit 8dda827

File tree

11 files changed

+32
-30
lines changed

11 files changed

+32
-30
lines changed

core/src/main/java/org/elasticsearch/index/shard/IndexShard.java

-6
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,6 @@ public Engine.CommitId flush(FlushRequest request) {
10051005
}
10061006
final long time = System.nanoTime();
10071007
final Engine.CommitId commitId = engine.flush(force, waitIfOngoing);
1008-
engine.refresh("flush"); // TODO this is technically wrong we should remove this in 7.0
10091008
flushMetric.inc(System.nanoTime() - time);
10101009
return commitId;
10111010
}
@@ -1036,9 +1035,6 @@ public void forceMerge(ForceMergeRequest forceMerge) throws IOException {
10361035
Engine engine = getEngine();
10371036
engine.forceMerge(forceMerge.flush(), forceMerge.maxNumSegments(),
10381037
forceMerge.onlyExpungeDeletes(), false, false);
1039-
if (forceMerge.flush()) {
1040-
engine.refresh("force_merge"); // TODO this is technically wrong we should remove this in 7.0
1041-
}
10421038
}
10431039

10441040
/**
@@ -1055,8 +1051,6 @@ public org.apache.lucene.util.Version upgrade(UpgradeRequest upgrade) throws IOE
10551051
engine.forceMerge(true, // we need to flush at the end to make sure the upgrade is durable
10561052
Integer.MAX_VALUE, // we just want to upgrade the segments, not actually optimize to a single segment
10571053
false, true, upgrade.upgradeOnlyAncientSegments());
1058-
engine.refresh("upgrade"); // TODO this is technically wrong we should remove this in 7.0
1059-
10601054
org.apache.lucene.util.Version version = minimumCompatibleVersion();
10611055
if (logger.isTraceEnabled()) {
10621056
logger.trace("upgraded segments for {} from version {} to version {}", shardId, previousVersion, version);

core/src/test/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequestTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void setupIndex() {
5555
client().prepareIndex("test", "type1", id).setSource("text", "sometext").get();
5656
}
5757
client().admin().indices().prepareFlush("test").get();
58+
client().admin().indices().prepareRefresh().get();
5859
}
5960

6061
public void testBasic() {

core/src/test/java/org/elasticsearch/get/GetActionIT.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,17 @@ public void testSimpleGet() {
131131
assertThat(response.getField("field1").getValues().get(0).toString(), equalTo("value1"));
132132
assertThat(response.getField("field2"), nullValue());
133133

134-
logger.info("--> flush the index, so we load it from it");
135-
flush();
136134

137-
logger.info("--> realtime get 1 (loaded from index)");
135+
logger.info("--> realtime get 1");
138136
response = client().prepareGet(indexOrAlias(), "type1", "1").get();
139137
assertThat(response.isExists(), equalTo(true));
140138
assertThat(response.getIndex(), equalTo("test"));
141139
assertThat(response.getSourceAsMap().get("field1").toString(), equalTo("value1"));
142140
assertThat(response.getSourceAsMap().get("field2").toString(), equalTo("value2"));
143141

142+
logger.info("--> refresh the index, so we load it from it");
143+
refresh();
144+
144145
logger.info("--> non realtime get 1 (loaded from index)");
145146
response = client().prepareGet(indexOrAlias(), "type1", "1").setRealtime(false).get();
146147
assertThat(response.isExists(), equalTo(true));

core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public void testSegmentsStats() {
573573

574574
client().admin().indices().prepareFlush().get();
575575
client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet();
576+
client().admin().indices().prepareRefresh().get();
576577
stats = client().admin().indices().prepareStats().setSegments(true).get();
577578

578579
assertThat(stats.getTotal().getSegments(), notNullValue());

core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java

+4-9
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@ public void testSimpleNested() throws Exception {
8383
.endObject()).execute().actionGet();
8484

8585
waitForRelocation(ClusterHealthStatus.GREEN);
86-
// flush, so we fetch it from the index (as see that we filter nested docs)
87-
flush();
8886
GetResponse getResponse = client().prepareGet("test", "type1", "1").get();
8987
assertThat(getResponse.isExists(), equalTo(true));
9088
assertThat(getResponse.getSourceAsBytes(), notNullValue());
91-
89+
refresh();
9290
// check the numDocs
9391
assertDocumentCount("test", 3);
9492

@@ -126,8 +124,7 @@ public void testSimpleNested() throws Exception {
126124
.endArray()
127125
.endObject()).execute().actionGet();
128126
waitForRelocation(ClusterHealthStatus.GREEN);
129-
// flush, so we fetch it from the index (as see that we filter nested docs)
130-
flush();
127+
refresh();
131128
assertDocumentCount("test", 6);
132129

133130
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1",
@@ -151,8 +148,7 @@ public void testSimpleNested() throws Exception {
151148
DeleteResponse deleteResponse = client().prepareDelete("test", "type1", "2").execute().actionGet();
152149
assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
153150

154-
// flush, so we fetch it from the index (as see that we filter nested docs)
155-
flush();
151+
refresh();
156152
assertDocumentCount("test", 3);
157153

158154
searchResponse = client().prepareSearch("test").setQuery(nestedQuery("nested1", termQuery("nested1.n_field1", "n_value1_1"), ScoreMode.Avg)).execute().actionGet();
@@ -179,11 +175,10 @@ public void testMultiNested() throws Exception {
179175
.endArray()
180176
.endObject()).execute().actionGet();
181177

182-
// flush, so we fetch it from the index (as see that we filter nested docs)
183-
flush();
184178
GetResponse getResponse = client().prepareGet("test", "type1", "1").execute().actionGet();
185179
assertThat(getResponse.isExists(), equalTo(true));
186180
waitForRelocation(ClusterHealthStatus.GREEN);
181+
refresh();
187182
// check the numDocs
188183
assertDocumentCount("test", 7);
189184

core/src/test/java/org/elasticsearch/versioning/SimpleVersioningIT.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
4545
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
46+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
4647
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThrows;
4748
import static org.hamcrest.Matchers.equalTo;
4849
import static org.hamcrest.Matchers.lessThanOrEqualTo;
@@ -268,12 +269,10 @@ public void testSimpleVersioningWithFlush() throws Exception {
268269
assertThat(indexResponse.getVersion(), equalTo(1L));
269270

270271
client().admin().indices().prepareFlush().execute().actionGet();
271-
272272
indexResponse = client().prepareIndex("test", "type", "1").setSource("field1", "value1_2").setVersion(1).execute().actionGet();
273273
assertThat(indexResponse.getVersion(), equalTo(2L));
274274

275275
client().admin().indices().prepareFlush().execute().actionGet();
276-
277276
assertThrows(client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(1).execute(),
278277
VersionConflictEngineException.class);
279278

@@ -286,13 +285,16 @@ public void testSimpleVersioningWithFlush() throws Exception {
286285
assertThrows(client().prepareDelete("test", "type", "1").setVersion(1).execute(), VersionConflictEngineException.class);
287286
assertThrows(client().prepareDelete("test", "type", "1").setVersion(1).execute(), VersionConflictEngineException.class);
288287

289-
client().admin().indices().prepareRefresh().execute().actionGet();
290288
for (int i = 0; i < 10; i++) {
291289
assertThat(client().prepareGet("test", "type", "1").execute().actionGet().getVersion(), equalTo(2L));
292290
}
293291

292+
client().admin().indices().prepareRefresh().execute().actionGet();
293+
294294
for (int i = 0; i < 10; i++) {
295-
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setVersion(true).execute().actionGet();
295+
SearchResponse searchResponse = client().prepareSearch().setQuery(matchAllQuery()).setVersion(true).
296+
execute().actionGet();
297+
assertHitCount(searchResponse, 1);
296298
assertThat(searchResponse.getHits().getAt(0).getVersion(), equalTo(2L));
297299
}
298300
}

docs/reference/migration/migrate_7_0/indices.asciidoc

+9
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ index names may no longer contain `:`.
1010

1111
Negative values were interpreted as zero in earlier versions but are no
1212
longer accepted.
13+
14+
15+
==== `_flush` and `_force_merge` will no longer refresh
16+
17+
In previous versions issuing a `_flush` or `_force_merge` (with `flush=true`)
18+
had the undocumented side-effect of refreshing the index which made new documents
19+
visible to searches and non-realtime GET operations. From now on these operations
20+
don't have this side-effect anymore. To make documents visible an explicit `_refresh`
21+
call is needed unless the index is refreshed by the internal scheduler.

modules/parent-join/src/test/java/org/elasticsearch/join/query/ChildQuerySearchIT.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,9 @@ public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrCh
593593

594594
createIndexRequest("test", "parent", "1", null, "p_field", 1).get();
595595
createIndexRequest("test", "child", "2", "1", "c_field", 1).get();
596-
client().admin().indices().prepareFlush("test").get();
597596

598597
client().prepareIndex("test", legacy() ? "type1" : "doc", "3").setSource("p_field", 1).get();
599-
client().admin().indices().prepareFlush("test").get();
598+
refresh();
600599

601600
SearchResponse searchResponse = client().prepareSearch("test")
602601
.setQuery(boolQuery().must(matchAllQuery()).filter(hasChildQuery("child", matchAllQuery(), ScoreMode.None))).get();
@@ -881,8 +880,8 @@ public void testHasChildAndHasParentFilter_withFilter() throws Exception {
881880
} else {
882881
client().prepareIndex("test", "doc", "3").setSource("p_field", 2).get();
883882
}
884-
client().admin().indices().prepareFlush("test").get();
885883

884+
refresh();
886885
SearchResponse searchResponse = client().prepareSearch("test")
887886
.setQuery(boolQuery().must(matchAllQuery()).filter(hasChildQuery("child", termQuery("c_field", 1), ScoreMode.None)))
888887
.get();
@@ -911,7 +910,7 @@ public void testHasChildInnerHitsHighlighting() throws Exception {
911910

912911
createIndexRequest("test", "parent", "1", null, "p_field", 1).get();
913912
createIndexRequest("test", "child", "2", "1", "c_field", "foo bar").get();
914-
client().admin().indices().prepareFlush("test").get();
913+
refresh();
915914

916915
SearchResponse searchResponse = client().prepareSearch("test").setQuery(
917916
hasChildQuery("child", matchQuery("c_field", "foo"), ScoreMode.None)

qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/10_basic.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
body: {"f1": "v6_mixed", "f2": 10}
4141

4242
- do:
43-
indices.flush:
43+
indices.refresh:
4444
index: test_index
4545

4646
- do:
@@ -56,7 +56,7 @@
5656
id: d10
5757

5858
- do:
59-
indices.flush:
59+
indices.refresh:
6060
index: test_index
6161

6262
- do:

qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/10_basic.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
- '{"f1": "d_old"}'
4747

4848
- do:
49-
indices.flush:
49+
indices.refresh:
5050
index: test_index,index_with_replicas
5151

5252
- do:

qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/10_basic.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
- '{"f1": "v5_upgraded", "f2": 14}'
3737

3838
- do:
39-
indices.flush:
39+
indices.refresh:
4040
index: test_index
4141

4242
- do:

0 commit comments

Comments
 (0)