Skip to content

Commit

Permalink
Add validation to group settings
Browse files Browse the repository at this point in the history
  • Loading branch information
markwu-sde committed Feb 7, 2025
1 parent 058e9d8 commit 9f50028
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/org/opensearch/knn/index/KNNSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,19 @@ public class KNNSettings {
/**
* Group setting that manages node-level circuit breaker configurations based on node tiers.
* Settings under this group define memory limits for different node classifications.
* Validation of limit occurs before the setting is retrieved.
*/
put(
KNN_MEMORY_CIRCUIT_BREAKER_LIMIT_PREFIX,
Setting.groupSetting(KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_LIMIT_PREFIX, NodeScope, Dynamic)
Setting.groupSetting(KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_LIMIT_PREFIX, settings -> {
settings.keySet()
.forEach(
(limit) -> parseknnMemoryCircuitBreakerValue(
settings.get(limit),
KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_CLUSTER_LIMIT
)
);
}, NodeScope, Dynamic)
);

/**
Expand All @@ -409,7 +418,7 @@ public class KNNSettings {
new Setting<>(
KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_CLUSTER_LIMIT,
KNNSettings.KNN_DEFAULT_MEMORY_CIRCUIT_BREAKER_LIMIT,
(s) -> parseknnMemoryCircuitBreakerValue(s, null, KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_CLUSTER_LIMIT),
(s) -> parseknnMemoryCircuitBreakerValue(s, KNNSettings.KNN_MEMORY_CIRCUIT_BREAKER_CLUSTER_LIMIT),
NodeScope,
Dynamic
)
Expand Down Expand Up @@ -766,6 +775,10 @@ public void initialize(Client client, ClusterService clusterService) {
setSettingsUpdateConsumers();
}

public static ByteSizeValue parseknnMemoryCircuitBreakerValue(String sValue, String settingName) {
return parseknnMemoryCircuitBreakerValue(sValue, null, settingName);
}

public static ByteSizeValue parseknnMemoryCircuitBreakerValue(String sValue, ByteSizeValue defaultValue, String settingName) {
settingName = Objects.requireNonNull(settingName);
if (sValue != null && sValue.endsWith("%")) {
Expand Down

0 comments on commit 9f50028

Please sign in to comment.