Skip to content

Commit

Permalink
Fix default value of ignore_unavailable for snapshot REST API (#27056)
Browse files Browse the repository at this point in the history
The default value for ignore_unavailable did not match what was documented when using the REST APIs for snapshot creation and restore. This commit sets the default value of ignore_unavailable to false, the way it is documented and ensures it's the same when using either REST API or transport client.

Closes #25359
  • Loading branch information
kel authored and ywelsch committed Nov 16, 2017
1 parent 623367d commit 6b81748
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,9 @@ public boolean includeGlobalState() {
* @param source snapshot definition
* @return this request
*/
@SuppressWarnings("unchecked")
public CreateSnapshotRequest source(Map<String, Object> source) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) source).entrySet()) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
String name = entry.getKey();
if (name.equals("indices")) {
if (entry.getValue() instanceof String) {
Expand All @@ -402,7 +403,7 @@ public CreateSnapshotRequest source(Map<String, Object> source) {
includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
}
}
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ public Settings indexSettings() {
* @param source restore definition
* @return this request
*/
@SuppressWarnings("unchecked")
public RestoreSnapshotRequest source(Map<String, Object> source) {
for (Map.Entry<String, Object> entry : source.entrySet()) {
String name = entry.getKey();
Expand Down Expand Up @@ -558,7 +559,7 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
}
}
}
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void testRestoreSnapshotRequestParsing() throws IOException {

XContentBuilder builder = jsonBuilder().startObject();

if(randomBoolean()) {
if (randomBoolean()) {
builder.field("indices", "foo,bar,baz");
} else {
builder.startArray("indices");
Expand Down Expand Up @@ -76,6 +76,10 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
builder.value("set3");
builder.endArray();
}
boolean includeIgnoreUnavailable = randomBoolean();
if (includeIgnoreUnavailable) {
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
}

BytesReference bytes = builder.endObject().bytes();

Expand All @@ -89,15 +93,18 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
assertEquals(partial, request.partial());
assertEquals("val1", request.settings().get("set1"));
assertArrayEquals(request.ignoreIndexSettings(), new String[]{"set2", "set3"});

boolean expectedIgnoreAvailable = includeIgnoreUnavailable
? indicesOptions.ignoreUnavailable()
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
}

public void testCreateSnapshotRequestParsing() throws IOException {
CreateSnapshotRequest request = new CreateSnapshotRequest("test-repo", "test-snap");

XContentBuilder builder = jsonBuilder().startObject();

if(randomBoolean()) {
if (randomBoolean()) {
builder.field("indices", "foo,bar,baz");
} else {
builder.startArray("indices");
Expand Down Expand Up @@ -134,6 +141,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
builder.value("set3");
builder.endArray();
}
boolean includeIgnoreUnavailable = randomBoolean();
if (includeIgnoreUnavailable) {
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
}

BytesReference bytes = builder.endObject().bytes();

Expand All @@ -144,6 +155,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
assertArrayEquals(request.indices(), new String[]{"foo", "bar", "baz"});
assertEquals(partial, request.partial());
assertEquals("val1", request.settings().get("set1"));
boolean expectedIgnoreAvailable = includeIgnoreUnavailable
? indicesOptions.ignoreUnavailable()
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,38 @@ setup:
snapshot: test_snapshot

- match: { acknowledged: true }

---
"Create a snapshot for missing index":
- skip:
version: " - 6.99.99"
reason: ignore_unavailable default is false in 7.0.0

- do:
catch: missing
snapshot.create:
repository: test_repo_create_1
snapshot: test_snapshot_1
wait_for_completion: true
body: |
{ "indices": "missing_1" }
- do:
snapshot.create:
repository: test_repo_create_1
snapshot: test_snapshot_2
wait_for_completion: true
body: |
{ "indices": "missing_2", "ignore_unavailable": true }
- match: { snapshot.snapshot: test_snapshot_2 }
- match: { snapshot.state : SUCCESS }
- match: { snapshot.shards.successful: 0 }
- match: { snapshot.shards.failed : 0 }

- do:
snapshot.delete:
repository: test_repo_create_1
snapshot: test_snapshot_2

- match: { acknowledged: true }

0 comments on commit 6b81748

Please sign in to comment.