Skip to content

Commit 7910274

Browse files
committed
Deprecate not copy settings and explicitly disallow (#30404)
We want copying settings to be the default behavior. This commit deprecates not copying settings, and disallows explicitly not copying settings. This gives users a transition path to the future default behavior.
1 parent 9d1e687 commit 7910274

File tree

14 files changed

+165
-59
lines changed

14 files changed

+165
-59
lines changed

docs/CHANGELOG.asciidoc

+2
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ analysis module. ({pull}30397[#30397])
316316
Highlighting::
317317
* Limit analyzed text for highlighting (improvements) {pull}28808[#28808] (issues: {issue}16764[#16764], {issue}27934[#27934])
318318
{ref-64}/breaking_64_api_changes.html#copy-source-settings-on-resize[Allow copying source settings on index resize operations] ({pull}30255[#30255])
319+
{ref-64}/breaking_64_api_changes.html#copy-source-settings-on-resize[Allow
320+
copying source settings on index resize operations] ({pull}30255[#30255], {pull}30404[#30404])
319321

320322
Added new "Request" object flavored request methods in the RestClient. Prefer
321323
these instead of the multi-argument versions. ({pull}29623[#29623])

docs/reference/indices/shrink-index.asciidoc

+15-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ the following request:
6262

6363
[source,js]
6464
--------------------------------------------------
65-
POST my_source_index/_shrink/my_target_index
65+
POST my_source_index/_shrink/my_target_index?copy_settings=true
66+
{
67+
"settings": {
68+
"index.routing.allocation.require._name": null, <1>
69+
"index.blocks.write": null <2>
70+
}
71+
}
6672
--------------------------------------------------
6773
// CONSOLE
6874
// TEST[continued]
6975

76+
<1> Clear the allocation requirement copied from the source index.
77+
<2> Clear the index write block copied from the source index.
78+
7079
The above request returns immediately once the target index has been added to
7180
the cluster state -- it doesn't wait for the shrink operation to start.
7281

@@ -97,7 +106,7 @@ and accepts `settings` and `aliases` parameters for the target index:
97106

98107
[source,js]
99108
--------------------------------------------------
100-
POST my_source_index/_shrink/my_target_index
109+
POST my_source_index/_shrink/my_target_index?copy_settings=true
101110
{
102111
"settings": {
103112
"index.number_of_replicas": 1,
@@ -125,9 +134,11 @@ NOTE: By default, with the exception of `index.analysis`, `index.similarity`,
125134
and `index.sort` settings, index settings on the source index are not copied
126135
during a shrink operation. With the exception of non-copyable settings, settings
127136
from the source index can be copied to the target index by adding the URL
128-
parameter `copy_settings=true` to the request.
137+
parameter `copy_settings=true` to the request. Note that `copy_settings` can not
138+
be set to `false`. The parameter `copy_settings` will be removed in 8.0.0
129139

130-
deprecated[6.4.0, `copy_settings` will default to `true` in 8.x and will be removed in 9.0.0]
140+
deprecated[6.4.0, not copying settings is deprecated, copying settings will be
141+
the default behavior in 7.x]
131142

132143
[float]
133144
=== Monitoring the shrink process

docs/reference/indices/split-index.asciidoc

+6-4
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ the following request:
117117

118118
[source,js]
119119
--------------------------------------------------
120-
POST my_source_index/_split/my_target_index
120+
POST my_source_index/_split/my_target_index?copy_settings=true
121121
{
122122
"settings": {
123123
"index.number_of_shards": 2
@@ -152,7 +152,7 @@ and accepts `settings` and `aliases` parameters for the target index:
152152

153153
[source,js]
154154
--------------------------------------------------
155-
POST my_source_index/_split/my_target_index
155+
POST my_source_index/_split/my_target_index?copy_settings=true
156156
{
157157
"settings": {
158158
"index.number_of_shards": 5 <1>
@@ -175,9 +175,11 @@ NOTE: By default, with the exception of `index.analysis`, `index.similarity`,
175175
and `index.sort` settings, index settings on the source index are not copied
176176
during a split operation. With the exception of non-copyable settings, settings
177177
from the source index can be copied to the target index by adding the URL
178-
parameter `copy_settings=true` to the request.
178+
parameter `copy_settings=true` to the request. Note that `copy_settings` can not
179+
be set to `false`. The parameter `copy_settings` will be removed in 8.0.0
179180

180-
deprecated[6.4.0, `copy_settings` will default to `true` in 8.x and will be removed in 9.0.0]
181+
deprecated[6.4.0, not copying settings is deprecated, copying settings will be
182+
the default behavior in 7.x]
181183

182184
[float]
183185
=== Monitoring the split process

rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/10_basic.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
---
22
"Shrink index via API":
3+
- skip:
4+
version: " - 6.3.99"
5+
reason: expects warnings that pre-6.4.0 will not send
6+
features: "warnings"
37
# creates an index with one document solely allocated on the master node
48
# and shrinks it into a new index with a single shard
59
# we don't do the relocation to a single node after the index is created
@@ -62,6 +66,8 @@
6266
body:
6367
settings:
6468
index.number_of_replicas: 0
69+
warnings:
70+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
6571

6672
- do:
6773
cluster.health:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/20_source_mapping.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
"Shrink index ignores target template mapping":
33
- skip:
4-
version: " - 5.99.99"
5-
reason: bug fixed in 5.6.0
4+
version: " - 6.3.99"
5+
reason: expects warnings that pre-6.4.0 will not send
6+
features: "warnings"
67

78
- do:
89
cluster.state: {}
@@ -69,6 +70,8 @@
6970
body:
7071
settings:
7172
index.number_of_replicas: 0
73+
warnings:
74+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
7275

7376
- do:
7477
cluster.health:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.shrink/30_copy_settings.yml

+16-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Copy settings during shrink index":
33
- skip:
44
version: " - 6.3.99"
5-
reason: copy_settings did not exist prior to 6.4.0
5+
reason: expects warnings that pre-6.4.0 will not send
66
features: "warnings"
77

88
- do:
@@ -47,8 +47,6 @@
4747
settings:
4848
index.number_of_replicas: 0
4949
index.merge.scheduler.max_thread_count: 2
50-
warnings:
51-
- "parameter [copy_settings] is deprecated but was [true]"
5250

5351
- do:
5452
cluster.health:
@@ -64,20 +62,19 @@
6462
- match: { copy-settings-target.settings.index.blocks.write: "true" }
6563
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $master }
6664

67-
# now we do a actual shrink and do not copy settings
65+
# now we do a actual shrink and do not copy settings (by default)
6866
- do:
6967
indices.shrink:
7068
index: "source"
7169
target: "no-copy-settings-target"
7270
wait_for_active_shards: 1
7371
master_timeout: 10s
74-
copy_settings: false
7572
body:
7673
settings:
7774
index.number_of_replicas: 0
7875
index.merge.scheduler.max_thread_count: 2
7976
warnings:
80-
- "parameter [copy_settings] is deprecated but was [false]"
77+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
8178

8279
- do:
8380
cluster.health:
@@ -92,3 +89,16 @@
9289
- match: { no-copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
9390
- is_false: no-copy-settings-target.settings.index.blocks.write
9491
- is_false: no-copy-settings-target.settings.index.routing.allocation.include._id
92+
93+
# now we do a actual shrink and try to set no copy settings
94+
- do:
95+
catch: /illegal_argument_exception/
96+
indices.shrink:
97+
index: "source"
98+
target: "explicit-no-copy-settings-target"
99+
wait_for_active_shards: 1
100+
master_timeout: 10s
101+
copy_settings: false
102+
body:
103+
settings:
104+
index.number_of_replicas: 0

rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/10_basic.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ setup:
3333
---
3434
"Split index via API":
3535
- skip:
36-
version: " - 6.0.99"
37-
reason: Added in 6.1.0
36+
version: " - 6.3.99"
37+
reason: expects warnings that pre-6.4.0 will not send
38+
features: "warnings"
3839

3940
# make it read-only
4041
- do:
@@ -60,6 +61,8 @@ setup:
6061
settings:
6162
index.number_of_replicas: 0
6263
index.number_of_shards: 2
64+
warnings:
65+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
6366

6467
- do:
6568
cluster.health:
@@ -103,8 +106,9 @@ setup:
103106
---
104107
"Create illegal split indices":
105108
- skip:
106-
version: " - 6.0.99"
107-
reason: Added in 6.1.0
109+
version: " - 6.3.99"
110+
reason: expects warnings that pre-6.4.0 will not send
111+
features: "warnings"
108112

109113
# try to do an illegal split with number_of_routing_shards set
110114
- do:
@@ -119,6 +123,8 @@ setup:
119123
index.number_of_replicas: 0
120124
index.number_of_shards: 2
121125
index.number_of_routing_shards: 4
126+
warnings:
127+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
122128

123129
# try to do an illegal split with illegal number_of_shards
124130
- do:
@@ -132,3 +138,5 @@ setup:
132138
settings:
133139
index.number_of_replicas: 0
134140
index.number_of_shards: 3
141+
warnings:
142+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"

rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/20_source_mapping.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
"Split index ignores target template mapping":
3-
# - skip:
4-
# version: " - 6.0.99"
5-
# reason: Added in 6.1.0
6-
# uncomment once AwaitsFix is resolved
73
- skip:
4+
# when re-enabling uncomment the below skips
85
version: "all"
96
reason: "AwaitsFix'ing, see https://github.com/elastic/elasticsearch/issues/30503"
7+
# version: " - 6.3.99"
8+
# reason: expects warnings that pre-6.4.0 will not send
9+
features: "warnings"
1010

1111
# create index
1212
- do:
@@ -68,6 +68,8 @@
6868
settings:
6969
index.number_of_shards: 2
7070
index.number_of_replicas: 0
71+
warnings:
72+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
7173

7274
- do:
7375
cluster.health:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.split/30_copy_settings.yml

+15-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Copy settings during split index":
33
- skip:
44
version: " - 6.3.99"
5-
reason: copy_settings did not exist prior to 6.4.0
5+
reason: expects warnings that pre-6.4.0 will not send
66
features: "warnings"
77

88
- do:
@@ -50,8 +50,6 @@
5050
index.number_of_replicas: 0
5151
index.number_of_shards: 2
5252
index.merge.scheduler.max_thread_count: 2
53-
warnings:
54-
- "parameter [copy_settings] is deprecated but was [true]"
5553

5654
- do:
5755
cluster.health:
@@ -67,21 +65,20 @@
6765
- match: { copy-settings-target.settings.index.blocks.write: "true" }
6866
- match: { copy-settings-target.settings.index.routing.allocation.include._id: $master }
6967

70-
# now we do a actual shrink and do not copy settings
68+
# now we do a actual shrink and do not copy settings (by default)
7169
- do:
7270
indices.split:
7371
index: "source"
7472
target: "no-copy-settings-target"
7573
wait_for_active_shards: 1
7674
master_timeout: 10s
77-
copy_settings: false
7875
body:
7976
settings:
8077
index.number_of_replicas: 0
8178
index.number_of_shards: 2
8279
index.merge.scheduler.max_thread_count: 2
8380
warnings:
84-
- "parameter [copy_settings] is deprecated but was [false]"
81+
- "resize operations without copying settings is deprecated; set parameter [copy_settings] to [true] for future default behavior"
8582

8683
- do:
8784
cluster.health:
@@ -96,3 +93,15 @@
9693
- match: { no-copy-settings-target.settings.index.merge.scheduler.max_thread_count: "2" }
9794
- is_false: no-copy-settings-target.settings.index.blocks.write
9895
- is_false: no-copy-settings-target.settings.index.routing.allocation.include._id
96+
97+
- do:
98+
catch: /illegal_argument_exception/
99+
indices.split:
100+
index: "source"
101+
target: "explicit-no-copy-settings-target"
102+
wait_for_active_shards: 1
103+
master_timeout: 10s
104+
copy_settings: false
105+
body:
106+
settings:
107+
index.number_of_replicas: 0

server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ResizeRequest.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class ResizeRequest extends AcknowledgedRequest<ResizeRequest> implements
5656
private CreateIndexRequest targetIndexRequest;
5757
private String sourceIndex;
5858
private ResizeType type = ResizeType.SHRINK;
59-
private boolean copySettings = false;
59+
private Boolean copySettings;
6060

6161
ResizeRequest() {}
6262

@@ -80,6 +80,7 @@ public ActionRequestValidationException validate() {
8080
if (type == ResizeType.SPLIT && IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING.exists(targetIndexRequest.settings()) == false) {
8181
validationException = addValidationError("index.number_of_shards is required for split operations", validationException);
8282
}
83+
assert copySettings == null || copySettings;
8384
return validationException;
8485
}
8586

@@ -98,10 +99,10 @@ public void readFrom(StreamInput in) throws IOException {
9899
} else {
99100
type = ResizeType.SHRINK; // BWC this used to be shrink only
100101
}
101-
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
102-
copySettings = in.readBoolean();
102+
if (in.getVersion().before(Version.V_6_4_0)) {
103+
copySettings = null;
103104
} else {
104-
copySettings = false;
105+
copySettings = in.readOptionalBoolean();
105106
}
106107
}
107108

@@ -113,8 +114,11 @@ public void writeTo(StreamOutput out) throws IOException {
113114
if (out.getVersion().onOrAfter(ResizeAction.COMPATIBILITY_VERSION)) {
114115
out.writeEnum(type);
115116
}
116-
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
117-
out.writeBoolean(copySettings);
117+
// noinspection StatementWithEmptyBody
118+
if (out.getVersion().before(Version.V_6_4_0)) {
119+
120+
} else {
121+
out.writeOptionalBoolean(copySettings);
118122
}
119123
}
120124

@@ -187,11 +191,14 @@ public ResizeType getResizeType() {
187191
return type;
188192
}
189193

190-
public void setCopySettings(final boolean copySettings) {
194+
public void setCopySettings(final Boolean copySettings) {
195+
if (copySettings != null && copySettings == false) {
196+
throw new IllegalArgumentException("[copySettings] can not be explicitly set to [false]");
197+
}
191198
this.copySettings = copySettings;
192199
}
193200

194-
public boolean getCopySettings() {
201+
public Boolean getCopySettings() {
195202
return copySettings;
196203
}
197204

server/src/main/java/org/elasticsearch/action/admin/indices/shrink/TransportResizeAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static CreateIndexClusterStateUpdateRequest prepareCreateIndexRequest(final Resi
185185
.waitForActiveShards(targetIndex.waitForActiveShards())
186186
.recoverFrom(metaData.getIndex())
187187
.resizeType(resizeRequest.getResizeType())
188-
.copySettings(resizeRequest.getCopySettings());
188+
.copySettings(resizeRequest.getCopySettings() == null ? false : resizeRequest.getCopySettings());
189189
}
190190

191191
@Override

0 commit comments

Comments
 (0)