Skip to content

refactor(redis): unify Redis key naming and drop read/write pool separation#609

Merged
fslongjin merged 1 commit into
TencentCloud:masterfrom
fslongjin:refactor/redis-key
Jun 23, 2026
Merged

refactor(redis): unify Redis key naming and drop read/write pool separation#609
fslongjin merged 1 commit into
TencentCloud:masterfrom
fslongjin:refactor/redis-key

Conversation

@fslongjin

Copy link
Copy Markdown
Member
  • Add centralized redis key definitions in pkg/base/rediskey
  • Unify CubeMaster Redis to single pool, drop read/write/metadata separation
  • Update CubeProxy Lua scripts to use new key scheme
  • Add migration script for existing Redis data
  • Add bilingual Redis key specification docs (zh/en)
  • Update configs for single-node deployment

@chenhengqi chenhengqi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have landed #613, I think this PR need refresh.

@fslongjin fslongjin force-pushed the refactor/redis-key branch from 9fb637b to 44d585f Compare June 23, 2026 06:51
@fslongjin fslongjin requested a review from lisongqian as a code owner June 23, 2026 06:51
Comment on lines +45 to +55
for _, key in ipairs(keys) do
local value, err
for i = 1, 3 do
value, err = red:hgetall(key)
if not err then
break
end
ngx.log(ngx.ERR, "LEVEL_WARN||",
string.format("request %s using key %s get redis err: %s, retry %d",
ngx.var.http_x_cube_request_id, key, err, i))
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested retry loop amplifies latency on the hot proxy path. Every data-plane request iterates 2 keys with up to 3 retries each — worst case is 6 sequential HGETALL calls before returning a 500. Burst errors (brief connection blip) get amplified 6× per request. Non-retriable errors (WRONGTYPE, NOAUTH) also burn retries on the same key before the fallback key is tried. Consider: (a) hoisting the retry loop to wrap only the outer key iteration so key2 is tried before exhausting retries on key1, and (b) skipping retry for non-retriable error types.

Comment on lines 29 to +34
EventStreamMaxLen = 100000

// StateKeyPrefix + sandboxID stores "running" | "pausing" | "paused" |
// "resuming". The sidecar uses these as cross-process locks (SETNX with
// TTL) to coordinate concurrent pause/resume.
StateKeyPrefix = "cube:sandbox:state:"
)

// StateKey returns the per-sandbox pause/resume coordination key. Values are
// "running" | "pausing" | "paused" | "resuming". The sidecar uses SETNX with
// TTL to coordinate concurrent pause/resume across replicas.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidecar hardcodes key strings rather than using the centralized rediskey package or the Lua redis_keys module. This contradicts the spec's rule that "scattered literal concatenation is forbidden." The parity test (parity_test.go) catches drift for MetaKey and EventStreamKey, but StateKey() is a runtime function that uses string concatenation and has no automated guard against a format mismatch with CubeMaster's rediskey.SandboxLifecycleState(). Recommend adding a parity test for StateKey output.

…ration

- Add centralized redis key definitions in pkg/base/rediskey
- Unify CubeMaster Redis to single pool, drop read/write/metadata separation
- Update CubeProxy Lua scripts to use new key scheme
- Add migration script for existing Redis data
- Add bilingual Redis key specification docs (zh/en)
- Update configs for single-node deployment

Signed-off-by: jinlong <jinlong@tencent.com>
@fslongjin fslongjin force-pushed the refactor/redis-key branch from 44d585f to 0dfee60 Compare June 23, 2026 08:58
@fslongjin fslongjin merged commit d168926 into TencentCloud:master Jun 23, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants