3737import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsRequestBuilder ;
3838import org .opensearch .action .admin .cluster .settings .ClusterUpdateSettingsResponse ;
3939import org .opensearch .action .admin .cluster .state .ClusterStateResponse ;
40+ import org .opensearch .cluster .metadata .IndexMetadata ;
4041import org .opensearch .cluster .metadata .Metadata ;
4142import org .opensearch .cluster .routing .allocation .decider .EnableAllocationDecider ;
43+ import org .opensearch .common .settings .AbstractScopedSettings ;
44+ import org .opensearch .common .settings .ClusterSettings ;
4245import org .opensearch .common .settings .Setting ;
4346import org .opensearch .common .settings .Settings ;
4447import org .opensearch .common .settings .SettingsException ;
4548import org .opensearch .common .unit .TimeValue ;
4649import org .opensearch .core .common .unit .ByteSizeUnit ;
50+ import org .opensearch .indices .IndicesQueryCache ;
4751import org .opensearch .indices .recovery .RecoverySettings ;
4852import org .opensearch .test .OpenSearchIntegTestCase ;
4953import org .junit .After ;
5054
5155import java .util .Arrays ;
56+ import java .util .HashMap ;
57+ import java .util .List ;
58+ import java .util .Map ;
59+ import java .util .regex .Matcher ;
60+ import java .util .regex .Pattern ;
5261
5362import static org .opensearch .cluster .routing .allocation .DiskThresholdSettings .CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING ;
5463import static org .opensearch .cluster .routing .allocation .decider .ThrottlingAllocationDecider .CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING ;
@@ -72,6 +81,14 @@ public void cleanup() throws Exception {
7281 );
7382 }
7483
84+ @ Override
85+ protected Settings nodeSettings (int nodeOrdinal ) {
86+ return Settings .builder ()
87+ .put (super .nodeSettings (nodeOrdinal ))
88+ .put (IndicesQueryCache .INDICES_QUERIES_CACHE_ALL_SEGMENTS_SETTING .getKey (), false )
89+ .build ();
90+ }
91+
7592 public void testClusterNonExistingSettingsUpdate () {
7693 String key1 = "no_idea_what_you_are_talking_about" ;
7794 int value1 = 10 ;
@@ -552,4 +569,39 @@ public void testUserMetadata() {
552569 }
553570 }
554571
572+ public void testWithMultipleIndexCreationAndVerifySettingRegisteredOnce () {
573+ int randomInt = randomIntBetween (10 , 50 );
574+ for (int i = 0 ; i < randomInt ; i ++) {
575+ String indexName = "test" + i ;
576+ assertAcked (prepareCreate (indexName ).setSettings (Settings .builder ().put (IndexMetadata .SETTING_BLOCKS_METADATA , true )));
577+ assertBlocked (client ().admin ().indices ().prepareGetSettings (indexName ), IndexMetadata .INDEX_METADATA_BLOCK );
578+ disableIndexBlock (indexName , IndexMetadata .SETTING_BLOCKS_METADATA );
579+ }
580+ Map <String , Boolean > settingToVerify = new HashMap <>();
581+ settingToVerify .put ("indices.fielddata.cache.size" , false );
582+ settingToVerify .put ("indices.queries.cache.skip_cache_factor" , false );
583+ ClusterSettings clusterSettings = clusterService ().getClusterSettings ();
584+ List <AbstractScopedSettings .SettingUpdater <?>> settingUpgraders = clusterSettings .getSettingUpdaters ();
585+ for (AbstractScopedSettings .SettingUpdater <?> settingUpgrader : settingUpgraders ) {
586+ String input = settingUpgrader .toString ();
587+ // Trying to fetch key value as there is no other way
588+ Pattern p = Pattern .compile ("\" key\" \\ s*:\\ s*\" ([^\" ]+)\" " );
589+ Matcher m = p .matcher (input );
590+ String key = "" ;
591+ if (m .find ()) {
592+ key = m .group (1 );
593+ }
594+ if (settingToVerify .containsKey (key ) && !settingToVerify .get (key )) {
595+ settingToVerify .put (key , true );
596+ } else if (settingToVerify .containsKey (key ) && settingToVerify .get (key )) {
597+ fail ("Setting registered multiple times" );
598+ }
599+ }
600+ for (Map .Entry <String , Boolean > entry : settingToVerify .entrySet ()) {
601+ if (!entry .getValue ()) {
602+ fail ("Was not able to read this setting: " + entry .getKey ());
603+ }
604+ }
605+ }
606+
555607}
0 commit comments