Skip to content

Commit

Permalink
Deprecate isShardsAcked in favour of isShardsAcknowledged
Browse files Browse the repository at this point in the history
  • Loading branch information
olcbean committed Jan 5, 2018
1 parent fdb9b50 commit ed1c3e1
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ public void testCreateIndex() throws IOException {

// tag::create-index-response
boolean acknowledged = createIndexResponse.isAcknowledged(); // <1>
boolean shardsAcked = createIndexResponse.isShardsAcked(); // <2>
boolean shardsAcknowledged = createIndexResponse.isShardsAcknowledged(); // <2>
// end::create-index-response
assertTrue(acknowledged);
assertTrue(shardsAcked);
assertTrue(shardsAcknowledged);
}
}

Expand All @@ -202,7 +202,6 @@ public void testCreateIndexAsync() throws Exception {

{
CreateIndexRequest request = new CreateIndexRequest("twitter");

// tag::create-index-execute-async
client.indices().createIndexAsync(request, new ActionListener<CreateIndexResponse>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public ActiveShardCount waitForActiveShards() {
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Index creation will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link CreateIndexResponse#isShardsAcked()} to
* to be active before returning. Check {@link CreateIndexResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public CreateIndexRequestBuilder setUpdateAllTypes(boolean updateAllTypes) {
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Index creation will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link CreateIndexResponse#isShardsAcked()} to
* to be active before returning. Check {@link CreateIndexResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ public class CreateIndexResponse extends AcknowledgedResponse implements ToXCont
PARSER.declareField(constructorArg(), (parser, context) -> parser.text(), INDEX, ObjectParser.ValueType.STRING);
}

private boolean shardsAcked;
private boolean shardsAcknowledged;
private String index;

protected CreateIndexResponse() {
}

protected CreateIndexResponse(boolean acknowledged, boolean shardsAcked, String index) {
protected CreateIndexResponse(boolean acknowledged, boolean shardsAcknowledged, String index) {
super(acknowledged);
assert acknowledged || shardsAcked == false; // if its not acknowledged, then shards acked should be false too
this.shardsAcked = shardsAcked;
assert acknowledged || shardsAcknowledged == false; // if its not acknowledged, then shardsAcknowledged should be false too
this.shardsAcknowledged = shardsAcknowledged;
this.index = index;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
readAcknowledged(in);
shardsAcked = in.readBoolean();
shardsAcknowledged = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_5_6_0)) {
index = in.readString();
}
Expand All @@ -79,27 +79,39 @@ public void readFrom(StreamInput in) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeAcknowledged(out);
out.writeBoolean(shardsAcked);
out.writeBoolean(shardsAcknowledged);
if (out.getVersion().onOrAfter(Version.V_5_6_0)) {
out.writeString(index);
}
}

/**
* Returns true if the requisite number of shards were started before
* returning from the index creation operation. If {@link #isAcknowledged()}
* returning from the index creation operation. If {@link #isAcknowledged()}
* is false, then this also returns false.
*
* @deprecated use {@link #isShardsAcknowledged()}
*/
@Deprecated
public boolean isShardsAcked() {
return shardsAcked;
return shardsAcknowledged;
}

/**
* Returns true if the requisite number of shards were started before
* returning from the index creation operation. If {@link #isAcknowledged()}
* is false, then this also returns false.
*/
public boolean isShardsAcknowledged() {
return shardsAcknowledged;
}

public String index() {
return index;
}

public void addCustomFields(XContentBuilder builder) throws IOException {
builder.field(SHARDS_ACKNOWLEDGED.getPreferredName(), isShardsAcked());
builder.field(SHARDS_ACKNOWLEDGED.getPreferredName(), isShardsAcknowledged());
builder.field(INDEX.getPreferredName(), index());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void masterOperation(final CreateIndexRequest request, final ClusterSt
.waitForActiveShards(request.waitForActiveShards());

createIndexService.createIndex(updateRequest, ActionListener.wrap(response ->
listener.onResponse(new CreateIndexResponse(response.isAcknowledged(), response.isShardsAcked(), indexName)),
listener.onResponse(new CreateIndexResponse(response.isAcknowledged(), response.isShardsAcknowledged(), indexName)),
listener::onFailure));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ CreateIndexRequest getCreateIndexRequest() {
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Index creation will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link RolloverResponse#isShardsAcked()} to
* to be active before returning. Check {@link RolloverResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public RolloverRequestBuilder mapping(String type, String source) {
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Index creation will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link RolloverResponse#isShardsAcked()} to
* to be active before returning. Check {@link RolloverResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public final class RolloverResponse extends ActionResponse implements ToXContent
private boolean dryRun;
private boolean rolledOver;
private boolean acknowledged;
private boolean shardsAcked;
private boolean shardsAcknowledged;

RolloverResponse() {
}

RolloverResponse(String oldIndex, String newIndex, Set<Condition.Result> conditionResults,
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcked) {
boolean dryRun, boolean rolledOver, boolean acknowledged, boolean shardsAcknowledged) {
this.oldIndex = oldIndex;
this.newIndex = newIndex;
this.dryRun = dryRun;
this.rolledOver = rolledOver;
this.acknowledged = acknowledged;
this.shardsAcked = shardsAcked;
this.shardsAcknowledged = shardsAcknowledged;
this.conditionStatus = conditionResults.stream()
.map(result -> new AbstractMap.SimpleEntry<>(result.condition.toString(), result.matched))
.collect(Collectors.toSet());
Expand Down Expand Up @@ -105,19 +105,31 @@ public boolean isRolledOver() {
* Returns true if the creation of the new rollover index and switching of the
* alias to the newly created index was successful, and returns false otherwise.
* If {@link #isDryRun()} is true, then this will also return false. If this
* returns false, then {@link #isShardsAcked()} will also return false.
* returns false, then {@link #isShardsAcknowledged()} will also return false.
*/
public boolean isAcknowledged() {
return acknowledged;
}

/**
* Returns true if the requisite number of shards were started in the newly
* created rollover index before returning. If {@link #isAcknowledged()} is
* created rollover index before returning. If {@link #isAcknowledged()} is
* false, then this will also return false.
*
* @deprecated use {@link #isShardsAcknowledged()}
*/
@Deprecated
public boolean isShardsAcked() {
return shardsAcked;
return shardsAcknowledged;
}

/**
* Returns true if the requisite number of shards were started in the newly
* created rollover index before returning. If {@link #isAcknowledged()} is
* false, then this will also return false.
*/
public boolean isShardsAcknowledged() {
return shardsAcknowledged;
}

@Override
Expand All @@ -136,7 +148,7 @@ public void readFrom(StreamInput in) throws IOException {
dryRun = in.readBoolean();
rolledOver = in.readBoolean();
acknowledged = in.readBoolean();
shardsAcked = in.readBoolean();
shardsAcknowledged = in.readBoolean();
}

@Override
Expand All @@ -152,7 +164,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(dryRun);
out.writeBoolean(rolledOver);
out.writeBoolean(acknowledged);
out.writeBoolean(shardsAcked);
out.writeBoolean(shardsAcknowledged);
}

@Override
Expand All @@ -163,7 +175,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field(ROLLED_OVER, rolledOver);
builder.field(DRY_RUN, dryRun);
builder.field(ACKNOWLEDGED, acknowledged);
builder.field(SHARDS_ACKED, shardsAcked);
builder.field(SHARDS_ACKED, shardsAcknowledged);
builder.startObject(CONDITIONS);
for (Map.Entry<String, Boolean> entry : conditionStatus) {
builder.field(entry.getKey(), entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ public void onResponse(IndicesStatsResponse statsResponse) {
activeShardsObserver.waitForActiveShards(new String[]{rolloverIndexName},
rolloverRequest.getCreateIndexRequest().waitForActiveShards(),
rolloverRequest.masterNodeTimeout(),
isShardsAcked -> listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName,
conditionResults, false, true, true, isShardsAcked)),
isShardsAcknowledged -> listener.onResponse(new RolloverResponse(
sourceIndexName, rolloverIndexName, conditionResults, false, true, true,
isShardsAcknowledged)),
listener::onFailure);
} else {
listener.onResponse(new RolloverResponse(sourceIndexName, rolloverIndexName, conditionResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String getSourceIndex() {
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Index creation will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link ResizeResponse#isShardsAcked()} to
* to be active before returning. Check {@link ResizeResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResizeRequestBuilder setSettings(Settings settings) {
* non-negative integer, up to the number of copies per shard (number of replicas + 1),
* to wait for the desired amount of shard copies to become active before returning.
* Index creation will only wait up until the timeout value for the number of shard copies
* to be active before returning. Check {@link ResizeResponse#isShardsAcked()} to
* to be active before returning. Check {@link ResizeResponse#isShardsAcknowledged()} to
* determine if the requisite shard copies were all started before returning or timing out.
*
* @param waitForActiveShards number of active shard copies to wait on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class ResizeResponse extends CreateIndexResponse {
ResizeResponse() {
}

ResizeResponse(boolean acknowledged, boolean shardsAcked, String index) {
super(acknowledged, shardsAcked, index);
ResizeResponse(boolean acknowledged, boolean shardsAcknowledged, String index) {
super(acknowledged, shardsAcknowledged, index);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public void onResponse(IndicesStatsResponse indicesStatsResponse) {
createIndexService.createIndex(
updateRequest,
ActionListener.wrap(response ->
listener.onResponse(new ResizeResponse(response.isAcknowledged(), response.isShardsAcked(),
updateRequest.index())), listener::onFailure
listener.onResponse(new ResizeResponse(response.isAcknowledged(), response.isShardsAcknowledged(),
updateRequest.index())), listener::onFailure
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,24 @@
*/
public class CreateIndexClusterStateUpdateResponse extends ClusterStateUpdateResponse {

private final boolean shardsAcked;
private final boolean shardsAcknowledged;

public CreateIndexClusterStateUpdateResponse(boolean acknowledged, boolean shardsAcked) {
public CreateIndexClusterStateUpdateResponse(boolean acknowledged, boolean shardsAcknowledged) {
super(acknowledged);
this.shardsAcked = shardsAcked;
this.shardsAcknowledged = shardsAcknowledged;
}

/**
* Returns whether the requisite number of shard copies started before the completion of the operation.
*
* @deprecated use {@link #isShardsAcknowledged()}
*/
@Deprecated
public boolean isShardsAcked() {
return shardsAcked;
return shardsAcknowledged;
}

public boolean isShardsAcknowledged() {
return shardsAcknowledged;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ public static void validateIndexOrAliasName(String index, BiFunction<String, Str
* before sending the response on the listener. If the index creation was successfully applied on
* the cluster state, then {@link CreateIndexClusterStateUpdateResponse#isAcknowledged()} will return
* true, otherwise it will return false and no waiting will occur for started shards
* ({@link CreateIndexClusterStateUpdateResponse#isShardsAcked()} will also be false). If the index
* ({@link CreateIndexClusterStateUpdateResponse#isShardsAcknowledged()} will also be false). If the index
* creation in the cluster state was successful and the requisite shard copies were started before
* the timeout, then {@link CreateIndexClusterStateUpdateResponse#isShardsAcked()} will
* the timeout, then {@link CreateIndexClusterStateUpdateResponse#isShardsAcknowledged()} will
* return true, otherwise if the operation timed out, then it will return false.
*
* @param request the index creation cluster state update request
Expand All @@ -204,12 +204,12 @@ public void createIndex(final CreateIndexClusterStateUpdateRequest request,
onlyCreateIndex(request, ActionListener.wrap(response -> {
if (response.isAcknowledged()) {
activeShardsObserver.waitForActiveShards(new String[]{request.index()}, request.waitForActiveShards(), request.ackTimeout(),
shardsAcked -> {
if (shardsAcked == false) {
shardsAcknowledged -> {
if (shardsAcknowledged == false) {
logger.debug("[{}] index created, but the operation timed out while waiting for " +
"enough shards to be started.", request.index());
}
listener.onResponse(new CreateIndexClusterStateUpdateResponse(response.isAcknowledged(), shardsAcked));
listener.onResponse(new CreateIndexClusterStateUpdateResponse(response.isAcknowledged(), shardsAcknowledged));
}, listener::onFailure);
} else {
listener.onResponse(new CreateIndexClusterStateUpdateResponse(false, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,16 @@ public void testDefaultWaitForActiveShardsUsesIndexSetting() throws Exception {
.put(settings)
.put(SETTING_WAIT_FOR_ACTIVE_SHARDS.getKey(), "all")
.build();
assertFalse(client().admin().indices().prepareCreate("test-idx-2").setSettings(settings).setTimeout("100ms").get().isShardsAcked());
assertFalse(client().admin().indices().prepareCreate("test-idx-2").setSettings(settings).setTimeout("100ms").get()
.isShardsAcknowledged());

// the numeric equivalent of all should also fail
settings = Settings.builder()
.put(settings)
.put(SETTING_WAIT_FOR_ACTIVE_SHARDS.getKey(), Integer.toString(numReplicas + 1))
.build();
assertFalse(client().admin().indices().prepareCreate("test-idx-3").setSettings(settings).setTimeout("100ms").get().isShardsAcked());
assertFalse(client().admin().indices().prepareCreate("test-idx-3").setSettings(settings).setTimeout("100ms").get()
.isShardsAcknowledged());
}

public void testInvalidPartitionSize() {
Expand Down
Loading

0 comments on commit ed1c3e1

Please sign in to comment.