Skip to content

Commit 0bf9dcf

Browse files
Fixes after merging with master
— fixed document:integTest
1 parent 3d7f978 commit 0bf9dcf

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public void flushAsync(FlushRequest flushRequest, ActionListener<FlushResponse>
273273
* Synced flush API on elastic.co</a>
274274
*/
275275
public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, Header... headers) throws IOException {
276-
return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, Request::syncedFlush,
276+
return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, RequestConverters::syncedFlush,
277277
SyncedFlushResponse::fromXContent, emptySet(), headers);
278278
}
279279

@@ -284,7 +284,7 @@ public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, He
284284
* Synced flush API on elastic.co</a>
285285
*/
286286
public void flushSyncedAsync(SyncedFlushRequest syncedFlushRequest, ActionListener<SyncedFlushResponse> listener, Header... headers) {
287-
restHighLevelClient.performRequestAsyncAndParseEntity(syncedFlushRequest, Request::syncedFlush,
287+
restHighLevelClient.performRequestAsyncAndParseEntity(syncedFlushRequest, RequestConverters::syncedFlush,
288288
SyncedFlushResponse::fromXContent, listener, emptySet(), headers);
289289
}
290290

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ static Request flush(FlushRequest flushRequest) {
209209

210210
static Request syncedFlush(SyncedFlushRequest syncedFlushRequest) {
211211
String[] indices = syncedFlushRequest.indices() == null ? Strings.EMPTY_ARRAY : syncedFlushRequest.indices();
212-
String endpoint = endpoint(indices, "_flush/synced");
213-
Params syncedFlushparameters = Params.builder();
214-
syncedFlushparameters.withIndicesOptions(syncedFlushRequest.indicesOptions());
215-
return new Request(HttpPost.METHOD_NAME, endpoint, syncedFlushparameters.getParams(), null);
212+
Request request = new Request(HttpPost.METHOD_NAME, endpoint(indices, "_flush/synced"));
213+
Params parameters = new Params(request);
214+
parameters.withIndicesOptions(syncedFlushRequest.indicesOptions());
215+
return request;
216216
}
217217

218218
static Request forceMerge(ForceMergeRequest forceMergeRequest) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void testSyncedFlush() {
599599
}
600600
Map<String, String> expectedParams = new HashMap<>();
601601
setRandomIndicesOptions(syncedFlushRequest::indicesOptions, syncedFlushRequest::indicesOptions, expectedParams);
602-
Request request = Request.syncedFlush(syncedFlushRequest);
602+
Request request = RequestConverters.syncedFlush(syncedFlushRequest);
603603
StringJoiner endpoint = new StringJoiner("/", "/", "");
604604
if (indices != null && indices.length > 0) {
605605
endpoint.add(String.join(",", indices));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import java.io.IOException;
7676
import java.util.HashMap;
7777
import java.util.Map;
78+
import java.util.Optional;
7879
import java.util.concurrent.CountDownLatch;
7980
import java.util.concurrent.TimeUnit;
8081

@@ -821,7 +822,7 @@ public void testSyncedFlushIndex() throws Exception {
821822
int successfulCopies = failureEntry.getValue().getSuccessfulCopies(); // <10>
822823
int failedCopies = failureEntry.getValue().getFailedCopies(); // <11>
823824
String failureReason = failureEntry.getValue().getFailureReason(); // <12>
824-
ShardRouting routing = failureEntry.getValue().getShardRouting(); // <13>
825+
Optional<ShardRouting> routing = failureEntry.getValue().getShardRouting(); // <13>
825826
}
826827
}
827828
}

docs/java-rest/high-level/indices/flush_synced.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-synced-respo
8282
<10> Successful copies of the shard mentioned in 8.
8383
<11> Failed copies of the shard mentioned in 8.
8484
<12> Reason for failure of copies of the shard mentioned in 8.
85-
<13> Routing information (like id, state, version etc.) for the failed shard copies.
85+
<13> Optional. Routing information (like id, state, version etc.) for the failed shard copies.
86+
If the entire shard failed then this returns Optional.empty.
8687

8788
By default, if the indices were not found, an `ElasticsearchException` will be thrown:
8889

docs/reference/indices/recovery.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Response:
8888
"total_time_in_millis" : 175576,
8989
"source" : {
9090
"repository" : "my_repository",
91+
"snapshot_uuid" : "faOyRKQOQwy8ze5yhwlAcQ",
9192
"snapshot" : "my_snapshot",
9293
"index" : "index1",
9394
"version" : "{version}"

server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.cluster.metadata.IndexMetaData;
2323
import org.elasticsearch.cluster.routing.ShardRouting;
2424
import org.elasticsearch.common.ParsingException;
25-
import org.elasticsearch.common.inject.internal.Nullable;
2625
import org.elasticsearch.common.io.stream.StreamInput;
2726
import org.elasticsearch.common.io.stream.StreamOutput;
2827
import org.elasticsearch.common.io.stream.Streamable;
@@ -38,11 +37,12 @@
3837
import org.elasticsearch.rest.RestStatus;
3938

4039
import java.io.IOException;
41-
import java.util.ArrayList;
4240
import java.util.Collections;
41+
import java.util.ArrayList;
42+
import java.util.Map;
4343
import java.util.HashMap;
4444
import java.util.List;
45-
import java.util.Map;
45+
import java.util.Optional;
4646

4747
import static java.util.Collections.unmodifiableMap;
4848
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
@@ -138,7 +138,7 @@ private Map<String, FlushSyncedResponsePerIndex> buildResponsePerIndex() {
138138
shardResults.failureReason(),
139139
shardResults.totalShards(),
140140
shardResults.successfulShards(),
141-
null)
141+
Optional.empty())
142142
);
143143
continue;
144144
}
@@ -151,7 +151,8 @@ private Map<String, FlushSyncedResponsePerIndex> buildResponsePerIndex() {
151151
shardResults.failureReason(),
152152
shardResults.totalShards(),
153153
shardResults.successfulShards(),
154-
shardEntry.getKey())
154+
Optional.of(shardEntry.getKey())
155+
)
155156
);
156157
}
157158
}
@@ -269,11 +270,11 @@ private static SyncedFlushResponse innerFromXContent(XContentParser parser) thro
269270
for (Map.Entry<ShardId, List<ShardFailure>> entry: failures.entrySet()) {
270271
Map<ShardRouting, SyncedFlushService.ShardSyncedFlushResponse> shardResponses = new HashMap<>();
271272
for (ShardFailure container: entry.getValue()) {
272-
if (container.shardRouting != null) {
273-
shardResponses.put(container.shardRouting,
273+
container.maybeShardRouting.ifPresent(shardRouting ->
274+
shardResponses.put(shardRouting,
274275
new SyncedFlushService.ShardSyncedFlushResponse(container.failureReason)
275-
);
276-
}
276+
)
277+
);
277278
}
278279
// Size of entry.getValue() will at least be one
279280
ShardFailure container = entry.getValue().get(0);
@@ -339,16 +340,16 @@ static ShardCounts calculateShardCounts(Iterable<ShardsSyncedFlushResult> result
339340
public static final class ShardFailure {
340341
ShardId shardId;
341342
String failureReason;
342-
ShardRouting shardRouting;
343+
Optional<ShardRouting> maybeShardRouting;
343344
int totalCopies;
344345
int successfulCopies;
345346
int failedCopies;
346347

347348
ShardFailure(ShardId shardId, String failureReason, int totalCopies, int successfulCopies,
348-
@Nullable ShardRouting shardRouting) {
349+
Optional<ShardRouting> maybeShardRouting) {
349350
this.shardId = shardId;
350351
this.failureReason = failureReason;
351-
this.shardRouting = shardRouting;
352+
this.maybeShardRouting = maybeShardRouting;
352353
this.totalCopies = totalCopies;
353354
this.successfulCopies = successfulCopies;
354355
this.failedCopies = this.totalCopies - this.successfulCopies;
@@ -362,8 +363,8 @@ public String getFailureReason() {
362363
return failureReason;
363364
}
364365

365-
public ShardRouting getShardRouting() {
366-
return shardRouting;
366+
public Optional<ShardRouting> getShardRouting() {
367+
return maybeShardRouting;
367368
}
368369

369370
public int getTotalCopies() {
@@ -424,7 +425,7 @@ public static ShardFailure fromXContent(XContentParser parser, String indexName)
424425
shardId != null &&
425426
totalCopies != null &&
426427
successfulCopies != null) {
427-
return new ShardFailure(shardId, failureReason, totalCopies, successfulCopies, routing);
428+
return new ShardFailure(shardId, failureReason, totalCopies, successfulCopies, Optional.ofNullable(routing));
428429
} else {
429430
throw new ParsingException(startLocation, "Unable to construct ShardsSyncedFlushResult");
430431
}

0 commit comments

Comments
 (0)