Repository navigation
feat: add configurable AOF and RDB persistence for Redis - #4137
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4137 +/- ##
=======================================
Coverage ? 52.10%
=======================================
Files ? 89
Lines ? 13825
Branches ? 0
=======================================
Hits ? 7204
Misses ? 6145
Partials ? 476 🚀 New features to boost your workflow:
|
1d02463 to
c2c3ce3
Compare
- Add aof.enabled (default true) to control AOF persistence - Add aof.fsync, aof.rewritePercentage, aof.rewriteMinSize for AOF tuning - Add rdb.enabled (default true) to control RDB snapshots - Add rdb.save for customizable snapshot schedule - AOF and RDB can be enabled together for dual persistence strategy - Add trailing newline to values.yaml - Fix extraConfig rendering to avoid blank lines - Add documentation for redis.redis.aof.* and redis.redis.rdb.* parameters - Add comments linking dir /data to volumeMount mountPath Default behavior: When persistence.enabled=true, both AOF and RDB are enabled for best durability. Users can disable either via aof.enabled=false or rdb.enabled=false. Signed-off-by: geekspeng <geekspeng@icloud.com>
82dad41 to
10bb5ac
Compare
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. Verified empirically with 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
| requirepass {{ .Values.redis.password }} | ||
| {{- end }} No newline at end of file | ||
| {{- end }} | ||
| {{- if .Values.redis.persistence.enabled }} |
There was a problem hiding this comment.
🔴 HIGH: Backward-incompatible behavior change for existing persistence.enabled=true users
The PR description claims "Backward compatible: Default behavior unchanged (persistence.enabled: false)", but this is misleading. The default persistence.enabled: false is preserved, but for users who have already set persistence.enabled=true, this PR silently flips on AOF and RDB by default:
- Before:
persistence.enabled=true→ onlydir /datain config, no persistence strategy - After:
persistence.enabled=true→dir /data+ AOF + RDB both enabled
Upgrade impact on existing deployments:
- AOF file begins growing immediately (
appendonly yes) - RDB snapshots fire on the default schedule (
save 900 1, etc.) - Default PVC size is 1Gi — AOF + RDB can fill this quickly under any non-trivial write load
- I/O pattern changes (write amplification from
appendfsync everysec) - First AOF rewrite triggers when file exceeds
rewriteMinSize=64mb
Recommended fix (pick one):
- Flip defaults to opt-in: set
aof.enabled: falseandrdb.enabled: falsein bothhelm/core/charts/redis/values.yamlandhelm/core/values.yaml. This is the safest approach for an existing deployment base. - Document as breaking change: add a prominent "
⚠️ Breaking change" callout to the PR description, release notes, and a new "Upgrading" section inhelm/higress/README.md.
Also worth noting: in the behavior matrix, case 4 (persistence=true, aof=false, rdb=false → only dir /data) is functionally equivalent to persistence.enabled=false and just mounts an unused PVC — consider documenting this or removing the case.
There was a problem hiding this comment.
Fixed in 0eda200: flipped aof.enabled/rdb.enabled defaults to false (opt-in) in both helm/core/charts/redis/values.yaml and helm/core/values.yaml, so existing persistence.enabled=true users keep their previous behavior. The PR description no longer claims the old default-on behavior was backward compatible, and the behavior matrix documents the new default (empty config with the PVC still mounted).
There was a problem hiding this comment.
Verified locally with helm template: defaults are now opt-in (aof.enabled: false, rdb.enabled: false in both values.yaml files and synced in helm/higress/README.md). With persistence.enabled=true and no extra flags, the rendered config is empty as expected. ✅ Resolved.
| dir /data | ||
| {{- if .Values.redis.aof.enabled }} | ||
| appendonly yes | ||
| appendfsync {{ .Values.redis.aof.fsync }} |
There was a problem hiding this comment.
🟢 LOW: No validation for aof.fsync value
The template renders appendfsync {{ .Values.redis.aof.fsync }} without validating the value. If a user sets aof.fsync: everysec_typo or any invalid string, Redis will fail to start with a confusing error like "Bad directive or wrong number of arguments" — far from the values.yaml they just edited.
Same applies to rdb.save list elements (no format check on the "<seconds> <changes>" string).
Recommended fix: add values.schema.json to helm/core/charts/redis/ validating aof.fsync against the set {always, everysec, no}, or add a fail guard in the template:
{{- if not (or (eq .Values.redis.aof.fsync "always") (eq .Values.redis.aof.fsync "everysec") (eq .Values.redis.aof.fsync "no")) }}
{{- fail (printf "redis.aof.fsync must be one of: always, everysec, no (got: %q)" .Values.redis.aof.fsync) }}
{{- end }}There was a problem hiding this comment.
Fixed in 0eda200: added a fail guard validating aof.fsync against {always, everysec, no} — an invalid value now fails at render time with a message naming the offending value (redis.aof.fsync must be one of: always, everysec, no (got: "typo")). Went with the template guard rather than values.schema.json since the repo has no values.schema.json precedent yet.
There was a problem hiding this comment.
Verified: helm template ... --set redis.aof.fsync=typo now fails at render time with redis.aof.fsync must be one of: always, everysec, no (got: "typo"). The template guard is the right call given there is no values.schema.json precedent in the chart. ✅ Resolved.
| # -- RDB snapshot schedule as "seconds changes" pairs. Redis saves when ANY rule is matched. | ||
| # Common defaults: "900 1" (15min/1 key), "300 10" (5min/10 keys), "60 10000" (1min/10000 keys). | ||
| # Set to empty list [] to disable RDB. See https://redis.io/docs/management/persistence/ | ||
| save: |
There was a problem hiding this comment.
🟡 MEDIUM: rdb.save=[] does NOT disable RDB as the comment claims
The comment says: "Set to empty list [] to disable RDB", but the template renders nothing when the list is empty:
{{- range .Values.redis.rdb.save }}
save {{ . }}
{{- end }}When rdb.enabled=true and rdb.save=[], no save directive is written to redis-stack.conf. Redis treats this as "use defaults", which means RDB snapshots still happen on the built-in schedule (save 3600 1, save 300 100, save 60 10000). So the documented way to disable RDB does not actually disable it.
Recommended fix (pick one):
- Fix the template to emit
save ""when the list is empty (this is the canonical way to disable RDB snapshots in Redis):
{{- if .Values.redis.rdb.enabled }}
{{- if eq (len .Values.redis.rdb.save) 0 }}
save ""
{{- else }}
{{- range .Values.redis.rdb.save }}
save {{ . }}
{{- end }}
{{- end }}
{{- end }}- Fix the comment to reflect reality: "Set to empty list [] to reset to Redis default save schedule (3600 1, 300 100, 60 10000). To fully disable RDB, set rdb.enabled=false."
There was a problem hiding this comment.
Fixed in 0eda200: when rdb.enabled=true and rdb.save is an empty list, the template now renders save "" (the canonical Redis directive to disable snapshotting), so the documented empty-list behavior now matches what is generated.
There was a problem hiding this comment.
Verified: --set-json redis.rdb.save=[] now renders save "" (canonical Redis way to disable snapshots). The comment in values.yaml was also clarified. ✅ Resolved.
| {{- end }} No newline at end of file | ||
| {{- end }} | ||
| {{- if .Values.redis.persistence.enabled }} | ||
| dir /data |
There was a problem hiding this comment.
🟢 LOW: Behavior matrix case 4 is functionally equivalent to persistence.enabled=false
When persistence.enabled=true and both aof.enabled=false and rdb.enabled=false, the template renders only:
dir /data
But the StatefulSet still mounts the PVC at /data (since persistence.enabled=true). This combination just allocates a PVC and mounts it without any persistence strategy — data goes to RAM only and is lost on restart. It is functionally identical to persistence.enabled=false, except for the wasted disk allocation.
Recommendation: either remove this case from the behavior matrix in the PR description, or render nothing in the template when both AOF and RDB are disabled (skip the dir /data line as well). For example:
{{- if and .Values.redis.persistence.enabled (or .Values.redis.aof.enabled .Values.redis.rdb.enabled) }}
dir /data
{{- if .Values.redis.aof.enabled }}
...
{{- end }}
{{- if .Values.redis.rdb.enabled }}
...
{{- end }}
{{- end }}This makes the matrix case 4 collapse to "same as persistence.enabled=false", which is the principle of least surprise.
There was a problem hiding this comment.
Fixed in 0eda200: dir /data is now rendered only when aof.enabled or rdb.enabled is true, so this combination collapses to the same config as persistence.enabled=false (the behavior matrix in the PR description was updated accordingly). The values.yaml comments document that driving persistence via extraConfig with both toggles off requires adding dir /data to extraConfig yourself.
There was a problem hiding this comment.
Verified: with persistence.enabled=true and both AOF/RDB disabled, the rendered configmap is empty (dir /data is now gated behind or aof.enabled rdb.enabled). The behavior matrix case 4 collapses as suggested. ✅ Resolved.
CH3CHO
left a comment
There was a problem hiding this comment.
Code Review Summary
Thanks for the clear PR description and the behavior matrix — that made it easy to verify the intent. The implementation works as designed and the helm template verification is thorough.
However, the PR is essentially a breaking change for anyone running with persistence.enabled=true (default-on AOF+RDB), and one of the new rdb.save=[] defaults does not behave as documented. Both should be addressed before merge.
Findings (in order of severity)
🔴 HIGH — Backward-incompatible default behavior change
persistence.enabled=true users will silently flip on AOF + RDB on upgrade, with 1Gi default PVC. See discussion.
🟡 MEDIUM — rdb.save=[] does not disable RDB
The doc comment promises one thing, the template delivers another (Redis falls back to built-in save defaults). See discussion.
🟢 LOW — No validation for aof.fsync
A typo silently produces an invalid appendfsync directive that fails Redis startup. See discussion.
🟢 LOW — Behavior matrix case 4 is functionally equivalent to persistence.enabled=false
Mounts a PVC that nothing writes to. See discussion.
Things that look good ✅
dir /datacorrectly aligns with the volumeMount instatefulset.yaml- AOF and RDB are independent toggles (not mutually exclusive as in the original chart)
- Defaults match Redis upstream recommendations (
everysec,64mb,100,900 1/300 10/60 10000) extraConfigis appended correctly vianindentredis.redis.*in parentvalues.yamlcorrectly reaches the sub-chart without alias remapping
Recommendation
Request changes until HIGH and MEDIUM are addressed. The HIGH issue is the most important: I'd lean toward flipping aof.enabled and rdb.enabled defaults to false so existing persistence.enabled=true users keep their previous behavior. New users who want dual persistence can opt-in explicitly.
- Flip aof.enabled/rdb.enabled defaults to false (opt-in) so existing persistence.enabled=true users keep their previous behavior - Render `save ""` when rdb.save is an empty list so documented RDB disabling actually works instead of falling back to Redis defaults - Add fail guard validating aof.fsync against always/everysec/no - Skip `dir /data` when both aof.enabled and rdb.enabled are false (collapses to persistence.enabled=false behavior, no wasted PVC) - Sync comments and higress README parameter table Signed-off-by: geekspeng <geekspeng@icloud.com>
0eda200 to
359e104
Compare
CH3CHO
left a comment
There was a problem hiding this comment.
All four review comments have been verified against commit 359e104:
aof.enabled/rdb.enableddefaults flipped tofalse(opt-in) in bothhelm/core/charts/redis/values.yamlandhelm/core/values.yaml, with the README parameter table in sync.rdb.save=[]now renders the canonicalsave ""directive, and the values.yaml comment was clarified.aof.fsyncis validated by a{{- fail }}guard at render time;helm template ... --set redis.aof.fsync=typoaborts with a clear error.dir /datais gated behind(or aof.enabled rdb.enabled), so behavior-matrix case 4 collapses as expected.
Verified all behavior-matrix combinations via helm template (sub-chart and parent chart paths); helm lint passes. The behavior is now safe to upgrade for existing persistence.enabled=true users. 👍
Ⅰ. Describe what this PR did
Adds configurable AOF and RDB persistence settings for Redis when
persistence.enabled=true.Behavior Matrix
persistence.enabledaof.enabledrdb.enabledtrue(default)false(default)false(default)persistence.enabled=false; the PVC is still mounted)truetruetruedir /data+ AOF + RDB (dual persistence)truefalsetruedir /data+ RDB-only (snapshots)truetruefalsedir /data+ AOF-onlytruetruetrue, withrdb.save=[]dir /data+ AOF +save ""(RDB snapshots disabled)New Configuration Options
AOF Settings:
aof.enabled(default: false, opt-in) - Enable AOF persistenceaof.fsync(default: "everysec") - AOF fsync policy: always, everysec, or no (validated at render time)aof.rewritePercentage(default: 100) - Auto-aof-rewrite-percentageaof.rewriteMinSize(default: "64mb") - Auto-aof-rewrite-min-sizeRDB Settings:
rdb.enabled(default: false, opt-in) - Enable RDB snapshotsrdb.save(default: ["900 1", "300 10", "60 10000"]) - Snapshot schedule; an empty list[]renderssave "", which disables RDB snapshotsKey Changes
aof.*configuration block for fine-grained AOF controlrdb.*configuration block for RDB snapshotsaof.enabledandrdb.enableddefault tofalseso existingpersistence.enabled=trueusers keep their previous behavior (per review feedback)dir /datais rendered only whenaof.enabledorrdb.enabledis true; when both are disabled, persistence can be driven viaextraConfig(adddir /datathere)rdb.save=[]renderssave ""(the canonical Redis way to disable snapshots)aof.fsyncis validated at render time against {always, everysec, no}Ⅱ. Does this pull request fix one issue?
No specific issue. Extends the original PR scope to provide flexible persistence configuration. This update addresses the review findings on this PR (opt-in defaults,
rdb.save=[]behavior,aof.fsyncvalidation,dir /datarendering condition).Ⅲ. Why don't you add test cases (unit test/integration test)?
This is a Helm template (YAML) change with no Go code. Verified by rendering the chart with
helm templateacross all configuration combinations.Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews
aof.enabled/rdb.enableddefault tofalse. Users who want persistence must enable at least one; this keeps the upgrade path safe for existingpersistence.enabled=truedeployments (addressing the HIGH review finding).everysec) + RDB (fast restart, compact backups). Redis prefers AOF for recovery when both are enabled.appendfsync everysec,save 900 1 300 10 60 10000, etc.)persistence.enabled: falserenders the same config as before;persistence.enabled: trueno longer implicitly enables AOF/RDB)Ⅵ. AI Coding Tool Usage Checklist
This PR was produced with the assistance of Claude Code (Anthropic).
Please check all applicable items:
AI Coding Summary
false(opt-in) per review feedback so existingpersistence.enabled=trueusers keep their behavior. (c) Add fine-grained control over AOF fsync and rewrite settings. (d) Fix trailing newline and extraConfig rendering issues.aof.enabled/rdb.enableddefaults tofalse; rendersave ""whenrdb.saveis empty so documented RDB disabling works; addedfailguard validatingaof.fsync; skipdir /datawhen both AOF and RDB are disabled; synced comments and the higress README parameter table.aof.*andrdb.*configuration blocks in values.yaml, updated configmap.yaml template, added README documentation.helm template(sub-chart and parent chart paths), including the fsync fail guard and empty-save rendering;helm lintpasses.🤖 Generated with Claude Code