Repository navigation
RED-211767 - Add BLESS — protect keys from eviction - #15649
Merged
TalBarYakar merged 101 commits intoSep 15, 2026
Merged
Conversation
Collaborator
|
This change touches performance-sensitive code paths. Adding the |
- evict.c: re-check blessNoEvict when selecting from the LRU/LFU/TTL pool; the pool persists across calls, so a key pooled while unblessed then marked NO-EVICT could be evicted. - keyattr.c: MOVE reused attrKeep, leaving a ghost in the source DB's blessed_keys (BLESS COUNT/LIST over-reported). Use attrRename to untrack the source; COPY keeps attrKeep. - tests: stale-pool and MOVE regression tests.
moticless
reviewed
Sep 10, 2026
Replace KeyMetaSpec with kvSpec carrying the NO-EVICT flag. Apply the flag and update the blessed index in dbAddInternal() and dbAddRDBLoad(), before creation callbacks. Remove raw bit assignments from RENAME/MOVE and post-add blessing calls from COPY, RESTORE, and RDB loading.
moticless
reviewed
Sep 14, 2026
moticless
reviewed
Sep 14, 2026
- Use spec consistently in DB insertion, RDB loading, RENAME, MOVE, COPY, and RESTORE, including declarations and documentation. - Remove redundant NO-EVICT initialization in dbAddRDBLoad. - Label the keymeta fields within kvSpec.
Rename kms/keymeta to spec in metadata declarations and implementations, and keyMetaEmpty to specEmpty in dbAdd and dbAddByLink. No functional changes.
moticless
reviewed
Sep 14, 2026
Rely on object initialization and deletion to clear the bit. Format the keyMetaOnCopy signature on one line.
moticless
approved these changes
Sep 14, 2026
sundb
approved these changes
Sep 15, 2026
This was referenced Oct 1, 2026
This was referenced Oct 9, 2026
This was referenced Oct 18, 2026
gabsow
pushed a commit
that referenced
this pull request
Oct 22, 2026
…5996) Test-only change to `tests/unit/bless.tcl`. It covers the eviction policies and paths that the BLESS suite added in #15649 didn't exercise yet. No server code changes. ## What's added | Area | Before | After | | --- | --- | --- | | Blessed key survives an eviction flood | 6 of 9 evicting policies | All 9 (adds `volatile-lfu`, `volatile-lrm`, `allkeys-lrm`) | | All-blessed bounded overshoot (tolerated within 1.25x `maxmemory`, OOM past it, `BLESS CLEAR` relieves it) | `allkeys-random` only, plus a separate `allkeys-lru` case | All 9 evicting policies; keys get a TTL under `volatile-*` | | Time-sliced eviction | Not covered | `lazyfree-lazy-eviction yes` with `maxmemory-eviction-tenacity 0` | | No overshoot when no blessed key is an eviction candidate | Not covered | `noeviction`, and `volatile-lru` with blessed keys that have no TTL: the plain `maxmemory` limit applies | Most of the additions wrap existing tests in `foreach` loops rather than copying them. Per review, the loops sit at column 0 so the wrapped tests keep their original indentation (+51 / −9). A few existing test names gain a `($policy)` or `(lazyfree-lazy-eviction ...)` suffix. ## Note on the "no overshoot" case The eviction docs say the overshoot tolerance "applies uniformly across every `maxmemory-policy` value". In the code, the tolerance only applies when eviction sampled keys and found that all of them were blessed (`blessed_blocked`). With `noeviction`, or under `volatile-*` when the blessed keys have no TTL, nothing is sampled, so writes get a plain OOM. The new test pins the current code behavior. If that's the intended behavior, the docs wording could be narrowed. ## Testing `./runtest --single unit/bless` on `unstable` @ 5e332ca (macOS arm64): all 48 cases pass, plus the memory-leak checks. Found while working on RED-213286 (BLESS OSS test coverage). 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Changes are limited to unit tests in `bless.tcl` with no production code paths modified. > > **Overview** > **Test-only** expansion of `tests/unit/bless.tcl` maxmemory/BLESS eviction scenarios—no server changes. > > The memory-pressure case now runs for both `lazyfree-lazy-eviction` **no** and **yes** (with `maxmemory-eviction-tenacity 0` on the lazy path), and several tests call **`config resetstat`** so `evicted_keys` assertions are not polluted by earlier cases. > > **All-blessed 1.25× overshoot** behavior (tolerate within factor, OOM beyond, recover via `BLESS CLEAR`) is parameterized across all nine evicting `maxmemory-policy` values, with TTLs on keys when using `volatile-*`. New cases assert **no** overshoot tolerance when nothing blessed is an eviction candidate (`noeviction`, and `volatile-lru` with blessed keys that have no TTL). > > TTL protection and pool-branch eviction floods add **`volatile-lfu`**, **`volatile-lrm`**, and **`allkeys-lrm`**; existing single-policy tests are mostly folded into `foreach` loops with policy names in test titles. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c3654b2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
BLESS— protect keys from evictionAdds
BLESS, a keyspace command family for marking specific keys as NO-EVICT undermaxmemory. A blessed key is never chosen as an eviction victim. The protection is stored per-key and survives restart (RDB/AOF), replication, and slot migration.Commands
All
since 8.12.0, containerBLESS.BLESS SET <key> NO-EVICT1if the key's flag set changed, else0BLESS CLEAR <key> NO-EVICT1/0BLESS GET <key>[]if none)BLESS SCAN <cursor> NO-EVICT [COUNT <count>][cursor, [key ...]]BLESS CLEARis intentionally not DENYOOM, so you can always unbless to recover under memory pressure.BLESS SCANmirrorsSCANsemantics (COUNTis a hint, buckets are emitted whole). WithoutCOUNTthe whole index is returned in one call with cursor0; withCOUNTit paginates.INFO Stats → blessed_keys— instance-wide count of blessed keys (replaces the earlierBLESS COUNTidea).Eviction
Blessed keys are never chosen as eviction victims, on all
maxmemorypolicies (LRU / LFU / random, and thevolatile-*variants).When eviction can't free enough because blessed keys are what's holding the memory, used memory is allowed to overshoot up to 1.25×
maxmemorybefore writes are rejected with OOM — that factor is the effective ceiling for a heavily-blessed keyspace.BLESS SETis DENYOOM (can't dig the hole deeper under pressure);BLESS CLEARis not, so unblessing is always available to recover.Design rationale
NO-EVICTis the first flag; the command grammar (BLESS SET/CLEAR/GET <key> <FLAG>,BLESS SCAN <cursor> <FLAG>) and the shared per-key ATTR bitmask are designed to take additional flags without an interface change.RW(not the logicalUPDATE/ACCESS), and blessing is excluded fromDUMP/RESTORE.READONLYdeliberately not set onBLESS GET/BLESS SCAN: that flag opts a command into client-side-caching tracking, and blessing state isn't part of the key's value, so there's nothing for CSC to invalidate — leaving it off keeps client-side caching from having to deal with these commands.WRITEset onBLESS SET/BLESS CLEAR: blessing is a state change that must originate on the primary, so the commands are rejected on cluster replicas.Note
High Risk
Changes core maxmemory eviction, RDB format version, and key lifecycle paths (db, cluster ASM, lazyfree); misbehavior could cause unexpected OOM, lost protection, or index drift under migration.
Overview
Introduces BLESS (
SET/CLEAR/GET/SCANwith NO-EVICT) so existing keys can be marked non-evictable undermaxmemory. The flag lives inkvBitson eachkvobj, with a per-DBblessed_keysindex for scan,INFO blessed_keys, andMEMORY STATSoverhead.Eviction skips blessed keys on all policies; when sampling finds only blessed keys, writes may succeed with used memory up to ~1.25×
maxmemorybefore OOM.BLESS SETis DENYOOM;BLESS CLEARis not.Durability and movement: RDB bumps to v16 with opcode
RDB_OPCODE_KEY_NOEVICT; AOF/ASM emitBLESS SET … NO-EVICTafter values viablessRewrite.DUMP/RESTOREstill omit the flag;RESTORE REPLACEkeeps the destination’s blessing. Rename/move/copy/SWAPDB/ASM slot trim wire the index andkvSpec(replacingKeyMetaSpec) includingno_evicton load paths.Reviewed by Cursor Bugbot for commit e9e57b6. Bugbot is set up for automated code reviews on this repo. Configure here.