Skip to content

Commit 9073cc6

Browse files
kelywelsch
authored andcommitted
Fix default value of ignore_unavailable for snapshot REST API (#27056)
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
1 parent 996b065 commit 9073cc6

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotRequest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ public boolean includeGlobalState() {
355355
* @param source snapshot definition
356356
* @return this request
357357
*/
358+
@SuppressWarnings("unchecked")
358359
public CreateSnapshotRequest source(Map<String, Object> source) {
359-
for (Map.Entry<String, Object> entry : ((Map<String, Object>) source).entrySet()) {
360+
for (Map.Entry<String, Object> entry : source.entrySet()) {
360361
String name = entry.getKey();
361362
if (name.equals("indices")) {
362363
if (entry.getValue() instanceof String) {
@@ -377,7 +378,7 @@ public CreateSnapshotRequest source(Map<String, Object> source) {
377378
includeGlobalState = nodeBooleanValue(entry.getValue(), "include_global_state");
378379
}
379380
}
380-
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
381+
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
381382
return this;
382383
}
383384

core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ public Settings indexSettings() {
470470
* @param source restore definition
471471
* @return this request
472472
*/
473+
@SuppressWarnings("unchecked")
473474
public RestoreSnapshotRequest source(Map<String, Object> source) {
474475
for (Map.Entry<String, Object> entry : source.entrySet()) {
475476
String name = entry.getKey();
@@ -523,7 +524,7 @@ public RestoreSnapshotRequest source(Map<String, Object> source) {
523524
}
524525
}
525526
}
526-
indicesOptions(IndicesOptions.fromMap((Map<String, Object>) source, IndicesOptions.lenientExpandOpen()));
527+
indicesOptions(IndicesOptions.fromMap(source, indicesOptions));
527528
return this;
528529
}
529530

core/src/test/java/org/elasticsearch/snapshots/SnapshotRequestsTests.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
3737

3838
XContentBuilder builder = jsonBuilder().startObject();
3939

40-
if(randomBoolean()) {
40+
if (randomBoolean()) {
4141
builder.field("indices", "foo,bar,baz");
4242
} else {
4343
builder.startArray("indices");
@@ -76,6 +76,10 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
7676
builder.value("set3");
7777
builder.endArray();
7878
}
79+
boolean includeIgnoreUnavailable = randomBoolean();
80+
if (includeIgnoreUnavailable) {
81+
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
82+
}
7983

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

@@ -89,15 +93,18 @@ public void testRestoreSnapshotRequestParsing() throws IOException {
8993
assertEquals(partial, request.partial());
9094
assertEquals("val1", request.settings().get("set1"));
9195
assertArrayEquals(request.ignoreIndexSettings(), new String[]{"set2", "set3"});
92-
96+
boolean expectedIgnoreAvailable = includeIgnoreUnavailable
97+
? indicesOptions.ignoreUnavailable()
98+
: IndicesOptions.strictExpandOpen().ignoreUnavailable();
99+
assertEquals(expectedIgnoreAvailable, request.indicesOptions().ignoreUnavailable());
93100
}
94101

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

98105
XContentBuilder builder = jsonBuilder().startObject();
99106

100-
if(randomBoolean()) {
107+
if (randomBoolean()) {
101108
builder.field("indices", "foo,bar,baz");
102109
} else {
103110
builder.startArray("indices");
@@ -134,6 +141,10 @@ public void testCreateSnapshotRequestParsing() throws IOException {
134141
builder.value("set3");
135142
builder.endArray();
136143
}
144+
boolean includeIgnoreUnavailable = randomBoolean();
145+
if (includeIgnoreUnavailable) {
146+
builder.field("ignore_unavailable", indicesOptions.ignoreUnavailable());
147+
}
137148

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

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

149164
}

rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.create/10_basic.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,38 @@ setup:
3737
snapshot: test_snapshot
3838

3939
- match: { acknowledged: true }
40+
41+
---
42+
"Create a snapshot for missing index":
43+
- skip:
44+
version: " - 6.0.0"
45+
reason: ignore_unavailable default is false in 6.0.0
46+
47+
- do:
48+
catch: missing
49+
snapshot.create:
50+
repository: test_repo_create_1
51+
snapshot: test_snapshot_1
52+
wait_for_completion: true
53+
body: |
54+
{ "indices": "missing_1" }
55+
56+
- do:
57+
snapshot.create:
58+
repository: test_repo_create_1
59+
snapshot: test_snapshot_2
60+
wait_for_completion: true
61+
body: |
62+
{ "indices": "missing_2", "ignore_unavailable": true }
63+
64+
- match: { snapshot.snapshot: test_snapshot_2 }
65+
- match: { snapshot.state : SUCCESS }
66+
- match: { snapshot.shards.successful: 0 }
67+
- match: { snapshot.shards.failed : 0 }
68+
69+
- do:
70+
snapshot.delete:
71+
repository: test_repo_create_1
72+
snapshot: test_snapshot_2
73+
74+
- match: { acknowledged: true }

0 commit comments

Comments
 (0)