Skip to content

Commit

Permalink
Output all empty snapshot info fields if in verbose mode (#25455)
Browse files Browse the repository at this point in the history
In #24477, a less verbose option was added to retrieve snapshot info via
GET /_snapshot/{repo}/{snapshots}.  The point of adding this less
verbose option was so that if the repository is a cloud based one, and
there are many snapshots for which the snapshot info needed to be
retrieved, then each snapshot would require reading a separate snapshot
metadata file to pull out the necessary information.  This can be costly
(performance and cost) on cloud based repositories, so a less verbose
option was added that only retrieves very basic information about each
snapshot that is all available in the index-N blob - requiring only one
read!

In order to display this less verbose snapshot info appropriately, logic
was added to not display those fields which could not be populated.
However, this broke integrators (e.g. ECE) that required these fields to
be present, even if empty.  This commit is to return these fields in the
response, even if empty, if the verbose option is set.
  • Loading branch information
Ali Beyad committed Jun 28, 2017
1 parent 5573f83 commit 9501233
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Expand Up @@ -37,14 +37,15 @@ public class GetSnapshotsRequest extends MasterNodeRequest<GetSnapshotsRequest>

public static final String ALL_SNAPSHOTS = "_all";
public static final String CURRENT_SNAPSHOT = "_current";
public static final boolean DEFAULT_VERBOSE_MODE = true;

private String repository;

private String[] snapshots = Strings.EMPTY_ARRAY;

private boolean ignoreUnavailable;

private boolean verbose = true;
private boolean verbose = DEFAULT_VERBOSE_MODE;

public GetSnapshotsRequest() {
}
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -346,6 +347,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
return toXContentSnapshot(builder, params);
}

final boolean verbose = params.paramAsBoolean("verbose", GetSnapshotsRequest.DEFAULT_VERBOSE_MODE);
// write snapshot info for the API and any other situations
builder.startObject();
builder.field(SNAPSHOT, snapshotId.getName());
Expand All @@ -359,22 +361,22 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
builder.value(index);
}
builder.endArray();
if (state != null) {
if (verbose || state != null) {
builder.field(STATE, state);
}
if (reason != null) {
builder.field(REASON, reason);
}
if (startTime != 0) {
if (verbose || startTime != 0) {
builder.field(START_TIME, DATE_TIME_FORMATTER.printer().print(startTime));
builder.field(START_TIME_IN_MILLIS, startTime);
}
if (endTime != 0) {
if (verbose || endTime != 0) {
builder.field(END_TIME, DATE_TIME_FORMATTER.printer().print(endTime));
builder.field(END_TIME_IN_MILLIS, endTime);
builder.timeValueField(DURATION_IN_MILLIS, DURATION, endTime - startTime);
}
if (!shardFailures.isEmpty()) {
if (verbose || !shardFailures.isEmpty()) {
builder.startArray(FAILURES);
for (SnapshotShardFailure shardFailure : shardFailures) {
builder.startObject();
Expand All @@ -383,7 +385,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
}
builder.endArray();
}
if (totalShards != 0) {
if (verbose || totalShards != 0) {
builder.startObject(SHARDS);
builder.field(TOTAL, totalShards);
builder.field(FAILED, failedShards());
Expand Down
Expand Up @@ -32,6 +32,7 @@ setup:
snapshot: test_snapshot

- is_true: snapshots
- is_true: snapshots.0.failures

- do:
snapshot.delete:
Expand Down Expand Up @@ -87,6 +88,8 @@ setup:
- is_true: snapshots
- match: { snapshots.0.snapshot: test_snapshot }
- match: { snapshots.0.state: SUCCESS }
- is_false: snapshots.0.failures
- is_false: snapshots.0.shards
- is_false: snapshots.0.version

- do:
Expand Down

0 comments on commit 9501233

Please sign in to comment.