Skip to content

Commit 05f7935

Browse files
authored
fixed: add backup request (#48)
* fixed: add backup request * feat: add backup requests
1 parent 72ce0a2 commit 05f7935

File tree

8 files changed

+462
-26
lines changed

8 files changed

+462
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
# change log
33

4+
## Unreleased
5+
6+
- add backup request config + dispatcher to duplicate slow master reads to replicas in Redis Cluster mode
7+
48
# 1.3.3
59

610
- avoid infinite call when cluster endpoint was down

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ fetch = 600
8282
# read_from_slave is the feature make slave balanced readed by client and ignore side effects.
8383
read_from_slave = true
8484
85+
# backup_request duplicates slow reads to replica nodes when enabled.
86+
# trigger_slow_ms decides the fixed delay (set "default" or remove field to rely on moving average).
87+
# multiplier is applied to the rolling average latency to determine another trigger threshold.
88+
backup_request = { enabled = false, trigger_slow_ms = 5, multiplier = 2.0 }
89+
8590
############################# Proxy Mode Special #######################################################
8691
# ping_fail_limit means when ping fail reach the limit number, the node will be ejected from the cluster
8792
# until the ping is ok in future.

default.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
fetch_interval = 1800000 # 1800s , 30 minutes
4545
fetch_since_latest_cmd = 1000 # 3600s , 1 hour
4646
read_from_slave = false
47+
backup_request = { enabled = false, trigger_slow_ms = 5, multiplier = 2.0 }
4748

4849
ping_fail_limit = 10
4950
ping_interval = 300

docs/functionality.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
- 订阅与阻塞命令:
7373
- SUBSCRIBE / PSUBSCRIBE 会进入独占会话,按频道哈希槽选择节点,并在 MOVED / ASK 时自动重连与重放订阅;
7474
- BLPOP 等阻塞类命令复用独占连接,避免被 pipeline 请求阻塞。
75+
- 备份读(backup request):仅在 Redis Cluster 模式下可选启用;当 master 读命令在配置阈值上仍未返回时,会复制该请求至对应 replica,优先向客户端返回更快的副本响应,同时继续跟踪 master 延迟以动态更新阈值。
7576
- 依赖大量 `Rc<RefCell<>>``futures::unsync::mpsc`,并使用 `tokio::runtime::current_thread`.
7677

7778
## 协议与命令抽象

docs/usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ cargo build --release
2626
- `hash_tag`:一致性 hash 标签,例如 `{}`
2727
- `read_timeout` / `write_timeout`:后端超时(毫秒)。
2828
- `read_from_slave`:Cluster 模式下允许从 replica 读取。
29+
- `backup_request`:Cluster 模式下用于配置“副本兜底读”策略的表,包含:
30+
- `enabled`:是否开启该策略(默认 `false`)。
31+
- `trigger_slow_ms`:固定延迟阈值(毫秒,可写 `"default"` 关闭固定阈值),超过该延迟仍未返回则发送副本备份请求。
32+
- `multiplier`:相对阈值,等于“master 累计平均耗时 × multiplier”;当满足固定阈值或相对阈值任意条件即派发备份请求。
33+
- `backup_request` 的三个字段均可通过 `CONFIG SET cluster.<name>.backup-request-*` 在线调整。
2934
- `slowlog_log_slower_than`:慢查询阈值(微秒,默认 `10000`,设为 `-1` 关闭记录)。
3035
- `slowlog_max_len`:慢查询日志最大保留条数(默认 `128`)。
3136
- `hotkey_sample_every`:热点 Key 采样间隔(默认 `32`,越大代表对请求采样越稀疏)。

0 commit comments

Comments
 (0)