Skip to content

Commit

Permalink
Fixes after merging with master
Browse files Browse the repository at this point in the history
— fixed document:integTest
  • Loading branch information
sohaibiftikhar committed May 2, 2018
1 parent 3d7f978 commit 0bf9dcf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void flushAsync(FlushRequest flushRequest, ActionListener<FlushResponse>
* Synced flush API on elastic.co</a>
*/
public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, Header... headers) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, Request::syncedFlush,
return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, RequestConverters::syncedFlush,
SyncedFlushResponse::fromXContent, emptySet(), headers);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ static Request flush(FlushRequest flushRequest) {

static Request syncedFlush(SyncedFlushRequest syncedFlushRequest) {
String[] indices = syncedFlushRequest.indices() == null ? Strings.EMPTY_ARRAY : syncedFlushRequest.indices();
String endpoint = endpoint(indices, "_flush/synced");
Params syncedFlushparameters = Params.builder();
syncedFlushparameters.withIndicesOptions(syncedFlushRequest.indicesOptions());
return new Request(HttpPost.METHOD_NAME, endpoint, syncedFlushparameters.getParams(), null);
Request request = new Request(HttpPost.METHOD_NAME, endpoint(indices, "_flush/synced"));
Params parameters = new Params(request);
parameters.withIndicesOptions(syncedFlushRequest.indicesOptions());
return request;
}

static Request forceMerge(ForceMergeRequest forceMergeRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public void testSyncedFlush() {
}
Map<String, String> expectedParams = new HashMap<>();
setRandomIndicesOptions(syncedFlushRequest::indicesOptions, syncedFlushRequest::indicesOptions, expectedParams);
Request request = Request.syncedFlush(syncedFlushRequest);
Request request = RequestConverters.syncedFlush(syncedFlushRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
if (indices != null && indices.length > 0) {
endpoint.add(String.join(",", indices));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -821,7 +822,7 @@ public void testSyncedFlushIndex() throws Exception {
int successfulCopies = failureEntry.getValue().getSuccessfulCopies(); // <10>
int failedCopies = failureEntry.getValue().getFailedCopies(); // <11>
String failureReason = failureEntry.getValue().getFailureReason(); // <12>
ShardRouting routing = failureEntry.getValue().getShardRouting(); // <13>
Optional<ShardRouting> routing = failureEntry.getValue().getShardRouting(); // <13>
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/java-rest/high-level/indices/flush_synced.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-synced-respo
<10> Successful copies of the shard mentioned in 8.
<11> Failed copies of the shard mentioned in 8.
<12> Reason for failure of copies of the shard mentioned in 8.
<13> Routing information (like id, state, version etc.) for the failed shard copies.
<13> Optional. Routing information (like id, state, version etc.) for the failed shard copies.
If the entire shard failed then this returns Optional.empty.

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

Expand Down
1 change: 1 addition & 0 deletions docs/reference/indices/recovery.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Response:
"total_time_in_millis" : 175576,
"source" : {
"repository" : "my_repository",
"snapshot_uuid" : "faOyRKQOQwy8ze5yhwlAcQ",
"snapshot" : "my_snapshot",
"index" : "index1",
"version" : "{version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.inject.internal.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
Expand All @@ -38,11 +37,12 @@
import org.elasticsearch.rest.RestStatus;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
Expand Down Expand Up @@ -138,7 +138,7 @@ private Map<String, FlushSyncedResponsePerIndex> buildResponsePerIndex() {
shardResults.failureReason(),
shardResults.totalShards(),
shardResults.successfulShards(),
null)
Optional.empty())
);
continue;
}
Expand All @@ -151,7 +151,8 @@ private Map<String, FlushSyncedResponsePerIndex> buildResponsePerIndex() {
shardResults.failureReason(),
shardResults.totalShards(),
shardResults.successfulShards(),
shardEntry.getKey())
Optional.of(shardEntry.getKey())
)
);
}
}
Expand Down Expand Up @@ -269,11 +270,11 @@ private static SyncedFlushResponse innerFromXContent(XContentParser parser) thro
for (Map.Entry<ShardId, List<ShardFailure>> entry: failures.entrySet()) {
Map<ShardRouting, SyncedFlushService.ShardSyncedFlushResponse> shardResponses = new HashMap<>();
for (ShardFailure container: entry.getValue()) {
if (container.shardRouting != null) {
shardResponses.put(container.shardRouting,
container.maybeShardRouting.ifPresent(shardRouting ->
shardResponses.put(shardRouting,
new SyncedFlushService.ShardSyncedFlushResponse(container.failureReason)
);
}
)
);
}
// Size of entry.getValue() will at least be one
ShardFailure container = entry.getValue().get(0);
Expand Down Expand Up @@ -339,16 +340,16 @@ static ShardCounts calculateShardCounts(Iterable<ShardsSyncedFlushResult> result
public static final class ShardFailure {
ShardId shardId;
String failureReason;
ShardRouting shardRouting;
Optional<ShardRouting> maybeShardRouting;
int totalCopies;
int successfulCopies;
int failedCopies;

ShardFailure(ShardId shardId, String failureReason, int totalCopies, int successfulCopies,
@Nullable ShardRouting shardRouting) {
Optional<ShardRouting> maybeShardRouting) {
this.shardId = shardId;
this.failureReason = failureReason;
this.shardRouting = shardRouting;
this.maybeShardRouting = maybeShardRouting;
this.totalCopies = totalCopies;
this.successfulCopies = successfulCopies;
this.failedCopies = this.totalCopies - this.successfulCopies;
Expand All @@ -362,8 +363,8 @@ public String getFailureReason() {
return failureReason;
}

public ShardRouting getShardRouting() {
return shardRouting;
public Optional<ShardRouting> getShardRouting() {
return maybeShardRouting;
}

public int getTotalCopies() {
Expand Down Expand Up @@ -424,7 +425,7 @@ public static ShardFailure fromXContent(XContentParser parser, String indexName)
shardId != null &&
totalCopies != null &&
successfulCopies != null) {
return new ShardFailure(shardId, failureReason, totalCopies, successfulCopies, routing);
return new ShardFailure(shardId, failureReason, totalCopies, successfulCopies, Optional.ofNullable(routing));
} else {
throw new ParsingException(startLocation, "Unable to construct ShardsSyncedFlushResult");
}
Expand Down

0 comments on commit 0bf9dcf

Please sign in to comment.