Skip to content

Commit fb32a55

Browse files
committed
Deprecate synced flush (#50835)
A normal flush has the same effect as a synced flush on Elasticsearch 7.6 or later. It's deprecated in 7.6 and will be removed in 8.0. Relates #50776
1 parent a18736b commit fb32a55

File tree

13 files changed

+79
-73
lines changed

13 files changed

+79
-73
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

+6
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,10 @@ public Cancellable flushAsync(FlushRequest flushRequest, RequestOptions options,
601601
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
602602
* @return the response
603603
* @throws IOException in case there is a problem sending the request or parsing back the response
604+
* @deprecated synced flush is deprecated and will be removed in 8.0.
605+
* Use {@link #flush(FlushRequest, RequestOptions)} instead.
604606
*/
607+
@Deprecated
605608
public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, RequestOptions options) throws IOException {
606609
return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, IndicesRequestConverters::flushSynced, options,
607610
SyncedFlushResponse::fromXContent, emptySet());
@@ -615,7 +618,10 @@ public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, Re
615618
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
616619
* @param listener the listener to be notified upon request completion
617620
* @return cancellable that may be used to cancel the request
621+
* @deprecated synced flush is deprecated and will be removed in 8.0.
622+
* Use {@link #flushAsync(FlushRequest, RequestOptions, ActionListener)} instead.
618623
*/
624+
@Deprecated
619625
public Cancellable flushSyncedAsync(SyncedFlushRequest syncedFlushRequest, RequestOptions options,
620626
ActionListener<SyncedFlushResponse> listener) {
621627
return restHighLevelClient.performRequestAsyncAndParseEntity(syncedFlushRequest, IndicesRequestConverters::flushSynced, options,

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import org.elasticsearch.index.mapper.MapperService;
101101
import org.elasticsearch.index.query.QueryBuilder;
102102
import org.elasticsearch.index.query.QueryBuilders;
103+
import org.elasticsearch.indices.flush.SyncedFlushService;
103104
import org.elasticsearch.rest.RestStatus;
104105
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction;
105106
import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction;
@@ -982,7 +983,8 @@ public void testSyncedFlush() throws IOException {
982983
createIndex(index, settings);
983984
SyncedFlushRequest syncedFlushRequest = new SyncedFlushRequest(index);
984985
SyncedFlushResponse flushResponse =
985-
execute(syncedFlushRequest, highLevelClient().indices()::flushSynced, highLevelClient().indices()::flushSyncedAsync);
986+
execute(syncedFlushRequest, highLevelClient().indices()::flushSynced, highLevelClient().indices()::flushSyncedAsync,
987+
expectWarnings(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE));
986988
assertThat(flushResponse.totalShards(), equalTo(1));
987989
assertThat(flushResponse.successfulShards(), equalTo(1));
988990
assertThat(flushResponse.failedShards(), equalTo(0));
@@ -997,7 +999,8 @@ public void testSyncedFlush() throws IOException {
997999
execute(
9981000
syncedFlushRequest,
9991001
highLevelClient().indices()::flushSynced,
1000-
highLevelClient().indices()::flushSyncedAsync
1002+
highLevelClient().indices()::flushSyncedAsync,
1003+
expectWarnings(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE)
10011004
)
10021005
);
10031006
assertEquals(RestStatus.NOT_FOUND, exception.status());

client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ public void testApiNamingConventions() throws Exception {
839839
// looking like it doesn't have a valid implementatation when it does.
840840
apiUnsupported.remove("indices.get_template");
841841

842-
842+
// Synced flush is deprecated
843+
apiUnsupported.remove("indices.flush_synced");
843844

844845
for (Map.Entry<String, Set<Method>> entry : methods.entrySet()) {
845846
String apiName = entry.getKey();

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,9 @@ public void testSyncedFlushIndex() throws Exception {
10191019
// end::flush-synced-request-indicesOptions
10201020

10211021
// tag::flush-synced-execute
1022-
SyncedFlushResponse flushSyncedResponse = client.indices().flushSynced(request, RequestOptions.DEFAULT);
1022+
SyncedFlushResponse flushSyncedResponse = client.indices().flushSynced(request, expectWarnings(
1023+
"Synced flush is deprecated and will be removed in 8.0. Use flush at _/flush or /{index}/_flush instead."
1024+
));
10231025
// end::flush-synced-execute
10241026

10251027
// tag::flush-synced-response
@@ -1063,7 +1065,9 @@ public void onFailure(Exception e) {
10631065
listener = new LatchedActionListener<>(listener, latch);
10641066

10651067
// tag::flush-synced-execute-async
1066-
client.indices().flushSyncedAsync(request, RequestOptions.DEFAULT, listener); // <1>
1068+
client.indices().flushSyncedAsync(request, expectWarnings(
1069+
"Synced flush is deprecated and will be removed in 8.0. Use flush at _/flush or /{index}/_flush instead."
1070+
), listener); // <1>
10671071
// end::flush-synced-execute-async
10681072

10691073
assertTrue(latch.await(30L, TimeUnit.SECONDS));

docs/reference/indices/synced-flush.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<titleabbrev>Synced flush</titleabbrev>
55
++++
66

7+
deprecated::[7.6, synced-flush is deprecated and will be removed in 8.0.
8+
Use <<indices-flush,flush>> instead. A <<indices-flush,flush>> has the
9+
same effect as a synced flush on Elasticsearch 7.6 or later]
10+
711
Performs a synced flush on one or more indices.
812

913
[source,console]

docs/reference/upgrade/synced-flush.asciidoc

+4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
--------------------------------------------------
44
POST _flush/synced
55
--------------------------------------------------
6+
// TEST[skip: will fail as synced flush is deprecated]
67

78
When you perform a synced flush, check the response to make sure there are
89
no failures. Synced flush operations that fail due to pending indexing
910
operations are listed in the response body, although the request itself
1011
still returns a 200 OK status. If there are failures, reissue the request.
12+
13+
Note that synced flush is deprecated and will be removed in 8.0. A flush
14+
has the same effect as a synced flush on Elasticsearch 7.6 or later.

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public void testRecovery() throws Exception {
745745
// We had a bug before where we failed to perform peer recovery with sync_id from 5.x to 6.x.
746746
// We added this synced flush so we can exercise different paths of recovery code.
747747
try {
748-
client().performRequest(new Request("POST", index + "/_flush/synced"));
748+
performSyncedFlush(index);
749749
} catch (ResponseException ignored) {
750750
// synced flush is optional here
751751
}

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ private void syncedFlush(String index) throws Exception {
591591
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
592592
assertBusy(() -> {
593593
try {
594-
Response resp = client().performRequest(new Request("POST", index + "/_flush/synced"));
594+
Response resp = performSyncedFlush(index);
595595
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
596596
assertThat(result.get("failed"), equalTo(0));
597597
} catch (ResponseException ex) {

rest-api-spec/src/main/resources/rest-api-spec/api/indices.flush_synced.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"indices.flush_synced":{
33
"documentation":{
44
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush-api.html",
5-
"description":"Performs a synced flush operation on one or more indices."
5+
"description":"Performs a synced flush operation on one or more indices. Synced flush is deprecated and will be removed in 8.0. Use flush instead"
66
},
77
"stability":"stable",
88
"url":{

rest-api-spec/src/main/resources/rest-api-spec/test/cat.shards/10_basic.yml

-48
Original file line numberDiff line numberDiff line change
@@ -88,54 +88,6 @@
8888
- match:
8989
$body: |
9090
/^$/
91-
92-
- do:
93-
indices.create:
94-
index: sync_id_test
95-
body:
96-
settings:
97-
number_of_shards: 5
98-
number_of_replicas: 0
99-
100-
- do:
101-
indices.flush_synced:
102-
index: sync_id_test
103-
104-
- is_false: _shards.failed
105-
106-
- do:
107-
cat.shards:
108-
index: sync_id_test
109-
h: index,state,sync_id
110-
# 20 chars for sync ids with 5.x which uses time-based uuids and 22 with 6.x which uses random uuids
111-
- match:
112-
$body: |
113-
/^(sync_id_test\s+STARTED\s+[A-Za-z0-9_\-]{20,22}\n){5}$/
114-
115-
- do:
116-
indices.delete:
117-
index: sync_id_test
118-
119-
- do:
120-
indices.create:
121-
index: sync_id_no_flush_test
122-
body:
123-
settings:
124-
number_of_shards: 5
125-
number_of_replicas: 0
126-
127-
- do:
128-
cat.shards:
129-
index: sync_id_no_flush_test
130-
h: index,state,sync_id
131-
- match:
132-
$body: |
133-
/^(sync_id_no_flush_test\s+STARTED\s+\n){5}$/
134-
135-
- do:
136-
indices.delete:
137-
index: sync_id_no_flush_test
138-
13991
- do:
14092
indices.create:
14193
index: index1

rest-api-spec/src/main/resources/rest-api-spec/test/indices.flush/10_basic.yml

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
---
22
"Index synced flush rest test":
3-
- do:
4-
indices.create:
5-
index: testing
6-
body:
7-
settings:
8-
index:
9-
number_of_replicas: 0
3+
- skip:
4+
version: " - 7.5.99"
5+
reason: "synced flush is deprecated in 7.6"
6+
features: "warnings"
7+
- do:
8+
indices.create:
9+
index: testing
10+
body:
11+
settings:
12+
index:
13+
number_of_replicas: 0
1014

11-
- do:
12-
cluster.health:
13-
wait_for_status: green
14-
- do:
15-
indices.flush_synced:
16-
index: testing
15+
- do:
16+
cluster.health:
17+
wait_for_status: green
18+
- do:
19+
warnings:
20+
- Synced flush is deprecated and will be removed in 8.0. Use flush at _/flush or /{index}/_flush instead.
21+
indices.flush_synced:
22+
index: testing
1723

18-
- is_false: _shards.failed
24+
- is_false: _shards.failed
1925

20-
- do:
21-
indices.stats: {level: shards}
26+
- do:
27+
indices.stats: {level: shards}
2228

23-
- is_true: indices.testing.shards.0.0.commit.user_data.sync_id
29+
- is_true: indices.testing.shards.0.0.commit.user_data.sync_id
2430

2531
---
2632
"Flush stats":

server/src/main/java/org/elasticsearch/indices/flush/SyncedFlushService.java

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.elasticsearch.common.inject.Inject;
4242
import org.elasticsearch.common.io.stream.StreamInput;
4343
import org.elasticsearch.common.io.stream.StreamOutput;
44+
import org.elasticsearch.common.logging.DeprecationLogger;
4445
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
4546
import org.elasticsearch.common.util.concurrent.CountDown;
4647
import org.elasticsearch.index.Index;
@@ -71,11 +72,17 @@
7172
import java.util.List;
7273
import java.util.Map;
7374
import java.util.concurrent.ConcurrentMap;
75+
import java.util.stream.StreamSupport;
7476

7577
public class SyncedFlushService implements IndexEventListener {
7678

7779
private static final Logger logger = LogManager.getLogger(SyncedFlushService.class);
7880

81+
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(logger);
82+
83+
public static final String SYNCED_FLUSH_DEPRECATION_MESSAGE =
84+
"Synced flush is deprecated and will be removed in 8.0. Use flush at _/flush or /{index}/_flush instead.";
85+
7986
private static final String PRE_SYNCED_FLUSH_ACTION_NAME = "internal:indices/flush/synced/pre";
8087
private static final String SYNCED_FLUSH_ACTION_NAME = "internal:indices/flush/synced/sync";
8188
private static final String IN_FLIGHT_OPS_ACTION_NAME = "internal:indices/flush/synced/in_flight";
@@ -130,6 +137,9 @@ public void attemptSyncedFlush(final String[] aliasesOrIndices,
130137
IndicesOptions indicesOptions,
131138
final ActionListener<SyncedFlushResponse> listener) {
132139
final ClusterState state = clusterService.state();
140+
if (StreamSupport.stream(state.nodes().spliterator(), false).allMatch(n -> n.getVersion().onOrAfter(Version.V_7_6_0))) {
141+
DEPRECATION_LOGGER.deprecatedAndMaybeLog("synced_flush", SYNCED_FLUSH_DEPRECATION_MESSAGE);
142+
}
133143
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices);
134144
final Map<String, List<ShardsSyncedFlushResult>> results = ConcurrentCollections.newConcurrentMap();
135145
int numberOfShards = 0;

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

+16
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.elasticsearch.core.internal.io.IOUtils;
5555
import org.elasticsearch.index.IndexSettings;
5656
import org.elasticsearch.index.seqno.ReplicationTracker;
57+
import org.elasticsearch.indices.flush.SyncedFlushService;
5758
import org.elasticsearch.rest.RestStatus;
5859
import org.elasticsearch.snapshots.SnapshotState;
5960
import org.elasticsearch.test.ESTestCase;
@@ -1222,4 +1223,19 @@ protected static Version minimumNodeVersion() throws IOException {
12221223
assertNotNull(minVersion);
12231224
return minVersion;
12241225
}
1226+
1227+
protected static Response performSyncedFlush(String indexName) throws IOException {
1228+
final Request request = new Request("POST", indexName + "/_flush/synced");
1229+
final List<String> expectedWarnings = Collections.singletonList(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE);
1230+
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_6_0))) {
1231+
final Builder options = RequestOptions.DEFAULT.toBuilder();
1232+
options.setWarningsHandler(warnings -> warnings.equals(expectedWarnings) == false);
1233+
request.setOptions(options);
1234+
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(Version.V_7_6_0))) {
1235+
final Builder options = RequestOptions.DEFAULT.toBuilder();
1236+
options.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false);
1237+
request.setOptions(options);
1238+
}
1239+
return client().performRequest(request);
1240+
}
12251241
}

0 commit comments

Comments
 (0)