-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backpressure): support dynamic configs (#2204)
* feat(backpressure): make back pressure manager configurable Signed-off-by: Ning Yu <[email protected]> * test: test diabled Signed-off-by: Ning Yu <[email protected]> * refactor: move backpressure from s3stream to kafka.core Signed-off-by: Ning Yu <[email protected]> * refactor: init `BackPressureManager` in `BrokerServer` Signed-off-by: Ning Yu <[email protected]> * refactor: introduce `BackPressureConfig` Signed-off-by: Ning Yu <[email protected]> * feat: make `BackPressureManager` reconfigurable Signed-off-by: Ning Yu <[email protected]> * test: test reconfigurable Signed-off-by: Ning Yu <[email protected]> * refactor: rename config key Signed-off-by: Ning Yu <[email protected]> * refactor: move metric "back_pressure_state" from s3stream to core Signed-off-by: Ning Yu <[email protected]> --------- Signed-off-by: Ning Yu <[email protected]>
- Loading branch information
1 parent
4d69c62
commit 96ae4bd
Showing
16 changed files
with
262 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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
87 changes: 87 additions & 0 deletions
87
core/src/main/java/kafka/automq/backpressure/BackPressureConfig.java
This file contains 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,87 @@ | ||
/* | ||
* Copyright 2024, AutoMQ HK Limited. | ||
* | ||
* The use of this file is governed by the Business Source License, | ||
* as detailed in the file "/LICENSE.S3Stream" included in this repository. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0 | ||
*/ | ||
|
||
package kafka.automq.backpressure; | ||
|
||
import kafka.automq.AutoMQConfig; | ||
import kafka.server.KafkaConfig; | ||
|
||
import org.apache.kafka.common.config.ConfigException; | ||
import org.apache.kafka.common.utils.ConfigUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class BackPressureConfig { | ||
|
||
public static final Set<String> RECONFIGURABLE_CONFIGS = Set.of( | ||
AutoMQConfig.S3_BACK_PRESSURE_ENABLED_CONFIG, | ||
AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG | ||
); | ||
|
||
private volatile boolean enabled; | ||
/** | ||
* The cooldown time in milliseconds to wait between two regulator actions. | ||
*/ | ||
private long cooldownMs; | ||
|
||
public static BackPressureConfig from(KafkaConfig config) { | ||
return new BackPressureConfig(config.s3BackPressureEnabled(), config.s3BackPressureCooldownMs()); | ||
} | ||
|
||
public static BackPressureConfig from(Map<String, ?> raw) { | ||
Map<String, Object> configs = new HashMap<>(raw); | ||
return new BackPressureConfig( | ||
ConfigUtils.getBoolean(configs, AutoMQConfig.S3_BACK_PRESSURE_ENABLED_CONFIG), | ||
ConfigUtils.getLong(configs, AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG) | ||
); | ||
} | ||
|
||
public BackPressureConfig(boolean enabled, long cooldownMs) { | ||
this.enabled = enabled; | ||
this.cooldownMs = cooldownMs; | ||
} | ||
|
||
public static void validate(Map<String, ?> raw) throws ConfigException { | ||
Map<String, Object> configs = new HashMap<>(raw); | ||
if (configs.containsKey(AutoMQConfig.S3_BACK_PRESSURE_ENABLED_CONFIG)) { | ||
ConfigUtils.getBoolean(configs, AutoMQConfig.S3_BACK_PRESSURE_ENABLED_CONFIG); | ||
} | ||
if (configs.containsKey(AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG)) { | ||
validateCooldownMs(ConfigUtils.getLong(configs, AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG)); | ||
} | ||
} | ||
|
||
public static void validateCooldownMs(long cooldownMs) throws ConfigException { | ||
if (cooldownMs < 0) { | ||
throw new ConfigException(AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG, cooldownMs, "The cooldown time must be non-negative."); | ||
} | ||
} | ||
|
||
public void update(Map<String, ?> raw) { | ||
Map<String, Object> configs = new HashMap<>(raw); | ||
if (configs.containsKey(AutoMQConfig.S3_BACK_PRESSURE_ENABLED_CONFIG)) { | ||
this.enabled = ConfigUtils.getBoolean(configs, AutoMQConfig.S3_BACK_PRESSURE_ENABLED_CONFIG); | ||
} | ||
if (configs.containsKey(AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG)) { | ||
this.cooldownMs = ConfigUtils.getLong(configs, AutoMQConfig.S3_BACK_PRESSURE_COOLDOWN_MS_CONFIG); | ||
} | ||
} | ||
|
||
public boolean enabled() { | ||
return enabled; | ||
} | ||
|
||
public long cooldownMs() { | ||
return cooldownMs; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.