28
28
import java .util .List ;
29
29
import java .util .concurrent .atomic .AtomicBoolean ;
30
30
import java .util .concurrent .atomic .AtomicReference ;
31
+ import java .util .function .Function ;
31
32
32
33
import static org .hamcrest .Matchers .equalTo ;
33
34
@@ -42,45 +43,58 @@ public void testThatNonDynamicSettingChangesTakeEffect() throws Exception {
42
43
MetadataUpdateSettingsService metadataUpdateSettingsService = internalCluster ().getCurrentMasterNodeInstance (
43
44
MetadataUpdateSettingsService .class
44
45
);
45
- UpdateSettingsClusterStateUpdateRequest request = new UpdateSettingsClusterStateUpdateRequest ().ackTimeout (TimeValue .ZERO );
46
- List <Index > indices = new ArrayList <>();
46
+ List <Index > indicesList = new ArrayList <>();
47
47
for (IndicesService indicesService : internalCluster ().getInstances (IndicesService .class )) {
48
48
for (IndexService indexService : indicesService ) {
49
- indices .add (indexService .index ());
49
+ indicesList .add (indexService .index ());
50
50
}
51
51
}
52
- request .indices (indices .toArray (Index .EMPTY_ARRAY ));
53
- request .settings (Settings .builder ().put ("index.codec" , "FastDecompressionCompressingStoredFieldsData" ).build ());
52
+ final var indices = indicesList .toArray (Index .EMPTY_ARRAY );
53
+
54
+ final Function <UpdateSettingsClusterStateUpdateRequest .OnStaticSetting , UpdateSettingsClusterStateUpdateRequest > requestFactory =
55
+ onStaticSetting -> new UpdateSettingsClusterStateUpdateRequest (
56
+ TEST_REQUEST_TIMEOUT ,
57
+ TimeValue .ZERO ,
58
+ Settings .builder ().put ("index.codec" , "FastDecompressionCompressingStoredFieldsData" ).build (),
59
+ UpdateSettingsClusterStateUpdateRequest .OnExisting .OVERWRITE ,
60
+ onStaticSetting ,
61
+ indices
62
+ );
54
63
55
64
// First make sure it fails if reopenShards is not set on the request:
56
65
AtomicBoolean expectedFailureOccurred = new AtomicBoolean (false );
57
- metadataUpdateSettingsService .updateSettings (request , new ActionListener <>() {
58
- @ Override
59
- public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
60
- fail ("Should have failed updating a non-dynamic setting without reopenShards set to true" );
61
- }
66
+ metadataUpdateSettingsService .updateSettings (
67
+ requestFactory .apply (UpdateSettingsClusterStateUpdateRequest .OnStaticSetting .REJECT ),
68
+ new ActionListener <>() {
69
+ @ Override
70
+ public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
71
+ fail ("Should have failed updating a non-dynamic setting without reopenShards set to true" );
72
+ }
62
73
63
- @ Override
64
- public void onFailure (Exception e ) {
65
- expectedFailureOccurred .set (true );
74
+ @ Override
75
+ public void onFailure (Exception e ) {
76
+ expectedFailureOccurred .set (true );
77
+ }
66
78
}
67
- } );
79
+ );
68
80
assertBusy (() -> assertThat (expectedFailureOccurred .get (), equalTo (true )));
69
81
70
82
// Now we set reopenShards and expect it to work:
71
- request .reopenShards (true );
72
83
AtomicBoolean success = new AtomicBoolean (false );
73
- metadataUpdateSettingsService .updateSettings (request , new ActionListener <>() {
74
- @ Override
75
- public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
76
- success .set (true );
77
- }
84
+ metadataUpdateSettingsService .updateSettings (
85
+ requestFactory .apply (UpdateSettingsClusterStateUpdateRequest .OnStaticSetting .REOPEN_INDICES ),
86
+ new ActionListener <>() {
87
+ @ Override
88
+ public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
89
+ success .set (true );
90
+ }
78
91
79
- @ Override
80
- public void onFailure (Exception e ) {
81
- fail (e );
92
+ @ Override
93
+ public void onFailure (Exception e ) {
94
+ fail (e );
95
+ }
82
96
}
83
- } );
97
+ );
84
98
assertBusy (() -> assertThat (success .get (), equalTo (true )));
85
99
86
100
// Now we look into the IndexShard objects to make sure that the code was actually updated (vs just the setting):
@@ -110,16 +124,23 @@ public void testThatNonDynamicSettingChangesDoNotUnncessesarilyCauseReopens() th
110
124
MetadataUpdateSettingsService metadataUpdateSettingsService = internalCluster ().getCurrentMasterNodeInstance (
111
125
MetadataUpdateSettingsService .class
112
126
);
113
- UpdateSettingsClusterStateUpdateRequest request = new UpdateSettingsClusterStateUpdateRequest ().ackTimeout (TimeValue .ZERO );
114
- List <Index > indices = new ArrayList <>();
127
+ List <Index > indicesList = new ArrayList <>();
115
128
for (IndicesService indicesService : internalCluster ().getInstances (IndicesService .class )) {
116
129
for (IndexService indexService : indicesService ) {
117
- indices .add (indexService .index ());
130
+ indicesList .add (indexService .index ());
118
131
}
119
132
}
120
- request .indices (indices .toArray (Index .EMPTY_ARRAY ));
121
- request .settings (Settings .builder ().put ("index.codec" , "FastDecompressionCompressingStoredFieldsData" ).build ());
122
- request .reopenShards (true );
133
+ final var indices = indicesList .toArray (Index .EMPTY_ARRAY );
134
+
135
+ final Function <Settings .Builder , UpdateSettingsClusterStateUpdateRequest > requestFactory =
136
+ settings -> new UpdateSettingsClusterStateUpdateRequest (
137
+ TEST_REQUEST_TIMEOUT ,
138
+ TimeValue .ZERO ,
139
+ settings .build (),
140
+ UpdateSettingsClusterStateUpdateRequest .OnExisting .OVERWRITE ,
141
+ UpdateSettingsClusterStateUpdateRequest .OnStaticSetting .REOPEN_INDICES ,
142
+ indices
143
+ );
123
144
124
145
ClusterService clusterService = internalCluster ().getInstance (ClusterService .class );
125
146
AtomicBoolean shardsUnassigned = new AtomicBoolean (false );
@@ -142,47 +163,49 @@ public void testThatNonDynamicSettingChangesDoNotUnncessesarilyCauseReopens() th
142
163
143
164
AtomicBoolean success = new AtomicBoolean (false );
144
165
// Make the first request, just to set things up:
145
- metadataUpdateSettingsService .updateSettings (request , new ActionListener <>() {
146
- @ Override
147
- public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
148
- success .set (true );
149
- }
166
+ metadataUpdateSettingsService .updateSettings (
167
+ requestFactory .apply (Settings .builder ().put ("index.codec" , "FastDecompressionCompressingStoredFieldsData" )),
168
+ new ActionListener <>() {
169
+ @ Override
170
+ public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
171
+ success .set (true );
172
+ }
150
173
151
- @ Override
152
- public void onFailure (Exception e ) {
153
- fail (e );
174
+ @ Override
175
+ public void onFailure (Exception e ) {
176
+ fail (e );
177
+ }
154
178
}
155
- } );
179
+ );
156
180
assertBusy (() -> assertThat (success .get (), equalTo (true )));
157
181
assertBusy (() -> assertThat (expectedSettingsChangeInClusterState .get (), equalTo (true )));
158
182
assertThat (shardsUnassigned .get (), equalTo (true ));
159
183
160
184
assertBusy (() -> assertThat (hasUnassignedShards (clusterService .state (), indexName ), equalTo (false )));
161
185
162
- // Same request, except now we'll also set the dynamic "index.max_result_window" setting:
163
- request .settings (
164
- Settings .builder ()
165
- .put ("index.codec" , "FastDecompressionCompressingStoredFieldsData" )
166
- .put ("index.max_result_window" , "1500" )
167
- .build ()
168
- );
169
186
success .set (false );
170
187
expectedSettingsChangeInClusterState .set (false );
171
188
shardsUnassigned .set (false );
172
189
expectedSetting .set ("index.max_result_window" );
173
190
expectedSettingValue .set ("1500" );
174
191
// Making this request ought to add this new setting but not unassign the shards:
175
- metadataUpdateSettingsService .updateSettings (request , new ActionListener <>() {
176
- @ Override
177
- public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
178
- success .set (true );
179
- }
192
+ metadataUpdateSettingsService .updateSettings (
193
+ // Same request, except now we'll also set the dynamic "index.max_result_window" setting:
194
+ requestFactory .apply (
195
+ Settings .builder ().put ("index.codec" , "FastDecompressionCompressingStoredFieldsData" ).put ("index.max_result_window" , "1500" )
196
+ ),
197
+ new ActionListener <>() {
198
+ @ Override
199
+ public void onResponse (AcknowledgedResponse acknowledgedResponse ) {
200
+ success .set (true );
201
+ }
180
202
181
- @ Override
182
- public void onFailure (Exception e ) {
183
- fail (e );
203
+ @ Override
204
+ public void onFailure (Exception e ) {
205
+ fail (e );
206
+ }
184
207
}
185
- } );
208
+ );
186
209
187
210
assertBusy (() -> assertThat (success .get (), equalTo (true )));
188
211
assertBusy (() -> assertThat (expectedSettingsChangeInClusterState .get (), equalTo (true )));
0 commit comments