refactor(redis): unify Redis key naming and drop read/write pool separation#609
Conversation
fslongjin
commented
Jun 22, 2026
- 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
left a comment
There was a problem hiding this comment.
I have landed #613, I think this PR need refresh.
9fb637b to
44d585f
Compare
| 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 |
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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>
44d585f to
0dfee60
Compare