29
29
import org .elasticsearch .cluster .service .ClusterService ;
30
30
import org .elasticsearch .common .Strings ;
31
31
import org .elasticsearch .common .settings .Settings ;
32
+ import org .elasticsearch .indices .AssociatedIndexDescriptor ;
32
33
import org .elasticsearch .indices .SystemIndexDescriptor ;
33
34
import org .elasticsearch .plugins .Plugin ;
34
35
import org .elasticsearch .plugins .SystemIndexPlugin ;
@@ -90,6 +91,18 @@ public void testMigrateInternalManagedSystemIndex() throws Exception {
90
91
createSystemIndexForDescriptor (EXTERNAL_MANAGED );
91
92
createSystemIndexForDescriptor (EXTERNAL_UNMANAGED );
92
93
94
+ CreateIndexRequestBuilder createRequest = prepareCreate (ASSOCIATED_INDEX_NAME );
95
+ createRequest .setWaitForActiveShards (ActiveShardCount .ALL );
96
+ createRequest .setSettings (
97
+ Settings .builder ()
98
+ .put ("index.version.created" , NEEDS_UPGRADE_VERSION )
99
+ .put (IndexMetadata .INDEX_NUMBER_OF_REPLICAS_SETTING .getKey (), 0 )
100
+ .put ("index.hidden" , true ) // So we don't get a warning
101
+ .build ()
102
+ );
103
+ CreateIndexResponse response = createRequest .get ();
104
+ assertTrue (response .isShardsAcknowledged ());
105
+
93
106
ensureGreen ();
94
107
95
108
SetOnce <Boolean > preUpgradeHookCalled = new SetOnce <>();
@@ -226,11 +239,16 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
226
239
CreateIndexRequestBuilder createRequest = prepareCreate (indexName );
227
240
createRequest .setWaitForActiveShards (ActiveShardCount .ALL );
228
241
if (descriptor .getSettings () != null ) {
229
- createRequest .setSettings (Settings .builder ().put ("index.version.created" , Version .CURRENT ).build ());
242
+ createRequest .setSettings (
243
+ Settings .builder ()
244
+ .put ("index.version.created" , Version .CURRENT )
245
+ .put (IndexMetadata .INDEX_NUMBER_OF_REPLICAS_SETTING .getKey (), 0 )
246
+ .build ()
247
+ );
230
248
} else {
231
249
createRequest .setSettings (
232
250
createSimpleSettings (
233
- Version . V_7_0_0 ,
251
+ NEEDS_UPGRADE_VERSION ,
234
252
descriptor .isInternal () ? INTERNAL_UNMANAGED_FLAG_VALUE : EXTERNAL_UNMANAGED_FLAG_VALUE
235
253
)
236
254
);
@@ -258,6 +276,7 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
258
276
static final String ORIGIN = FeatureMigrationIT .class .getSimpleName ();
259
277
static final String FlAG_SETTING_KEY = IndexMetadata .INDEX_PRIORITY_SETTING .getKey ();
260
278
static final int INDEX_DOC_COUNT = 100 ; // arbitrarily chosen
279
+ public static final Version NEEDS_UPGRADE_VERSION = Version .V_7_0_0 ;
261
280
262
281
static final int INTERNAL_MANAGED_FLAG_VALUE = 1 ;
263
282
static final int INTERNAL_UNMANAGED_FLAG_VALUE = 2 ;
@@ -268,12 +287,12 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
268
287
.setAliasName (".internal-managed-alias" )
269
288
.setPrimaryIndex (".int-man-old" )
270
289
.setType (SystemIndexDescriptor .Type .INTERNAL_MANAGED )
271
- .setSettings (createSimpleSettings (Version . V_7_0_0 , INTERNAL_MANAGED_FLAG_VALUE ))
290
+ .setSettings (createSimpleSettings (NEEDS_UPGRADE_VERSION , INTERNAL_MANAGED_FLAG_VALUE ))
272
291
.setMappings (createSimpleMapping (true , true ))
273
292
.setOrigin (ORIGIN )
274
293
.setVersionMetaKey (VERSION_META_KEY )
275
294
.setAllowedElasticProductOrigins (Collections .emptyList ())
276
- .setMinimumNodeVersion (Version . V_7_0_0 )
295
+ .setMinimumNodeVersion (NEEDS_UPGRADE_VERSION )
277
296
.setPriorSystemIndexDescriptors (Collections .emptyList ())
278
297
.build ();
279
298
static final SystemIndexDescriptor INTERNAL_UNMANAGED = SystemIndexDescriptor .builder ()
@@ -282,20 +301,20 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
282
301
.setOrigin (ORIGIN )
283
302
.setVersionMetaKey (VERSION_META_KEY )
284
303
.setAllowedElasticProductOrigins (Collections .emptyList ())
285
- .setMinimumNodeVersion (Version . V_7_0_0 )
304
+ .setMinimumNodeVersion (NEEDS_UPGRADE_VERSION )
286
305
.setPriorSystemIndexDescriptors (Collections .emptyList ())
287
306
.build ();
288
307
static final SystemIndexDescriptor EXTERNAL_MANAGED = SystemIndexDescriptor .builder ()
289
308
.setIndexPattern (".ext-man-*" )
290
309
.setAliasName (".external-managed-alias" )
291
310
.setPrimaryIndex (".ext-man-old" )
292
311
.setType (SystemIndexDescriptor .Type .EXTERNAL_MANAGED )
293
- .setSettings (createSimpleSettings (Version . V_7_0_0 , EXTERNAL_MANAGED_FLAG_VALUE ))
312
+ .setSettings (createSimpleSettings (NEEDS_UPGRADE_VERSION , EXTERNAL_MANAGED_FLAG_VALUE ))
294
313
.setMappings (createSimpleMapping (true , false ))
295
314
.setOrigin (ORIGIN )
296
315
.setVersionMetaKey (VERSION_META_KEY )
297
316
.setAllowedElasticProductOrigins (Collections .singletonList (ORIGIN ))
298
- .setMinimumNodeVersion (Version . V_7_0_0 )
317
+ .setMinimumNodeVersion (NEEDS_UPGRADE_VERSION )
299
318
.setPriorSystemIndexDescriptors (Collections .emptyList ())
300
319
.build ();
301
320
static final SystemIndexDescriptor EXTERNAL_UNMANAGED = SystemIndexDescriptor .builder ()
@@ -304,9 +323,10 @@ public void createSystemIndexForDescriptor(SystemIndexDescriptor descriptor) thr
304
323
.setOrigin (ORIGIN )
305
324
.setVersionMetaKey (VERSION_META_KEY )
306
325
.setAllowedElasticProductOrigins (Collections .singletonList (ORIGIN ))
307
- .setMinimumNodeVersion (Version . V_7_0_0 )
326
+ .setMinimumNodeVersion (NEEDS_UPGRADE_VERSION )
308
327
.setPriorSystemIndexDescriptors (Collections .emptyList ())
309
328
.build ();
329
+ static final String ASSOCIATED_INDEX_NAME = ".my-associated-idx" ;
310
330
311
331
static Settings createSimpleSettings (Version creationVersion , int flagSettingValue ) {
312
332
return Settings .builder ()
@@ -367,6 +387,12 @@ public Collection<SystemIndexDescriptor> getSystemIndexDescriptors(Settings sett
367
387
return Arrays .asList (INTERNAL_MANAGED , INTERNAL_UNMANAGED , EXTERNAL_MANAGED , EXTERNAL_UNMANAGED );
368
388
}
369
389
390
+ @ Override
391
+ public Collection <AssociatedIndexDescriptor > getAssociatedIndexDescriptors () {
392
+
393
+ return Collections .singletonList (new AssociatedIndexDescriptor (ASSOCIATED_INDEX_NAME , TestPlugin .class .getCanonicalName ()));
394
+ }
395
+
370
396
@ Override
371
397
public void prepareForIndicesMigration (ClusterService clusterService , Client client , ActionListener <Map <String , Object >> listener ) {
372
398
listener .onResponse (preMigrationHook .get ().apply (clusterService .state ()));
0 commit comments