loserwang1024 commented on code in PR #2178: URL: https://github.com/apache/fluss/pull/2178#discussion_r2621702566
########## fluss-flink/fluss-flink-common/src/main/java/org/apache/fluss/flink/procedure/SetSharedRocksDBRateLimiterProcedure.java: ########## @@ -0,0 +1,108 @@ +/* + * 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.ConfigOptions; +import org.apache.fluss.config.MemorySize; +import org.apache.fluss.config.cluster.AlterConfig; +import org.apache.fluss.config.cluster.AlterConfigOpType; +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 java.util.Collection; +import java.util.Collections; + +/** + * Procedure to set RocksDB rate limiter dynamically via cluster configuration. The configuration + * will be persisted in ZooKeeper and applied to all TabletServers. + * + * <p>Usage examples: + * + * <pre> + * -- Set rate limiter to 200MB/s + * CALL sys.set_shared_rocksdb_rate_limiter('200MB'); + * + * -- Set rate limiter to 1GB/s + * CALL sys.set_shared_rocksdb_rate_limiter('1GB'); + * </pre> + */ +public class SetSharedRocksDBRateLimiterProcedure extends ProcedureBase { + + @ProcedureHint( + argument = {@ArgumentHint(name = "bytes_per_second", type = @DataTypeHint("STRING"))}) + public String[] call(ProcedureContext context, String bytesPerSecondStr) throws Exception { + + try { + // Parse and validate input format first + long bytesPerSecond = MemorySize.parse(bytesPerSecondStr).getBytes(); + + // Get cluster configuration + Collection<ConfigEntry> configs = admin.describeClusterConfigs().get(); + + ConfigEntry configEntry = null; + for (ConfigEntry entry : configs) { + if (entry.key().equals(ConfigOptions.KV_SHARED_RATE_LIMITER_BYTES_PER_SEC.key())) { + configEntry = entry; + } + } + + if (null == configEntry) { + throw new IllegalStateException( + "Failed to set shared RocksDB rate limiter: previous config not found, server does not support rate limiter setting."); + } + + long oldValue = MemorySize.parseBytes(configEntry.value()); Review Comment: This can move to server, client just need to alter config. All the clients can reuse it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
