Skip to content

Commit 08b8450

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 36079d4 commit 08b8450

File tree

13 files changed

+76
-73
lines changed

13 files changed

+76
-73
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,10 @@ public Cancellable flushAsync(FlushRequest flushRequest, RequestOptions options,
423423
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
424424
* @return the response
425425
* @throws IOException in case there is a problem sending the request or parsing back the response
426+
* @deprecated synced flush is deprecated and will be removed in 8.0.
427+
* Use {@link #flush(FlushRequest, RequestOptions)} instead.
426428
*/
429+
@Deprecated
427430
public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, RequestOptions options) throws IOException {
428431
return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, IndicesRequestConverters::flushSynced, options,
429432
SyncedFlushResponse::fromXContent, emptySet());
@@ -437,7 +440,10 @@ public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, Re
437440
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
438441
* @param listener the listener to be notified upon request completion
439442
* @return cancellable that may be used to cancel the request
443+
* @deprecated synced flush is deprecated and will be removed in 8.0.
444+
* Use {@link #flushAsync(FlushRequest, RequestOptions, ActionListener)} instead.
440445
*/
446+
@Deprecated
441447
public Cancellable flushSyncedAsync(SyncedFlushRequest syncedFlushRequest, RequestOptions options,
442448
ActionListener<SyncedFlushResponse> listener) {
443449
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
@@ -97,6 +97,7 @@
9797
import org.elasticsearch.index.IndexSettings;
9898
import org.elasticsearch.index.query.QueryBuilder;
9999
import org.elasticsearch.index.query.QueryBuilders;
100+
import org.elasticsearch.indices.flush.SyncedFlushService;
100101
import org.elasticsearch.rest.RestStatus;
101102

102103
import java.io.IOException;
@@ -768,7 +769,8 @@ public void testSyncedFlush() throws IOException {
768769
createIndex(index, settings);
769770
SyncedFlushRequest syncedFlushRequest = new SyncedFlushRequest(index);
770771
SyncedFlushResponse flushResponse =
771-
execute(syncedFlushRequest, highLevelClient().indices()::flushSynced, highLevelClient().indices()::flushSyncedAsync);
772+
execute(syncedFlushRequest, highLevelClient().indices()::flushSynced, highLevelClient().indices()::flushSyncedAsync,
773+
expectWarnings(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE));
772774
assertThat(flushResponse.totalShards(), equalTo(1));
773775
assertThat(flushResponse.successfulShards(), equalTo(1));
774776
assertThat(flushResponse.failedShards(), equalTo(0));
@@ -783,7 +785,8 @@ public void testSyncedFlush() throws IOException {
783785
execute(
784786
syncedFlushRequest,
785787
highLevelClient().indices()::flushSynced,
786-
highLevelClient().indices()::flushSyncedAsync
788+
highLevelClient().indices()::flushSyncedAsync,
789+
expectWarnings(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE)
787790
)
788791
);
789792
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
@@ -1018,7 +1018,9 @@ public void testSyncedFlushIndex() throws Exception {
10181018
// end::flush-synced-request-indicesOptions
10191019

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

10241026
// tag::flush-synced-response
@@ -1062,7 +1064,9 @@ public void onFailure(Exception e) {
10621064
listener = new LatchedActionListener<>(listener, latch);
10631065

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

10681072
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
@@ -684,7 +684,7 @@ public void testRecovery() throws Exception {
684684
// We had a bug before where we failed to perform peer recovery with sync_id from 5.x to 6.x.
685685
// We added this synced flush so we can exercise different paths of recovery code.
686686
try {
687-
client().performRequest(new Request("POST", index + "/_flush/synced"));
687+
performSyncedFlush(index);
688688
} catch (ResponseException ignored) {
689689
// synced flush is optional here
690690
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ private void syncedFlush(String index) throws Exception {
562562
// A synced-flush request considers the global checkpoint sync as an going operation because it acquires a shard permit.
563563
assertBusy(() -> {
564564
try {
565-
Response resp = client().performRequest(new Request("POST", index + "/_flush/synced"));
565+
Response resp = performSyncedFlush(index);
566566
Map<String, Object> result = ObjectPath.createFromResponse(resp).evaluate("_shards");
567567
assertThat(result.get("failed"), equalTo(0));
568568
} 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

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.elasticsearch.common.inject.Inject;
4141
import org.elasticsearch.common.io.stream.StreamInput;
4242
import org.elasticsearch.common.io.stream.StreamOutput;
43+
import org.elasticsearch.common.logging.DeprecationLogger;
4344
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
4445
import org.elasticsearch.common.util.concurrent.CountDown;
4546
import org.elasticsearch.index.Index;
@@ -74,6 +75,11 @@ public class SyncedFlushService {
7475

7576
private static final Logger logger = LogManager.getLogger(SyncedFlushService.class);
7677

78+
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(logger);
79+
80+
public static final String SYNCED_FLUSH_DEPRECATION_MESSAGE =
81+
"Synced flush is deprecated and will be removed in 8.0. Use flush at _/flush or /{index}/_flush instead.";
82+
7783
private static final String PRE_SYNCED_FLUSH_ACTION_NAME = "internal:indices/flush/synced/pre";
7884
private static final String SYNCED_FLUSH_ACTION_NAME = "internal:indices/flush/synced/sync";
7985
private static final String IN_FLIGHT_OPS_ACTION_NAME = "internal:indices/flush/synced/in_flight";
@@ -109,6 +115,7 @@ public void attemptSyncedFlush(final String[] aliasesOrIndices,
109115
IndicesOptions indicesOptions,
110116
final ActionListener<SyncedFlushResponse> listener) {
111117
final ClusterState state = clusterService.state();
118+
DEPRECATION_LOGGER.deprecatedAndMaybeLog("synced_flush", SYNCED_FLUSH_DEPRECATION_MESSAGE);
112119
final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, indicesOptions, aliasesOrIndices);
113120
final Map<String, List<ShardsSyncedFlushResult>> results = ConcurrentCollections.newConcurrentMap();
114121
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;
@@ -1212,4 +1213,19 @@ protected static Version minimumNodeVersion() throws IOException {
12121213
assertNotNull(minVersion);
12131214
return minVersion;
12141215
}
1216+
1217+
protected static Response performSyncedFlush(String indexName) throws IOException {
1218+
final Request request = new Request("POST", indexName + "/_flush/synced");
1219+
final List<String> expectedWarnings = Collections.singletonList(SyncedFlushService.SYNCED_FLUSH_DEPRECATION_MESSAGE);
1220+
if (nodeVersions.stream().allMatch(version -> version.onOrAfter(Version.V_7_6_0))) {
1221+
final Builder options = RequestOptions.DEFAULT.toBuilder();
1222+
options.setWarningsHandler(warnings -> warnings.equals(expectedWarnings) == false);
1223+
request.setOptions(options);
1224+
} else if (nodeVersions.stream().anyMatch(version -> version.onOrAfter(Version.V_7_6_0))) {
1225+
final Builder options = RequestOptions.DEFAULT.toBuilder();
1226+
options.setWarningsHandler(warnings -> warnings.isEmpty() == false && warnings.equals(expectedWarnings) == false);
1227+
request.setOptions(options);
1228+
}
1229+
return client().performRequest(request);
1230+
}
12151231
}

0 commit comments

Comments
 (0)