Skip to content

Commit 2b6d266

Browse files
authored
Fix duplicate registration of FieldDataCache dynamic setting (#20140)
Signed-off-by: Sagar Upadhyaya <[email protected]> Signed-off-by: Sagar <[email protected]>
1 parent f76826c commit 2b6d266

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
9898
- Fix toBuilder method in EngineConfig to include mergedSegmentTransferTracker([#20105](https://github.com/opensearch-project/OpenSearch/pull/20105))
9999
- Fixed handling of property index in BulkRequest during deserialization ([#20132](https://github.com/opensearch-project/OpenSearch/pull/20132))
100100
- Fix negative CPU usage values in node stats ([#19120](https://github.com/opensearch-project/OpenSearch/issues/19120))
101+
- Fix duplicate registration of FieldDataCache dynamic setting ([20140](https://github.com/opensearch-project/OpenSearch/pull/20140))
101102

102103
### Dependencies
103104
- Bump Apache Lucene from 10.3.1 to 10.3.2 ([#20026](https://github.com/opensearch-project/OpenSearch/pull/20026))

server/src/internalClusterTest/java/org/opensearch/cluster/settings/ClusterSettingsIT.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,27 @@
3737
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder;
3838
import org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse;
3939
import org.opensearch.action.admin.cluster.state.ClusterStateResponse;
40+
import org.opensearch.cluster.metadata.IndexMetadata;
4041
import org.opensearch.cluster.metadata.Metadata;
4142
import org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider;
43+
import org.opensearch.common.settings.AbstractScopedSettings;
44+
import org.opensearch.common.settings.ClusterSettings;
4245
import org.opensearch.common.settings.Setting;
4346
import org.opensearch.common.settings.Settings;
4447
import org.opensearch.common.settings.SettingsException;
4548
import org.opensearch.common.unit.TimeValue;
4649
import org.opensearch.core.common.unit.ByteSizeUnit;
50+
import org.opensearch.indices.IndicesQueryCache;
4751
import org.opensearch.indices.recovery.RecoverySettings;
4852
import org.opensearch.test.OpenSearchIntegTestCase;
4953
import org.junit.After;
5054

5155
import 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

5362
import static org.opensearch.cluster.routing.allocation.DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING;
5463
import 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
}

server/src/main/java/org/opensearch/common/settings/AbstractScopedSettings.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ protected AbstractScopedSettings(
123123
this.keySettings = keySettings;
124124
}
125125

126+
/**
127+
* Returns the list of setting updaters registered in this scope.
128+
* @return an unmodifiable view of the setting updaters
129+
*/
130+
public List<SettingUpdater<?>> getSettingUpdaters() {
131+
return Collections.unmodifiableList(settingUpdaters);
132+
}
133+
126134
protected void validateSettingKey(Setting<?> setting) {
127135
if (isValidKey(setting.getKey()) == false
128136
&& (setting.isGroupSetting() && isValidGroupKey(setting.getKey()) || isValidAffixKey(setting.getKey())) == false

server/src/main/java/org/opensearch/indices/IndicesService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,6 @@ public synchronized MapperService createIndexMapperService(IndexMetadata indexMe
12321232
public synchronized void verifyIndexMetadata(IndexMetadata metadata, IndexMetadata metadataUpdate) throws IOException {
12331233
final List<Closeable> closeables = new ArrayList<>();
12341234
try {
1235-
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {
1236-
}, clusterService, threadPool);
1237-
closeables.add(indicesFieldDataCache);
1238-
IndicesQueryCache indicesQueryCache = new IndicesQueryCache(settings, clusterService.getClusterSettings());
1239-
closeables.add(indicesQueryCache);
12401235
// this will also fail if some plugin fails etc. which is nice since we can verify that early
12411236
final IndexService service = createIndexService(
12421237
METADATA_VERIFICATION,

0 commit comments

Comments
 (0)