17
17
import org .elasticsearch .action .index .IndexRequest ;
18
18
import org .elasticsearch .action .search .SearchRequest ;
19
19
import org .elasticsearch .action .search .SearchResponse ;
20
- import org .elasticsearch .action .support .ActiveShardCount ;
21
20
import org .elasticsearch .analysis .common .CommonAnalysisPlugin ;
22
21
import org .elasticsearch .cluster .ClusterState ;
23
22
import org .elasticsearch .cluster .metadata .MappingMetaData ;
@@ -313,10 +312,7 @@ public void testFollowIndexAndCloseNode() throws Exception {
313
312
internalCluster ().ensureAtLeastNumDataNodes (3 );
314
313
String leaderIndexSettings = getIndexSettings (3 , 1 , singletonMap (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), "true" ));
315
314
assertAcked (client ().admin ().indices ().prepareCreate ("index1" ).setSource (leaderIndexSettings , XContentType .JSON ));
316
-
317
- String followerIndexSettings = getIndexSettings (3 , 1 , singletonMap (CcrSettings .CCR_FOLLOWING_INDEX_SETTING .getKey (), "true" ));
318
- assertAcked (client ().admin ().indices ().prepareCreate ("index2" ).setSource (followerIndexSettings , XContentType .JSON ));
319
- ensureGreen ("index1" , "index2" );
315
+ ensureGreen ("index1" );
320
316
321
317
AtomicBoolean run = new AtomicBoolean (true );
322
318
Thread thread = new Thread (() -> {
@@ -338,7 +334,7 @@ public void testFollowIndexAndCloseNode() throws Exception {
338
334
final FollowIndexAction .Request followRequest = new FollowIndexAction .Request ("index1" , "index2" , randomIntBetween (32 , 2048 ),
339
335
randomIntBetween (2 , 10 ), Long .MAX_VALUE , randomIntBetween (2 , 10 ),
340
336
FollowIndexAction .DEFAULT_MAX_WRITE_BUFFER_SIZE , TimeValue .timeValueMillis (500 ), TimeValue .timeValueMillis (10 ));
341
- client ().execute (FollowIndexAction .INSTANCE , followRequest ).get ();
337
+ client ().execute (CreateAndFollowIndexAction .INSTANCE , new CreateAndFollowIndexAction . Request ( followRequest ) ).get ();
342
338
343
339
long maxNumDocsReplicated = Math .min (1000 , randomLongBetween (followRequest .getMaxBatchOperationCount (),
344
340
followRequest .getMaxBatchOperationCount () * 10 ));
@@ -415,33 +411,6 @@ public void testFollowNonExistentIndex() throws Exception {
415
411
expectThrows (IndexNotFoundException .class , () -> client ().execute (FollowIndexAction .INSTANCE , followRequest3 ).actionGet ());
416
412
}
417
413
418
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/33379" )
419
- public void testValidateFollowingIndexSettings () throws Exception {
420
- assertAcked (client ().admin ().indices ().prepareCreate ("test-leader" )
421
- .setSettings (Settings .builder ().put (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), true )));
422
- // TODO: indexing should be optional but the current mapping logic requires for now.
423
- client ().prepareIndex ("test-leader" , "doc" , "id" ).setSource ("{\" f\" : \" v\" }" , XContentType .JSON ).get ();
424
- assertAcked (client ().admin ().indices ().prepareCreate ("test-follower" ).get ());
425
- IllegalArgumentException followError = expectThrows (IllegalArgumentException .class , () -> client ().execute (
426
- FollowIndexAction .INSTANCE , createFollowRequest ("test-leader" , "test-follower" )).actionGet ());
427
- assertThat (followError .getMessage (), equalTo ("the following index [test-follower] is not ready to follow;" +
428
- " the setting [index.xpack.ccr.following_index] must be enabled." ));
429
- // updating the `following_index` with an open index must not be allowed.
430
- IllegalArgumentException updateError = expectThrows (IllegalArgumentException .class , () -> {
431
- client ().admin ().indices ().prepareUpdateSettings ("test-follower" )
432
- .setSettings (Settings .builder ().put (CcrSettings .CCR_FOLLOWING_INDEX_SETTING .getKey (), true )).get ();
433
- });
434
- assertThat (updateError .getMessage (), containsString ("Can't update non dynamic settings " +
435
- "[[index.xpack.ccr.following_index]] for open indices [[test-follower/" ));
436
- assertAcked (client ().admin ().indices ().prepareClose ("test-follower" ));
437
- assertAcked (client ().admin ().indices ().prepareUpdateSettings ("test-follower" )
438
- .setSettings (Settings .builder ().put (CcrSettings .CCR_FOLLOWING_INDEX_SETTING .getKey (), true )));
439
- assertAcked (client ().admin ().indices ().prepareOpen ("test-follower" ).setWaitForActiveShards (ActiveShardCount .DEFAULT ));
440
- assertAcked (client ().execute (FollowIndexAction .INSTANCE ,
441
- createFollowRequest ("test-leader" , "test-follower" )).actionGet ());
442
- unfollowIndex ("test-follower" );
443
- }
444
-
445
414
public void testFollowIndex_lowMaxTranslogBytes () throws Exception {
446
415
final String leaderIndexSettings = getIndexSettings (1 , between (0 , 1 ),
447
416
singletonMap (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), "true" ));
@@ -476,6 +445,37 @@ public void testFollowIndex_lowMaxTranslogBytes() throws Exception {
476
445
unfollowIndex ("index2" );
477
446
}
478
447
448
+ public void testDontFollowTheWrongIndex () throws Exception {
449
+ String leaderIndexSettings = getIndexSettings (1 , 0 ,
450
+ Collections .singletonMap (IndexSettings .INDEX_SOFT_DELETES_SETTING .getKey (), "true" ));
451
+ assertAcked (client ().admin ().indices ().prepareCreate ("index1" ).setSource (leaderIndexSettings , XContentType .JSON ));
452
+ ensureGreen ("index1" );
453
+ assertAcked (client ().admin ().indices ().prepareCreate ("index3" ).setSource (leaderIndexSettings , XContentType .JSON ));
454
+ ensureGreen ("index3" );
455
+
456
+ FollowIndexAction .Request followRequest = new FollowIndexAction .Request ("index1" , "index2" , 1024 , 1 , 1024L ,
457
+ 1 , 10240 , TimeValue .timeValueMillis (500 ), TimeValue .timeValueMillis (10 ));
458
+ CreateAndFollowIndexAction .Request createAndFollowRequest = new CreateAndFollowIndexAction .Request (followRequest );
459
+ client ().execute (CreateAndFollowIndexAction .INSTANCE , createAndFollowRequest ).get ();
460
+
461
+ followRequest = new FollowIndexAction .Request ("index3" , "index4" , 1024 , 1 , 1024L ,
462
+ 1 , 10240 , TimeValue .timeValueMillis (500 ), TimeValue .timeValueMillis (10 ));
463
+ createAndFollowRequest = new CreateAndFollowIndexAction .Request (followRequest );
464
+ client ().execute (CreateAndFollowIndexAction .INSTANCE , createAndFollowRequest ).get ();
465
+ unfollowIndex ("index2" , "index4" );
466
+
467
+ FollowIndexAction .Request wrongRequest1 = new FollowIndexAction .Request ("index1" , "index4" , 1024 , 1 , 1024L ,
468
+ 1 , 10240 , TimeValue .timeValueMillis (500 ), TimeValue .timeValueMillis (10 ));
469
+ Exception e = expectThrows (IllegalArgumentException .class ,
470
+ () -> client ().execute (FollowIndexAction .INSTANCE , wrongRequest1 ).actionGet ());
471
+ assertThat (e .getMessage (), containsString ("follow index [index4] should reference" ));
472
+
473
+ FollowIndexAction .Request wrongRequest2 = new FollowIndexAction .Request ("index3" , "index2" , 1024 , 1 , 1024L ,
474
+ 1 , 10240 , TimeValue .timeValueMillis (500 ), TimeValue .timeValueMillis (10 ));
475
+ e = expectThrows (IllegalArgumentException .class , () -> client ().execute (FollowIndexAction .INSTANCE , wrongRequest2 ).actionGet ());
476
+ assertThat (e .getMessage (), containsString ("follow index [index2] should reference" ));
477
+ }
478
+
479
479
private CheckedRunnable <Exception > assertTask (final int numberOfPrimaryShards , final Map <ShardId , Long > numDocsPerShard ) {
480
480
return () -> {
481
481
final ClusterState clusterState = client ().admin ().cluster ().prepareState ().get ().getState ();
@@ -512,10 +512,12 @@ private CheckedRunnable<Exception> assertTask(final int numberOfPrimaryShards, f
512
512
};
513
513
}
514
514
515
- private void unfollowIndex (String index ) throws Exception {
516
- final UnfollowIndexAction .Request unfollowRequest = new UnfollowIndexAction .Request ();
517
- unfollowRequest .setFollowIndex (index );
518
- client ().execute (UnfollowIndexAction .INSTANCE , unfollowRequest ).get ();
515
+ private void unfollowIndex (String ... indices ) throws Exception {
516
+ for (String index : indices ) {
517
+ final UnfollowIndexAction .Request unfollowRequest = new UnfollowIndexAction .Request ();
518
+ unfollowRequest .setFollowIndex (index );
519
+ client ().execute (UnfollowIndexAction .INSTANCE , unfollowRequest ).get ();
520
+ }
519
521
assertBusy (() -> {
520
522
final ClusterState clusterState = client ().admin ().cluster ().prepareState ().get ().getState ();
521
523
final PersistentTasksCustomMetaData tasks = clusterState .getMetaData ().custom (PersistentTasksCustomMetaData .TYPE );
0 commit comments