-
Notifications
You must be signed in to change notification settings - Fork 448
Support shared RocksDB rate limiter in Fluss #2178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
platinumhamburg
wants to merge
3
commits into
apache:main
Choose a base branch
from
platinumhamburg:ratelimiter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
fluss-common/src/main/java/org/apache/fluss/config/cluster/ConfigValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.config.cluster; | ||
|
|
||
| import org.apache.fluss.annotation.PublicEvolving; | ||
| import org.apache.fluss.exception.ConfigException; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Validator for a single dynamic configuration key. | ||
| * | ||
| * <p>Unlike {@link ServerReconfigurable}, validators are stateless and only perform validation | ||
| * logic without requiring component instances. This allows coordinators to validate configurations | ||
| * for components they don't run (e.g., KvManager). | ||
| * | ||
| * <p>Example use case: CoordinatorServer needs to validate KV-related configurations even though it | ||
| * doesn't have a KvManager instance. A {@link ConfigValidator} can be registered on both | ||
| * CoordinatorServer (for validation) and TabletServer (for both validation and actual | ||
| * reconfiguration via {@link ServerReconfigurable}). | ||
| * | ||
| * <p>Each validator monitors a single configuration key. The validator will only be invoked when | ||
| * that specific key changes, improving validation efficiency. | ||
| * | ||
| * <p>This interface is designed to be stateless and thread-safe. Implementations should not rely on | ||
| * any mutable component state. | ||
| */ | ||
| @PublicEvolving | ||
| public interface ConfigValidator { | ||
|
|
||
| /** | ||
| * Returns the configuration key this validator monitors. | ||
| * | ||
| * <p>The validator will only be invoked when this specific configuration key changes. This | ||
| * allows efficient filtering of validators and clear declaration of dependencies. | ||
| * | ||
| * @return the configuration key to monitor, must not be null or empty | ||
| */ | ||
| String configKey(); | ||
|
|
||
| /** | ||
| * Validates a configuration value change. | ||
| * | ||
| * <p>This method is called when the monitored configuration key changes. It should check | ||
| * whether the new value is valid, potentially considering the old value and validation rules. | ||
| * | ||
| * <p>The method should be stateless and deterministic - given the same old and new values, it | ||
| * should always produce the same validation result. | ||
| * | ||
| * @param oldValue the previous value of the configuration key, null if the key was not set | ||
| * before | ||
| * @param newValue the new value of the configuration key, null if the key is being deleted | ||
| * @throws ConfigException if the configuration change is invalid, with a descriptive error | ||
| * message explaining why the change cannot be applied | ||
| */ | ||
| void validate(@Nullable String oldValue, @Nullable String newValue) throws ConfigException; | ||
| } |
124 changes: 124 additions & 0 deletions
124
...link-common/src/main/java/org/apache/fluss/flink/procedure/GetClusterConfigProcedure.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.flink.procedure; | ||
|
|
||
| import org.apache.fluss.config.cluster.ConfigEntry; | ||
|
|
||
| import org.apache.flink.table.annotation.ArgumentHint; | ||
| import org.apache.flink.table.annotation.DataTypeHint; | ||
| import org.apache.flink.table.annotation.ProcedureHint; | ||
| import org.apache.flink.table.procedure.ProcedureContext; | ||
| import org.apache.flink.types.Row; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Procedure to get cluster configuration(s). | ||
| * | ||
| * <p>This procedure allows querying dynamic cluster configurations. It can retrieve: | ||
| * | ||
| * <ul> | ||
| * <li>A specific configuration key | ||
| * <li>All configurations (when key parameter is null or empty) | ||
| * </ul> | ||
| * | ||
| * <p>Usage examples: | ||
| * | ||
| * <pre> | ||
| * -- Get a specific configuration | ||
| * CALL sys.get_cluster_config('kv.shared-rate-limiter.bytes-per-sec'); | ||
| * | ||
| * -- Get all cluster configurations | ||
| * CALL sys.get_cluster_config(); | ||
| * </pre> | ||
| */ | ||
| public class GetClusterConfigProcedure extends ProcedureBase { | ||
|
|
||
| @ProcedureHint( | ||
| output = | ||
| @DataTypeHint( | ||
| "ROW<config_key STRING, config_value STRING, config_source STRING>")) | ||
| public Row[] call(ProcedureContext context) throws Exception { | ||
| return getConfigs(null); | ||
| } | ||
|
|
||
| @ProcedureHint( | ||
| argument = {@ArgumentHint(name = "config_key", type = @DataTypeHint("STRING"))}, | ||
| output = | ||
| @DataTypeHint( | ||
| "ROW<config_key STRING, config_value STRING, config_source STRING>")) | ||
| public Row[] call(ProcedureContext context, String configKey) throws Exception { | ||
| return getConfigs(configKey); | ||
| } | ||
|
|
||
| private Row[] getConfigs(@Nullable String configKey) throws Exception { | ||
| try { | ||
| // Get all cluster configurations | ||
| Collection<ConfigEntry> configs = admin.describeClusterConfigs().get(); | ||
|
|
||
| List<Row> results = new ArrayList<>(); | ||
|
|
||
| if (configKey == null || configKey.isEmpty()) { | ||
| // Return all configurations | ||
| for (ConfigEntry entry : configs) { | ||
| results.add( | ||
| Row.of( | ||
| entry.key(), | ||
| entry.value(), | ||
| entry.source() != null ? entry.source().name() : "UNKNOWN")); | ||
| } | ||
|
|
||
| if (results.isEmpty()) { | ||
| return new Row[] {Row.of("No cluster configurations found", null, null)}; | ||
| } | ||
| } else { | ||
| // Find specific configuration | ||
| for (ConfigEntry entry : configs) { | ||
| if (entry.key().equals(configKey)) { | ||
| results.add( | ||
| Row.of( | ||
| entry.key(), | ||
| entry.value(), | ||
| entry.source() != null | ||
| ? entry.source().name() | ||
| : "UNKNOWN")); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (results.isEmpty()) { | ||
| return new Row[] { | ||
| Row.of( | ||
| String.format("Configuration key '%s' not found", configKey), | ||
| null, | ||
| null) | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| return results.toArray(new Row[0]); | ||
|
|
||
| } catch (Exception e) { | ||
| throw new RuntimeException("Failed to get cluster config: " + e.getMessage(), e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...link-common/src/main/java/org/apache/fluss/flink/procedure/SetClusterConfigProcedure.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.flink.procedure; | ||
|
|
||
| import org.apache.fluss.config.cluster.AlterConfig; | ||
| import org.apache.fluss.config.cluster.AlterConfigOpType; | ||
|
|
||
| import org.apache.flink.table.annotation.ArgumentHint; | ||
| import org.apache.flink.table.annotation.DataTypeHint; | ||
| import org.apache.flink.table.annotation.ProcedureHint; | ||
| import org.apache.flink.table.procedure.ProcedureContext; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.util.Collections; | ||
|
|
||
| /** | ||
| * Procedure to set or delete cluster configuration dynamically. | ||
| * | ||
| * <p>This procedure allows modifying dynamic cluster configurations. The changes are: | ||
| * | ||
| * <ul> | ||
| * <li>Validated by the CoordinatorServer before persistence | ||
| * <li>Persisted in ZooKeeper for durability | ||
| * <li>Applied to all relevant servers (Coordinator and TabletServers) | ||
| * <li>Survive server restarts | ||
| * </ul> | ||
| * | ||
| * <p>Usage examples: | ||
| * | ||
| * <pre> | ||
| * -- Set a configuration | ||
| * CALL sys.set_cluster_config('kv.shared-rate-limiter.bytes-per-sec', '200MB'); | ||
| * CALL sys.set_cluster_config('datalake.format', 'paimon'); | ||
| * | ||
| * -- Delete a configuration (reset to default) | ||
| * CALL sys.set_cluster_config('kv.shared-rate-limiter.bytes-per-sec', NULL); | ||
| * CALL sys.set_cluster_config('kv.shared-rate-limiter.bytes-per-sec', ''); | ||
| * </pre> | ||
| * | ||
| * <p><b>Note:</b> Not all configurations support dynamic changes. The server will validate the | ||
| * change and reject it if the configuration cannot be modified dynamically or if the new value is | ||
| * invalid. | ||
| */ | ||
| public class SetClusterConfigProcedure extends ProcedureBase { | ||
|
|
||
| @ProcedureHint(argument = {@ArgumentHint(name = "config_key", type = @DataTypeHint("STRING"))}) | ||
| public String[] call(ProcedureContext context, String configKey) throws Exception { | ||
| return performSet(configKey, null); | ||
| } | ||
|
|
||
| @ProcedureHint( | ||
| argument = { | ||
| @ArgumentHint(name = "config_key", type = @DataTypeHint("STRING")), | ||
| @ArgumentHint(name = "config_value", type = @DataTypeHint("STRING")) | ||
| }) | ||
| public String[] call(ProcedureContext context, String configKey, String configValue) | ||
| throws Exception { | ||
| return performSet(configKey, configValue); | ||
| } | ||
|
|
||
| private String[] performSet(String configKey, @Nullable String configValue) throws Exception { | ||
|
|
||
| try { | ||
| // Validate config key | ||
| if (configKey == null || configKey.trim().isEmpty()) { | ||
| throw new IllegalArgumentException( | ||
| "Config key cannot be null or empty. " | ||
| + "Please specify a valid configuration key."); | ||
| } | ||
|
|
||
| configKey = configKey.trim(); | ||
|
|
||
| // Determine operation type | ||
| AlterConfigOpType opType; | ||
| String operationDesc; | ||
|
|
||
| if (configValue == null || configValue.trim().isEmpty()) { | ||
| // Delete operation - reset to default | ||
| opType = AlterConfigOpType.DELETE; | ||
| operationDesc = "deleted (reset to default)"; | ||
| } else { | ||
| // Set operation | ||
| opType = AlterConfigOpType.SET; | ||
| operationDesc = String.format("set to '%s'", configValue); | ||
| } | ||
|
|
||
| // Construct configuration modification operation. | ||
| AlterConfig alterConfig = new AlterConfig(configKey, configValue, opType); | ||
|
|
||
| // Call Admin API to modify cluster configuration | ||
| // This will trigger validation on CoordinatorServer before persistence | ||
| admin.alterClusterConfigs(Collections.singletonList(alterConfig)).get(); | ||
|
|
||
| return new String[] { | ||
| String.format( | ||
| "Successfully %s configuration '%s'. " | ||
| + "The change is persisted in ZooKeeper and applied to all servers.", | ||
| operationDesc, configKey) | ||
| }; | ||
|
|
||
| } catch (IllegalArgumentException e) { | ||
| // Re-throw validation errors with original message | ||
| throw e; | ||
| } catch (Exception e) { | ||
| // Wrap other exceptions with more context | ||
| throw new RuntimeException( | ||
| String.format( | ||
| "Failed to set cluster config '%s': %s", configKey, e.getMessage()), | ||
| e); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
set_cluster_configanddelete_cluster_configcan be divided into different procedures?