Skip to content

Commit 774273a

Browse files
committed
Don't refres on _flush _force_merge and _upgrade
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 (elastic#26972) we artificially add a refresh call for bwc. This change removes this sideeffect in 7.0.
1 parent a789583 commit 774273a

File tree

5 files changed

+10
-18
lines changed

5 files changed

+10
-18
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

0 commit comments

Comments
 (0)