@@ -472,45 +472,96 @@ public void testExistingTempFiles() throws IOException {
472
472
}
473
473
}
474
474
475
- public void testEnsureNoShardData () throws IOException {
475
+ public void testEnsureNoShardDataOrIndexMetaData () throws IOException {
476
476
Settings settings = buildEnvSettings (Settings .EMPTY );
477
477
Index index = new Index ("test" , "testUUID" );
478
478
479
+ // build settings using same path.data as original but with node.data=false and node.master=false
480
+ Settings noDataNoMasterSettings = Settings .builder ()
481
+ .put (settings )
482
+ .put (Node .NODE_DATA_SETTING .getKey (), false )
483
+ .put (Node .NODE_MASTER_SETTING .getKey (), false )
484
+ .build ();
485
+
486
+ // test that we can create data=false and master=false with no meta information
487
+ newNodeEnvironment (noDataNoMasterSettings ).close ();
488
+
489
+ Path indexPath ;
479
490
try (NodeEnvironment env = newNodeEnvironment (settings )) {
480
491
for (Path path : env .indexPaths (index )) {
481
492
Files .createDirectories (path .resolve (MetaDataStateFormat .STATE_DIR_NAME ));
482
493
}
494
+ indexPath = env .indexPaths (index )[0 ];
483
495
}
484
496
497
+ verifyFailsOnMetaData (noDataNoMasterSettings , indexPath );
498
+
485
499
// build settings using same path.data as original but with node.data=false
486
500
Settings noDataSettings = Settings .builder ()
487
501
.put (settings )
488
502
.put (Node .NODE_DATA_SETTING .getKey (), false ).build ();
489
503
490
504
String shardDataDirName = Integer .toString (randomInt (10 ));
491
- Path shardPath ;
492
505
493
- // test that we can create data=false env with only meta information
506
+ // test that we can create data=false env with only meta information. Also create shard data for following asserts
494
507
try (NodeEnvironment env = newNodeEnvironment (noDataSettings )) {
495
508
for (Path path : env .indexPaths (index )) {
496
509
Files .createDirectories (path .resolve (shardDataDirName ));
497
510
}
498
- shardPath = env .indexPaths (index )[0 ];
499
511
}
500
512
513
+ verifyFailsOnShardData (noDataSettings , indexPath , shardDataDirName );
514
+
515
+ // assert that we get the stricter message on meta-data when both conditions fail
516
+ verifyFailsOnMetaData (noDataNoMasterSettings , indexPath );
517
+
518
+ // build settings using same path.data as original but with node.master=false
519
+ Settings noMasterSettings = Settings .builder ()
520
+ .put (settings )
521
+ .put (Node .NODE_MASTER_SETTING .getKey (), false )
522
+ .build ();
523
+
524
+ // test that we can create master=false env regardless of data.
525
+ newNodeEnvironment (noMasterSettings ).close ();
526
+
527
+ // test that we can create data=true, master=true env. Also remove state dir to leave only shard data for following asserts
528
+ try (NodeEnvironment env = newNodeEnvironment (settings )) {
529
+ for (Path path : env .indexPaths (index )) {
530
+ Files .delete (path .resolve (MetaDataStateFormat .STATE_DIR_NAME ));
531
+ }
532
+ }
533
+
534
+ // assert that we fail on shard data even without the metadata dir.
535
+ verifyFailsOnShardData (noDataSettings , indexPath , shardDataDirName );
536
+ verifyFailsOnShardData (noDataNoMasterSettings , indexPath , shardDataDirName );
537
+ }
538
+
539
+ private void verifyFailsOnShardData (Settings settings , Path indexPath , String shardDataDirName ) {
501
540
IllegalStateException ex = expectThrows (IllegalStateException .class ,
502
541
"Must fail creating NodeEnvironment on a data path that has shard data if node.data=false" ,
503
- () -> newNodeEnvironment (noDataSettings ).close ());
542
+ () -> newNodeEnvironment (settings ).close ());
504
543
505
544
assertThat (ex .getMessage (),
506
- containsString (shardPath .resolve (shardDataDirName ).toAbsolutePath ().toString ()));
545
+ containsString (indexPath .resolve (shardDataDirName ).toAbsolutePath ().toString ()));
507
546
assertThat (ex .getMessage (),
508
547
startsWith ("Node is started with "
509
548
+ Node .NODE_DATA_SETTING .getKey ()
510
549
+ "=false, but has shard data" ));
550
+ }
511
551
512
- // test that we can create data=true env
513
- newNodeEnvironment (settings ).close ();
552
+ private void verifyFailsOnMetaData (Settings settings , Path indexPath ) {
553
+ IllegalStateException ex = expectThrows (IllegalStateException .class ,
554
+ "Must fail creating NodeEnvironment on a data path that has index meta-data if node.data=false and node.master=false" ,
555
+ () -> newNodeEnvironment (settings ).close ());
556
+
557
+ assertThat (ex .getMessage (),
558
+ containsString (indexPath .resolve (MetaDataStateFormat .STATE_DIR_NAME ).toAbsolutePath ().toString ()));
559
+ assertThat (ex .getMessage (),
560
+ startsWith ("Node is started with "
561
+ + Node .NODE_DATA_SETTING .getKey ()
562
+ + "=false and "
563
+ + Node .NODE_MASTER_SETTING .getKey ()
564
+ + "=false, but has index metadata" ));
514
565
}
515
566
516
567
/** Converts an array of Strings to an array of Paths, adding an additional child if specified */
0 commit comments