Skip to content

Replace the ZSET skiplist with a B+ tree behind an ordered index - #4359

Merged
madolson merged 9 commits into
unstablefrom
zset-btree
Aug 11, 2026
Merged

madolson merged 9 commits into
unstablefrom
zset-btree

Conversation

@ranshid

@ranshid ranshid commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Merges the zset-btree feature branch, completing #3166. The sorted set
skiplist is replaced with a B+ tree behind a new ordered-index
abstraction. 35 files, +12,627/-1,280.

skiplist.c and skiplist.h are deleted, zskiplist and zskiplistNode are
removed from server.h, and zset now holds a hashtable plus an
OrderedIndex. OBJ_ENCODING_SKIPLIST becomes OBJ_ENCODING_BTREE (same
value, 7), so OBJECT ENCODING on a large sorted set answers "btree"
instead of "skiplist". The listpack encoding for small sorted sets is
untouched.

Two new layers replace it:

  • ordered_index.[ch] (802 lines) is the API the rest of the server
    speaks: insert, delete, update score, pop, seek, iterate, count and
    delete by score, lex and rank range, defrag, memory estimation. Every
    skiplist call site in t_zset.c, object.c, rdb.c, aof.c, geo.c, sort.c,
    db.c, debug.c, defrag.c, lazyfree.c, module.c and valkey-check-rdb.c
    now goes through it, so nothing outside this file knows what the
    backing structure is. t_zset.c loses 643 lines net.

  • fbtree.[ch] plus fbtree_internal.h (2,811 lines) is the tree itself. It
    is a general-purpose ordered collection of sds with no ZSET knowledge,
    depending only on sds for string operations. Score packing, lex range
    sentinels and positioned seeks all live in the adapter.

Details worth knowing when reading it:

Items are packed sds. Each entry is a single allocation holding
[8-byte sortable score][element bytes], so plain sdscmp gives correct
ZSET ordering. The score is a big-endian sign-flipped IEEE 754 double,
with -0.0 normalized to 0.0 so equal scores map to one key.

Node layout is 61-way fanout, with leaves at exactly 512 B and inner
nodes at exactly 2048 B on 64-bit, enforced by static_assert so they land
in jemalloc size classes. Inner nodes carry per-child subtree sizes for
O(log N) rank arithmetic, and 4 bytes of discriminating "feature" per
child in a cache-line-aligned row, searched with AVX2 or NEON (scalar
fallback) to route a lookup without touching the child.

Hashtable lookups need disambiguation. The hashtable stores packed items
but is looked up with a plain sds, and hashtable has no heterogeneous
lookup. Rather than allocating a temporary packed key per lookup, lookup
keys are transiently marked via an sds aux bit (sdshdr8+) or a spare type
value (sdshdr5), and zsetHashFunction/zsetKeyCompare check the mark to
decide whether to skip the 8-byte score prefix. This is not pretty; the
plan is to add real heterogeneous lookup to hashtable and delete the
scheme.

Delete does not merge. Empty nodes are freed and a single-child root
collapses, but sibling leaves are never rebalanced, so leaves can stay
sparse after heavy deletion. Background compaction is a follow-up, along
with 32-bit node sizing (NODE_SIZE is tuned for 64-bit, so 32-bit nodes
fit their size class but do not fill it).

Defrag is rank-based. defragZsetSkiplist becomes defragZset and drops 52
lines. The cursor is a rank, resumed by O(log N) tree navigation,
processing 4 full leaves (~244 items) per call.

Compatibility:

  • No RDB or AOF format change. Saves still use RDB_TYPE_ZSET_2 and
    RDB_TYPE_ZSET_LISTPACK, and loading is unchanged apart from converting
    to OBJ_ENCODING_BTREE.
  • No config change and no module API change. valkeymodule.h is untouched.
    Module zset range iteration is reimplemented on the ordered-index
    iterator with the same semantics.
  • OBJECT ENCODING is the only user-visible reply change.
  • Two DEBUG outputs change: the crash report logs "Index height: N"
    instead of "Skiplist level: N", and DEBUG HTSTATS-KEY and DEBUG DIGEST
    follow the new encoding constant.

Performance, measured on the branch in #4206 and not re-run for this
merge. ARM Graviton 3 (c7g.metal, 64 cores), io-threads=9, pipeline=10,
3M-member zset, 5 repetitions, 95% CI within 2% except ZRANDMEMBER (5%):

Command Workload Skiplist fbtree Change
ZADD Score update, all hits 205K 421K +105%
ZREM 50/50 random add/remove 386K 680K +76%
ZCOUNT Score-range count 720K 917K +27%
ZRANK Point rank lookup 692K 825K +19%
ZRANGE 100-element rank scan 174K 183K +6%
ZRANDMEMBER 100 random samples 5.0K 5.1K +2%
ZSCORE Point score lookup 1.44M 1.46M +2%
ZRANGEBYSCORE 100-element score scan 95K 96K +1%
ZPOPMIN Pop min, append new member 1.08M 1.08M 0%

Mutations that reposition an element gain the most from cache locality.
Range scans are bottlenecked on reply size. ZSCORE and ZRANDMEMBER are
hashtable paths and do not involve the ordered index.

Memory, 5M members, 20-byte elements, via jemalloc heap profiling.
Per-member overhead excluding user data:

Insertion pattern Skiplist fbtree Savings
Sequential, dense packing 50.3 B 28.5 B -21.8 B (-43%)
Random, fresh fill 50.3 B 32.0 B -18.2 B (-36%)

fbtree overhead tracks leaf occupancy. The skiplist is flat at ~50.3 B
regardless of insertion order. Since there is no compaction yet,
delete-heavy workloads will land worse than either number here.

Testing:

  • 302 new gtest cases: 205 in test_fbtree.cpp (tree operations, SIMD
    feature search, property and fuzz tests) and 97 in
    test_ordered_index.cpp, which exercise the interface contract and were
    written against the skiplist before fbtree existed. They passed
    unchanged against the new backend, which is the main evidence the swap
    is behavior preserving.
  • 21 new tcl tests, 18 in tests/unit/type/zset.tcl and 3 in
    tests/unit/sort.tcl, mostly forcing the non-listpack encoding on paths
    that previously only ran on small sets.
  • New with_config helper in tests/support/util.tcl that restores the old
    value even when the body fails.
  • assert_encoding skiplist becomes assert_encoding btree in 5 test files.
  • -Wframe-larger-than in src/unit/Makefile goes from 32K to 128K. The cap
    applies to the compiler-generated static initializer, whose frame grows
    with the number of gtest registrations under ASan, and test_fbtree.cpp
    has 205 of them.

Also included beyond the three feature PRs:

  • Fix strict-aliasing miscompilation of the fbtree iterator under LTO #4363, a strict-aliasing miscompilation of the fbtree iterator.
    fbtreeIterator is uint64_t[3] accessed through an internal struct, which
    is UB everywhere and got miscompiled on Alpine gcc 15.2 at -O3 -flto:
    the optimizer elided the seek stores, so ZRANGE and ZREVRANGE returned
    results as if the iterator had never been seeked. Fixed with
    attribute((may_alias)) on the internal struct.
  • fbtree.c included both assert.h and serverassert.h, and only produced
    server crash reports because serverassert.h happened to come last and
    reclaim the macro. assert.h is dropped and the include order is
    documented.
  • "Ba" and "Addd" added to the typos allowlist, both from fbtree test
    fixtures.

This is PR 1 of the series introducing an abstraction layer over the
sorted set skiplist, enabling a future swap to a B+ tree for memory and
performance gains. (Issue #3166) It targets the zset-btree feature
branch.

### Planned PRs:
1. **Skiplist extraction ← this PR**
2. OrderedIndex interface + skiplist backend + unit tests
3. Convert t_zset.c to OrderedIndex
4. Convert module.c
5. Convert remaining files
6. Integration tests

### Summary of changes:

Move the skiplist implementation out of `t_zset.c` into its own
compilation unit (`skiplist.c` / `skiplist.h`), establishing a clean
module boundary.

**New files:**
- `src/skiplist.h` — struct definitions (`zskiplistNode`, `zskiplist`),
inline helpers (span/height accessors), and function declarations
- `src/skiplist.c` — all skiplist data structure operations extracted
from `t_zset.c`

**Changes to `server.h`:**
- Remove `zskiplistNode` and `zskiplist` struct definitions (moved to
`skiplist.h`)
- Remove `ZSKIPLIST_MAXLEVEL`, `ZSKIPLIST_MAX_SEARCH` defines (moved to
`skiplist.h`)
- Remove skiplist function declarations (moved to `skiplist.h`)
- Add forward declaration `struct zskiplist` for the `zset` struct
pointer

**Changes to `t_zset.c`:**
- Remove skiplist implementation (now in `skiplist.c`)
- Add `#include "skiplist.h"`
- Retain range parsing helpers (`zslParseRange`, `zslParseLexRangeItem`,
`zsetParseLexRange`, `zsetFreeLexRange`) as command-layer logic

**Other files:**
- Add `#include "skiplist.h"` to files that dereference skiplist struct
fields (`defrag.c`, `geo.c`, `module.c`, `object.c`, `sort.c`, `aof.c`,
`db.c`, `debug.c`, `rdb.c`, `server.c`, `lazyfree.c`,
`valkey-check-rdb.c`)
- Update `Makefile` and `CMakeLists.txt` to compile `skiplist.c`

Functions that were `static` in `t_zset.c` and are now needed across
translation units are made non-static. No behavioral changes.

Signed-off-by: Rain Valentine <[email protected]>
This is the second PR for implementing B+ tree for ZSET (#3166)

## Overview

The objective in this feature branch is to replace skiplist with a B+
tree.
- This PR introduces an interface abstraction wrapping the skiplist, and
a thorough set of unit tests. All call sites are migrated.
- Next PR will add the B+ tree as a second implementation. The same unit
tests will run and pass on both implementations, proving that they match
ZSET's expectations and are interchangeable.
(rainsupreme#12)

## Motivation

The skiplist is deeply coupled into ZSET operations — ~30 call sites
directly access skiplist internals. This makes it impossible to
experiment with alternative data structures (B+tree, adaptive index)
without rewriting all of `t_zset.c`. This PR creates a clean boundary:
ZSET code calls `orderedIndex*()` functions, and the backend (currently
skiplist) implements them behind the interface.

The unit tests document and establish how skiplist or other
implementations need to work for ZSET. In the next PR the same tests
will prove that the B+ tree is a drop-in replacement.

## Reviewing guide

Suggested reading order:
1. **`ordered_index.h`** (5 min) -- the full API contract
2. **`skiplist_ordered_index.c`** (10 min) -- how skiplist implements
each function
3. **`t_zset.c` diff** (15 min) -- the call site migration
4. **Other production code** -- mostly mechanical, same patterns
repeated
5. **Unit tests, integration tests** -- most of the added code is
automated testing

**Patterns to watch for in the migration:**

Most call sites are mechanical renames (`zslInsert` →
`orderedIndexInsert`), but two changes affect how code reads:

- **Iterator-based traversal:** The old code walked the skiplist via
`node->level[0].forward` / `node->backward` pointer chasing. The new
code uses an opaque iterator (`orderedIndexInitIterator` +
`orderedIndexNext`/`orderedIndexPrev`), with seek functions for
positioned starts. This makes traversal loops slightly more verbose but
backend-independent.

- **Opaque elements:** Elements were previously accessed as `node->ele`
(an sds). They're now accessed via `orderedIndexGetElementRaw(item,
&ptr, &len)` which returns a raw `(ptr, len)` pair. This is intentional
-- it avoids baking the assumption that elements are sds into the
interface, which is needed for the B+ tree backend where elements are
stored in a packed format.

## What changes

**New files:**
- `ordered_index.h` / `ordered_index.c` — public API (create, insert,
delete, update, iterate, seek, range-delete, pop, get-by-index,
get-first/last, defrag, memory)
- `skiplist_ordered_index.h` / `skiplist_ordered_index.c` — skiplist
backend implementing the interface

**Modified files (by category):**

| Category | Files | What changed |
|----------|-------|-------------|
| ZSET commands | `t_zset.c` | All skiplist access replaced with
`orderedIndex*()` calls |
| Object lifecycle | `object.c` | `zslCreate` → `orderedIndexCreate`,
free/dismiss |
| Persistence | `rdb.c`, `aof.c` | Iteration via ordered-index iterator
|
| Other commands | `geo.c`, `sort.c` | Iterator + element accessor
migration |
| Infrastructure | `defrag.c`, `db.c`, `debug.c`, `server.c`,
`lazyfree.c`, `module.c` | Element access via
`orderedIndexGetElementRaw()` |
| Skiplist internals | `skiplist.h`, `skiplist.c` | New iterator API,
accessor functions, node creation takes raw ptr+len |
| Tests | `test_ordered_index.cpp`, `ordered_index_test.h` | 358
parameterized unit tests, C-style (no STL) |
| Integration tests | `sort.tcl`, `zset.tcl` | New tests forcing
skiplist encoding |

## Testing

- 358 unit tests (79 new)
- 337 integration tests (11 new)
- All pass under AddressSanitizer
- CI green

## Scope boundaries

This PR does NOT:
- Add a new backend (that's the next PR)
- Change any runtime behavior or output
- Modify the skiplist algorithm itself
- Touch the listpack (small-ZSET) encoding path

---------

Signed-off-by: Rain Valentine <[email protected]>
Signed-off-by: Rain Valentine <[email protected]>
This is the third PR for implementing B+ tree for ZSET (#3166).
After this PR I will merge the feature branch into unstable and submit
future enhancements to the unstable branch.

## Overview

This PR replaces the skiplist with a B+ tree as the OrderedIndex
backend. The skiplist is fully removed. The encoding name changes from
"skiplist" to "btree" in OBJECT ENCODING responses.

The implementation is called "fbtree" — short for FB+ tree or Feature B+
Tree, a B+ tree variant that stores per-subtree feature metadata
(subtree size, a few distinguishing bytes) in inner nodes to minimize
memory fetches. See issue #3166 for details (design,
performance, memory overhead)

## What's included

**New files:**
- `fbtree.c` — the B+ tree implementation (insert, delete, split, seek,
iterate, defrag)
- `fbtree.h` / `fbtree_internal.h` — public and internal headers

**Modified files:**
- `ordered_index.c` — rewritten as the fbtree adapter
- `ordered_index.h` — iterator size increased to fit fbtreeIterator
- `server.c` / `server.h` — `zsetExtractElement` with packed-item
detection; `zsetMarkLookupKey`/`zsetUnmarkLookupKey` for heterogeneous
hashtable lookup; `OBJ_ENCODING_BTREE`
- `t_zset.c` — lookup callsites wrapped with mark/unmark for hashtable
operations
- `Makefile` — skiplist.o removed, fbtree.o added
- `defrag.c` — renamed defragZsetSkiplist → defragZset

**Deleted files:**
- `skiplist.c`, `skiplist.h`

## Reviewing guide

- fbtree is written as a general-purpose ordered collection of strings.
It only depends on sds for string operations.
- ordered_index.c is the adapter which uses fbtree to implement the ZSET
OrderedIndex interface (score packing, lex range sentinels, seek
helpers).
- hashtable does not currently support heterogeneous lookup, which is
where the stored entry and the lookup key are different types. To avoid
allocating a temporary packed entry for every hashtable lookup operation
I've cooked up a scheme to mark the lookup string sds so hashtableType
methods can differentiate between packed entry and simple lookup string.
(Not pretty. I plan to separately propose hashtable changes to make this
unnecessary.)

### Suggested reading order

1. **`fbtree.h`** (3 min) — public API surface
2. **`fbtree_internal.h`** (3 min) — node layout, constants, internal
structs
3. **`fbtree.c`** (30 min) — core tree operations: leaf ops, inner node
routing, splits, iteration/seek, defrag scan
4. **`ordered_index.c`** (15 min) — adapter layer. Key areas:
score-element packing, lex-range sentinel handling, `seekForBound`
helper for positioned range operations, defrag bridge
5. **`server.c` changes** (5 min) — `zsetExtractElement` packed-item
path, mark/unmark helpers, `zsetHashtableType`
6. **Tests** — encoding assertions updated from "skiplist" to "btree";
unit tests exercise orderedIndex functions directly (which now route to
fbtree)

## Design decisions

- **Node sizing** — leaf nodes are 512 B and inner nodes 2048 B, tuned
to exactly fill jemalloc size classes at 61-way fanout
- **No merge on delete** — simplified initial implementation. Leaves can
become sparse; background compaction is planned for a later PR
- **Score+element packed into sds** — each leaf item is a single sds
containing `[8B score][element bytes]`, enabling standard sds comparison
for tree ordering
- **Lookup-key marking** — hashtable callbacks must distinguish packed
fbtree items (skip 8B score prefix) from plain lookup keys. Solution:
transiently mark lookup keys via sds aux bit (sdshdr8+) or unused type
value (sdshdr5), check in `zsetExtractElement`, unmark after lookup
- **Sentinels handled in adapter** — fbtree.c is a generic B+ tree with
no ZSET knowledge; lex-range sentinel handling lives in the adapter
- **O(log N) defrag scan** — uses rank-based tree navigation to resume
from cursor position, processes 4 full leaves per call (~244 items)
- **Cursor-between-items iterator** — fbtreeSeekToRank(N) positions
cursor so next() returns rank N and prev() returns rank N-1, matching
the Java ListIterator semantics established in PR 2

## Testing

- 275 unit tests pass — 193 new in test_fbtree.cpp (tree operations,
SIMD feature search, property/fuzz tests), plus the 82 existing
ordered-index tests from PR 2, unchanged and now exercising fbtree
- 337 integration tests pass

## Benchmark Results

ARM Graviton 3 (c7g.metal, 64 cores), io-threads=9, pipeline=10,
3M-member zset, 5 repetitions per test. 95% confidence intervals are ≤2%
for all tests except ZRANDMEMBER (±5%, low absolute throughput).

| Command | Workload | Skiplist | fbtree | Change |
|---------|----------|--------:|-------:|-------:|
| ZADD | Score update (all hits) | 205K | 421K | **+105%** |
| ZREM | 50/50 random add/remove | 386K | 680K | **+76%** |
| ZPOPMIN | Pop min + append new member | 1.08M | 1.08M | 0% |
| ZRANGE | 100-element rank scan | 174K | 183K | +6% |
| ZRANGEBYSCORE | 100-element score scan | 95K | 96K | +1% |
| ZRANDMEMBER | 100 random samples | 5.0K | 5.1K | +2% |
| ZRANK | Point rank lookup | 692K | 825K | **+19%** |
| ZCOUNT | Score-range count | 720K | 917K | **+27%** |
| ZSCORE | Point score lookup (hashtable) | 1.44M | 1.46M | +2% |

Mutations that reposition elements in the ordered index (ZADD, ZREM)
show the largest gains from improved cache locality. ZRANK and ZCOUNT
benefit from O(log N) rank arithmetic. Scan operations are unchanged, as
expected. ZSCORE and ZRANDMEMBER are hashtable-based and perform
identically since the ordered index is not involved. Range operations
are unchanged because they are bottlenecked by the large reply size.

## Memory Overhead

5M-member zset, 20-byte members (+ 8-byte score), measured via jemalloc
heap profiling. Overhead is per-member bytes excluding user data,
measured across two insertion patterns that produce different
ordered-index occupancy:

| Insertion pattern | Skiplist | fbtree | Savings |
|-------------------|--------:|-------:|--------:|
| Sequential (ascending scores, dense packing) | 50.3 B | 28.5 B | −21.8
B (−43%) |
| Random (scattered scores, fresh fill) | 50.3 B | 32.0 B | −18.2 B
(−36%) |

fbtree overhead scales with leaf occupancy: dense sequential fills pack
tightest (−43%), while scattered random fills leave leaves partially
full (−36%). The skiplist stays flat at ~50.3 B across both patterns,
since per-node cost is independent of insertion order and every node is
freed on delete.

## Scope boundaries

This PR does NOT:
- Implement merge/compaction (planned for a later PR)
- Add the heterogeneous hashtable lookup that would make the sds marking
scheme unnecessary (separate PR)

---------

Signed-off-by: Rain Valentine <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change replaces skiplist-backed sorted sets with BTREE storage built from new fbtree and OrderedIndex implementations. Server operations, persistence, maintenance, module APIs, build wiring, and tests now use the new representation.

Changes

Sorted-set B+tree migration

Layer / File(s) Summary
fbtree core and contract
src/fbtree.*, src/unit/test_fbtree.cpp
Adds B+tree storage with ordering, iteration, range operations, validation, SIMD searches, defragmentation, memory dismissal, and extensive tests.
OrderedIndex contract and implementation
src/ordered_index.*, src/unit/test_ordered_index.cpp
Adds score/member packing, lifecycle operations, range queries, iterators, callbacks, memory handling, integrity checks, and property tests.
Sorted-set storage and command migration
src/server.*, src/object.c, src/t_zset.c, src/geo.c, src/module.c, src/sort.c
Changes sorted-set storage and command paths from skiplist nodes to OrderedIndex items with BTREE encoding.
Persistence and maintenance integration
src/aof.c, src/db.c, src/debug.c, src/defrag.c, src/lazyfree.c, src/rdb.c, src/valkey-check-rdb.c
Updates AOF, RDB, scans, diagnostics, lazy freeing, and defragmentation for BTREE sorted sets.
Build wiring and regression coverage
cmake/Modules/SourceFiles.cmake, src/Makefile, tests/*, src/unit/Makefile, src/unit/wrappers.h, .config/typos.toml
Adds build sources, updates encoding expectations, adds BTREE behavior coverage, and adjusts test support configuration.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

Suggested reviewers: zuiderkwast

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description clearly explains the skiplist-to-B+ tree migration, ordered-index abstraction, compatibility, performance, memory, and testing changes.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: replacing the ZSET skiplist with a B+ tree behind an ordered index.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ranshid ranshid added the run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP) label Aug 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 11

Note

Due to the large number of review comments, Critical, Major severity comments were prioritized as inline comments.

🟡 Minor comments (12)
tests/unit/sort.tcl-174-217 (1)

174-217: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Rename the BTREE test labels.

The tests force and assert btree encoding. Their names still state skiplist. Rename all three labels to btree so test output identifies the tested backend.

Proposed fix
-    test "SORT sorted set skiplist BY nosort should retain ordering" {
+    test "SORT sorted set btree BY nosort should retain ordering" {
...
-    test "SORT sorted set skiplist BY nosort + LIMIT" {
+    test "SORT sorted set btree BY nosort + LIMIT" {
...
-    test "SORT sorted set skiplist with BY pattern" {
+    test "SORT sorted set btree with BY pattern" {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/sort.tcl` around lines 174 - 217, Rename the three test labels in
the diff from “skiplist” to “btree” while preserving their existing test logic
and assertions, so each test name accurately reflects the forced and asserted
encoding.
.config/typos.toml-18-19 (1)

18-19: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the Ba global typo exception.

Ba is not present in the checked-in sources, and src/crc16_slottable.c is already excluded by .config/typos.toml, so this exception scope and necessity are unclear.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.config/typos.toml around lines 18 - 19, Remove the Ba entry from the typo
configuration while preserving the Addd exception and existing file exclusions.

Source: Coding guidelines

tests/integration/convert-ziplist-zset-on-load.tcl-22-22 (1)

22-22: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the renamed sorted-set encoding references.

The tests use assert_encoding btree for sorted sets, so rename the skiplist test labels/comments that describe those sorted-set encodings to match the public encoding name.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/convert-ziplist-zset-on-load.tcl` at line 22, Update the
sorted-set encoding test labels and comments surrounding assert_encoding in
convert-ziplist-zset-on-load.tcl, replacing skiplist references with the public
btree encoding name while preserving the existing assertions and test behavior.

Source: Coding guidelines

src/unit/test_fbtree.cpp-3559-3565 (1)

3559-3565: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the comment blocks that describe tests which are not present.

Five comment blocks describe tests that the file does not contain:

  • Lines 3561-3563 describe a large range delete from the start of a multilevel tree; the next statement is an unrelated test.
  • Lines 3580-3581 describe a leaf underflow and merge test.
  • Lines 3664-3665 describe a test where the sibling has NODE_SIZE items.
  • Line 3802 describes pop operations that trigger leaf merges.
  • Lines 4082-4084 describe merge enforcement and MIN_FILL, but the test that follows is LookupWithParentPrefixExceedingChildPrefix, which tests prefix routing.

These blocks are stale after the tests were removed or renamed. They claim coverage that does not exist. Delete them, or restore the tests they describe.

Also applies to: 3578-3582, 3664-3666, 3802-3803, 4082-4085

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/unit/test_fbtree.cpp` around lines 3559 - 3565, Remove the five stale
comment blocks in the edge-range deletion test section, including those before
the unrelated test statements and LookupWithParentPrefixExceedingChildPrefix. Do
not add replacement comments or restore tests; leave the existing test
implementations unchanged.
src/ordered_index.h-227-232 (1)

227-232: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Document whether callback may be NULL.

orderedIndexScanDefrag forwards callback to defragItemCallback in ordered_index.c, which dereferences it without a NULL check. fbtreeDefragScan also calls it without a check. Every other callback in this header, for example on_delete on the range-delete functions, is explicitly documented as optional.

State that callback is mandatory, or accept NULL and check it in defragItemCallback.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordered_index.h` around lines 227 - 232, Document the NULLability
contract for callback in orderedIndexScanDefrag: either state that callers must
provide a non-NULL callback, consistent with defragItemCallback and
fbtreeDefragScan, or make callback optional by adding the necessary NULL checks
before invocation.
src/fbtree.c-1388-1399 (1)

1388-1399: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Do not clear it->fbt on the empty-tree path.

fbtreeSeekToScore and fbtreeSeekToValue set it->fbt = NULL when the tree is empty. This detaches the iterator from the index permanently. fbtreeSeekToRank does not do this; it only clears current_leaf. After the detach, fbtreeIteratorGetIndex returns NULL and every later seek on the same iterator is a no-op, even after the caller re-initializes nothing else.

orderedIndexSeekToScoreRange reads fbtreeIteratorGetIndex and returns early when it is NULL, so a reused iterator silently yields an empty result. Leave it->fbt intact and rely on the ITER_* state and current_leaf for the empty case, so all three seek functions behave the same way.

🔧 Proposed fix (apply to both functions)
     if (!fbt || !fbt->root) {
-        it->fbt = NULL;
+        it->state = ITER_PAST_END;
         return 0;
     }

Also applies to: 1439-1450

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 1388 - 1399, In fbtreeSeekToScore and
fbtreeSeekToValue, remove the assignments that set it->fbt to NULL when the
index is missing or has no root. Preserve the iterator’s existing fbt reference
while using its state and current_leaf fields to represent the empty-tree
result, matching fbtreeSeekToRank and allowing subsequent seeks to reuse the
iterator.
src/fbtree.c-1330-1381 (1)

1330-1381: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Document the minimum item length that the score-based APIs require.

findChildIndexByScore and leafNodeBinarySearchByScore read exactly SCORE_SIZE (8) bytes from every anchor and every leaf value. The file header describes fbtree as a general-purpose structure for sorted binary strings, and fbtreeInsert accepts any sds, including shorter ones. test_fbtree.cpp inserts strings such as "a" and "".

If a caller mixes short items with fbtreeSeekToScore, fbtreeDeleteRangeByScore, or fbtreeCountRangeByScore, these memcmp calls read past the end of the sds buffer.

State the precondition in fbtree.h for every score-based entry point, and add an assertion in the leaf search under debug builds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 1330 - 1381, Document in fbtree.h that every
score-based entry point requires keys/values to be at least SCORE_SIZE bytes
long, including fbtreeSeekToScore, fbtreeDeleteRangeByScore, and
fbtreeCountRangeByScore. Add a debug-build assertion in
leafNodeBinarySearchByScore validating each searched leaf value meets this
minimum before the fixed-width memcmp, while leaving general insertion support
for shorter strings unchanged.
src/unit/test_ordered_index.cpp-1266-1272 (1)

1266-1272: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a lex-seek overshoot test on an index that extends beyond max.

This case uses offset 10 on a 5-element index. The seek skips past the last member of the whole index, so orderedIndexNext returns NULL because the index is exhausted, not because the offset left the lex range. The assertion therefore cannot detect a missing far-bound check.

Add a case where members exist after max. For example, insert apple through elderberry, seek ["banana", "cherry"] with offset 5, and assert orderedIndexNext returns NULL. That distinguishes "the range ended" from "the index ended".

This covers the gap described in the comment on src/ordered_index.c lines 469-504.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/unit/test_ordered_index.cpp` around lines 1266 - 1272, Extend the
ordered-index lex-seek tests around orderedIndexInitIterator and seekToLexRange
by using an index containing members beyond the requested max, such as apple
through elderberry. Seek the range ["banana", "cherry"] with offset 5 and assert
orderedIndexNext returns nullptr, ensuring the far-bound check is exercised
rather than index exhaustion.
src/fbtree.c-2554-2557 (1)

2554-2557: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

State that item_callback must not be NULL, or check it.

fbtreeDefragScan calls item_callback without a NULL check. Every other callback parameter in this file is documented as optional and is checked before the call, for example in deleteRangeSameLeaf line 1765 and deleteRangeCore line 1860. The header comment for fbtreeDefragScan (fbtree.h lines 75-83) does not state that this callback is mandatory.

orderedIndexScanDefrag forwards a caller-supplied OrderedIndexDefragCallback through defragItemCallback, which also dereferences it unconditionally. A NULL callback from defrag.c crashes.

Either add a NULL check here, or document the requirement in fbtree.h and in ordered_index.h.

🔧 Proposed fix
-            item_callback(old_item, new_item, ctx);
+            if (item_callback) item_callback(old_item, new_item, ctx);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 2554 - 2557, Make the defragmentation callback
contract explicit and safe: update the fbtreeDefragScan documentation in
fbtree.h and the OrderedIndexDefragCallback documentation in ordered_index.h to
state that callbacks are mandatory, and ensure orderedIndexScanDefrag does not
pass a NULL callback through defragItemCallback. Alternatively, add NULL guards
before invoking item_callback in fbtreeDefragScan and the forwarded callback
path while preserving existing defragmentation behavior.
src/ordered_index.c-242-245 (1)

242-245: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Assert that the item was found before converting the rank.

fbtreeGetIndexOfItem returns -1 when the item is not in the tree. Line 244 casts that to unsigned long, which produces ULONG_MAX. A caller that treats the result as a rank then indexes far out of range, and the failure appears far from its cause.

The header documents the "item must be in the index" precondition, so an assertion is the right enforcement.

🔧 Proposed fix
 unsigned long orderedIndexGetIndex(const OrderedIndex *oi, const OrderedIndexItem *item) {
     long rank = fbtreeGetIndexOfItem((fbtreeIndex *)oi, (const_sds)item);
+    serverAssert(rank >= 0);
     return (unsigned long)rank;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordered_index.c` around lines 242 - 245, Update orderedIndexGetIndex to
assert that the rank returned by fbtreeGetIndexOfItem is nonnegative before
casting it to unsigned long, enforcing the documented requirement that the item
exists in the index.
src/ordered_index.c-108-115 (1)

108-115: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Check the result of fbtreeDelete in orderedIndexUpdateScore.

fbtreeDelete returns a bool that indicates whether the item was found and removed. The result is discarded here. If the item is not in this index, the function still inserts new_packed. The index then holds one extra item, orderedIndexLength grows by one, and the stale item remains reachable at its old score. The companion hashtable and the index diverge silently.

The header documents that the item must be in the index, so this is a caller error. Make it detectable instead of silently corrupting the index.

🔧 Proposed fix
     sds new_packed = packScoreElement(newscore, ele, ele_len);
-    fbtreeDelete((fbtreeIndex *)oi, packed);
+    bool removed = fbtreeDelete((fbtreeIndex *)oi, packed);
+    serverAssert(removed);
     return (OrderedIndexItem *)fbtreeInsert((fbtreeIndex *)oi, new_packed);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordered_index.c` around lines 108 - 115, Update orderedIndexUpdateScore
to check the boolean result of fbtreeDelete before inserting new_packed; if
deletion fails because the item is absent, signal the documented caller error
using the existing assertion/error-handling convention instead of inserting.
Only call fbtreeInsert after successful deletion.
src/module.c-223-231 (1)

223-231: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the stale comment on the oi field.

The comment says "for skiplist encoding". The skiplist encoding no longer exists. Use "BTREE encoding".

📝 Proposed fix
-            OrderedIndexIterator oi; /* OrderedIndex iterator for skiplist encoding. */
+            OrderedIndexIterator oi; /* OrderedIndex iterator for BTREE encoding. */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/module.c` around lines 223 - 231, Update the comment on the
OrderedIndexIterator field oi in the zset iterator structure to say it is used
for BTREE encoding instead of skiplist encoding; leave the field and surrounding
comments unchanged.
🧹 Nitpick comments (19)
tests/integration/convert-ziplist-zset-on-load.tcl (1)

22-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Update all stale test titles after the encoding rename.

These assertions now validate btree, but the adjacent test titles still name the removed skiplist backend. This makes test output misleading.

  • tests/integration/convert-ziplist-zset-on-load.tcl#L22-L22: Rename the title from converts to skiplist when zset-max-ziplist-entries is exceeded to converts to btree when zset-max-ziplist-entries is exceeded.
  • tests/unit/keyspace.tcl#L321-L321: Rename COPY basic usage for skiplist sorted set to COPY basic usage for btree sorted set.
  • tests/unit/moduleapi/scan.tcl#L43-L43: Rename Module scan zset skiplist to Module scan zset btree.

Based on the PR objective, the skiplist backend is removed and the encoding name is btree.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/convert-ziplist-zset-on-load.tcl` at line 22, Rename the
stale test titles to use the btree encoding name: update
tests/integration/convert-ziplist-zset-on-load.tcl lines 22-22 to “converts to
btree when zset-max-ziplist-entries is exceeded,” tests/unit/keyspace.tcl lines
321-321 to “COPY basic usage for btree sorted set,” and
tests/unit/moduleapi/scan.tcl lines 43-43 to “Module scan zset btree.”
src/fbtree_internal.h (3)

9-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Include <assert.h> so the header is self-contained.

This header uses static_assert at lines 70-79 and 84. In C11 and C17, static_assert is a macro that <assert.h> provides; the keyword is _Static_assert. This header includes <stddef.h>, <stdint.h>, and <stdbool.h>, but not <assert.h>.

The build works today only because src/fbtree.c includes <assert.h> at line 8 before this header. Any other C translation unit that includes fbtree_internal.h first will fail to compile.

Add the include so the header stands alone.

🔧 Proposed fix
 `#include` <stddef.h>
 `#include` <stdint.h>
 `#include` <stdbool.h>
+#include <assert.h>
 `#include` "fbtree.h"
 `#include` "sds.h"
#!/bin/bash
# Description: Determine the C standard the project targets, to confirm whether static_assert needs assert.h.
rg -n -- '-std=(c|gnu)[0-9x]+' src/Makefile
fd -t f 'CMakeLists.txt|.*\.cmake' -x rg -n 'C_STANDARD|CMAKE_C_FLAGS' {}

Also applies to: 69-79

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree_internal.h` around lines 9 - 13, Add <assert.h> to the include
list in fbtree_internal.h so its static_assert uses are self-contained for any
translation unit that includes the header directly.

20-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Fail the build when the pointer width is unknown.

EMBED_PREFIX_LEN is defined only when SIZE_MAX equals UINT64_MAX or UINT32_MAX. On any other target the macro stays undefined, and innerNode then fails with a confusing "undeclared identifier" error inside a struct definition. Add an explicit #error so the failure names the cause.

🔧 Proposed fix
 `#elif` SIZE_MAX == UINT32_MAX /* 32-bit */
 `#define` EMBED_PREFIX_LEN 30  /* Tuned to fit innerNode exactly in 1024-byte jemalloc size class */
+#else
+#error "fbtree: unsupported pointer width; EMBED_PREFIX_LEN is not tuned for this target"
 `#endif`
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree_internal.h` around lines 20 - 24, Add an explicit preprocessor
`#else` branch after the UINT64_MAX and UINT32_MAX cases in the EMBED_PREFIX_LEN
configuration, emitting `#error` for unsupported pointer widths so the build fails
with a clear cause instead of leaving EMBED_PREFIX_LEN undefined.

21-23: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Correct two stale comments.

Line 23 states the 32-bit innerNode fits "exactly in 1024-byte jemalloc size class", but the assertion at line 76 requires <= 2048. Line 16 also states the 64-bit target is a 1792-byte innerNode, while line 21 and the assertion at line 70 use 2048.

Line 33 explains MAX_TREE_DEPTH with "depth 6 handles >61^6", but the constant is 16. State why 16 is the chosen bound.

Also applies to: 33-33

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree_internal.h` around lines 21 - 23, Correct the stale comments in
the EMBED_PREFIX_LEN definitions to consistently describe the 2048-byte
innerNode limit used by the corresponding assertions, including the 64-bit
comment. Update the MAX_TREE_DEPTH comment to explain the rationale for choosing
depth 16 instead of referencing depth 6 or 61^6; leave the constants and
assertions unchanged.
src/fbtree.c (4)

2601-2622: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Guard the extrapolation against a zero item count.

fbtreeEstimateStructureMemory computes len / ((double)items_seen / leaves_seen) at line 2617. If every sampled leaf reports num_items == 0, items_seen is 0, the divisor is 0.0, the quotient is infinity, and the cast to size_t is undefined behavior.

The early return at line 2604 covers only a fully empty tree, not a tree whose first leaves are empty. Add a direct guard.

🔧 Proposed fix
-    size_t est_leaves = (leaf == NULL) ? leaves_seen : (size_t)(len / ((double)items_seen / leaves_seen)) + 1;
+    size_t est_leaves;
+    if (leaf == NULL || items_seen == 0)
+        est_leaves = leaves_seen ? leaves_seen : 1;
+    else
+        est_leaves = (size_t)(len / ((double)items_seen / leaves_seen)) + 1;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 2601 - 2622, Update
fbtreeEstimateStructureMemory’s leaf-count extrapolation to guard against
items_seen being zero before dividing by the sampled fill. When all sampled
leaves report no items, use a safe finite leaf estimate instead of evaluating
the zero divisor; preserve the existing exact estimate for fully traversed
leaves and the current extrapolation for positive items_seen.

2296-2302: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Static-analysis hint reviewed: no format-string issue here.

ast-grep flags the vsnprintf call as a non-literal format string (CWE-134). Every caller of validateFail in this file passes a compile-time string literal, and the function is reachable only from fbtreeDebugValidate. No untrusted data reaches fmt. No change is needed.

To keep the guarantee under future edits, consider annotating the function with __attribute__((format(printf, 2, 3))) so the compiler rejects a non-literal or mismatched format.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 2296 - 2302, Annotate validateFail with the
compiler printf-format attribute using fmt as the format parameter and the
variadic arguments as the checked arguments. Preserve the existing validation
and vsnprintf behavior while enabling compile-time format checking for future
callers.

Source: Linters/SAST tools


684-717: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Gate the test-only wrappers out of production builds.

featureSearchSIMD_test_wrapper, featureSearchSIMD_avx2_test_wrapper, featureSearchSIMD_sse2_test_wrapper, and featureSearchSIMD_scalar_test_wrapper are non-static symbols in a production source file. They are linked into the server binary and add four exported names that no production caller uses.

Wrap them in the same conditional the repository already uses for unit-test-only code, so release builds do not carry them.

#!/bin/bash
# Description: Find the macro the repository uses to gate unit-test-only symbols in C sources.
rg -n 'SERVER_TEST|VALKEY_TEST|`#ifdef` .*TEST' src --type=c -g '!src/unit/**' | head -50
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 684 - 717, Wrap all four test wrapper
functions—featureSearchSIMD_test_wrapper, featureSearchSIMD_avx2_test_wrapper,
featureSearchSIMD_sse2_test_wrapper, and
featureSearchSIMD_scalar_test_wrapper—in the repository’s existing
unit-test-only preprocessor conditional, identified from other C sources, so
none are compiled or exported in release builds.

1527-1544: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value

Assert the MAX_TREE_DEPTH bound before writing the path arrays.

descendSubPath writes path[*path_depth] and path_idx[*path_depth] with no bound check. The same pattern appears in buildBoundaryPaths (line 1679), in fbtreeDeleteRangeByRank (lines 2031, 2062, 2081), and in fbtreeDefragScan (lines 2478-2479). All these arrays are stack-allocated with MAX_TREE_DEPTH (16) entries.

The current split policy keeps the real depth far below 16, so this is not reachable today. If a future change lowers the fanout or adds a shallower split rule, the overflow corrupts the caller's stack frame silently. An assertion converts that into an immediate, diagnosable failure at zero release cost.

🔧 Proposed fix
     node *current = start;
     while (!current->is_leaf) {
         innerNode *inner = (innerNode *)current;
+        assert(*path_depth < MAX_TREE_DEPTH);
         path[*path_depth] = current;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` around lines 1527 - 1544, Add an assertion that *path_depth is
less than MAX_TREE_DEPTH immediately before the path and path_idx writes in
descendSubPath. Apply the same pre-write bound assertion to the corresponding
array writes in buildBoundaryPaths, fbtreeDeleteRangeByRank, and
fbtreeDefragScan, preserving the existing traversal behavior.
src/ordered_index.c (2)

333-355: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Collapse the two identical branches in seekForBound.

The !reverse && !inclusive branch (lines 336-342) and the reverse && inclusive branch (lines 343-350) contain exactly the same two statements. Only the explanatory comments differ. The combined condition is reverse == inclusive.

Two copies of the same adjustment can diverge on a later edit, and the reader must compare them character by character to confirm they agree today. Write the condition once and keep both explanations in a single comment.

🔧 Proposed fix
     fbtreeSeekToValue(packed, fbt_iter);
 
-    if (!reverse && !inclusive) {
-        /* Forward + exclusive: peek the first element >= bound. If it IS the
-         * bound, leave it consumed so fbtreeNext() returns the element after it
-         * (the bound is excluded). If it is already past the bound, step back so
-         * fbtreeNext() returns it. */
-        const_sds pos = fbtreeNext(fbt_iter);
-        if (pos != NULL && sdscmp(pos, packed) != 0) fbtreePrev(fbt_iter);
-    } else if (reverse && inclusive) {
-        /* Reverse + inclusive: peek the first element >= bound. If it IS the
-         * bound, leave it consumed so fbtreePrev() returns the bound. If it is
-         * past the bound (bound absent), step back so fbtreePrev() returns the
-         * last element < bound. */
+    if ((reverse != 0) == (inclusive != 0)) {
+        /* Two cases need a one-element nudge, and both need the same one:
+         *  - Forward + exclusive: if the first element >= bound IS the bound,
+         *    leave it consumed so fbtreeNext() returns the element after it.
+         *  - Reverse + inclusive: if it IS the bound, leave it consumed so
+         *    fbtreePrev() returns the bound itself.
+         * In both cases, when the element is already past the bound, step back
+         * so the next step in the iteration direction returns it. */
         const_sds pos = fbtreeNext(fbt_iter);
         if (pos != NULL && sdscmp(pos, packed) != 0) fbtreePrev(fbt_iter);
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordered_index.c` around lines 333 - 355, In seekForBound, merge the
duplicated !reverse && !inclusive and reverse && inclusive branches into one
reverse == inclusive condition containing the shared fbtreeNext/fbtreePrev
adjustment. Consolidate both behavioral explanations into a single comment while
leaving the other cases unchanged.

226-245: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Constify the read-only fbtree entry points instead of casting const away.

Ten functions in this file accept const OrderedIndex *oi and then cast it to a non-const fbtreeIndex *, for example at lines 227, 231, 235, 239, 243, 257, and 269. Each cast discards the const the header promises. The compiler can no longer verify that these query paths do not mutate the index.

fbtreeHeight already takes const fbtreeIndex *, so the pattern works. Apply the same change to fbtreeLength, fbtreeGetAtRank, fbtreePeekMin, fbtreePeekMax, fbtreeCountRangeByScore, and fbtreeCountRangeByValue, then drop the casts here.

Also applies to: 256-270

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordered_index.c` around lines 226 - 245, Constify the read-only fbtree
APIs used by orderedIndexLength, orderedIndexGetByIndex, orderedIndexGetFirst,
orderedIndexGetLast, and the query functions near lines 256–270, including
fbtreeLength, fbtreeGetAtRank, fbtreePeekMin, fbtreePeekMax,
fbtreeCountRangeByScore, and fbtreeCountRangeByValue. Update their declarations
and definitions to accept const fbtreeIndex pointers, then remove the non-const
casts at each call site while preserving behavior.
src/unit/test_fbtree.cpp (1)

822-858: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Reduce the item count in DeepTree4Levels.

This test inserts NODE_SIZE * NODE_SIZE * NODE_SIZE + 10000 items, which is 236981 with NODE_SIZE == 61. Each item is a separate sds allocation, and the test then iterates the first half one element at a time. Under the sanitizer builds this dominates the unit-test runtime.

A four-level tree needs only slightly more than NODE_SIZE^3 items at full fill, and far fewer at the realistic fill factor. Assert the height with fbtreeHeight instead of assuming it from the count, and lower the count to the smallest value that reaches height 4.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/unit/test_fbtree.cpp` around lines 822 - 858, Reduce the item count in
DeepTree4Levels to the smallest value that produces a four-level tree instead of
NODE_SIZE * NODE_SIZE * NODE_SIZE + 10000. Replace the implicit depth assumption
with an assertion on fbtreeHeight(fbt), while preserving the existing validity,
length, lookup, and iterator checks.
src/fbtree.h (1)

69-73: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Declare fbtreeDebugValidate in one header only.

This header declares fbtreeDebugValidate. src/fbtree_internal.h line 90 declares the same prototype and describes it as "test-only, not part of the public API". The two statements contradict each other. Keep the declaration in the public header and remove the duplicate from the internal header, or the reverse.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.h` around lines 69 - 73, Keep the fbtreeDebugValidate declaration
in only one header to eliminate the conflicting API descriptions. Since the diff
places it in the public header, remove the duplicate prototype and associated
contradictory comment from fbtree_internal.h, preserving the public declaration
and its documented signature.
src/ordered_index.h (1)

26-33: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Include <stdint.h> for uint64_t.

Line 33 declares OrderedIndexIterator as an array of uint64_t. The header includes sds.h, <stdbool.h>, and <stddef.h>, but not <stdint.h>. The declaration compiles today only if sds.h pulls in <stdint.h> transitively. Add the include so the header does not depend on that.

🔧 Proposed fix
 `#include` "sds.h"
 `#include` <stdbool.h>
 `#include` <stddef.h>
+#include <stdint.h>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/ordered_index.h` around lines 26 - 33, Add an explicit <stdint.h> include
alongside the standard headers in ordered_index.h so the uint64_t used by
OrderedIndexIterator is defined without relying on sds.h’s transitive includes.
src/server.c (1)

634-634: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Share FBTREE_SCORE_SIZE with the code that owns the packed layout.

The packed item layout [8B score][element] is produced by the ordered index / fbtree code, but the size constant is redefined here. If the packing changes, this copy diverges silently and the hash and compare callbacks read the wrong bytes. Export the constant from ordered_index.h (or fbtree.h) and include it here instead.

#!/bin/bash
# Check whether a score-size constant already exists in the fbtree/ordered_index headers.
rg -n 'SCORE_SIZE|sizeof\(double\)' src/fbtree.h src/fbtree_internal.h src/ordered_index.h src/ordered_index.c 2>/dev/null
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server.c` at line 634, Remove the local FBTREE_SCORE_SIZE definition in
server.c and expose the packed score-size constant from the owning
ordered-index/fbtree header, preferably ordered_index.h or fbtree.h. Include
that header in server.c and update its hash/compare callbacks to use the shared
FBTREE_SCORE_SIZE symbol, preserving the [8B score][element] layout.
src/db.c (1)

1091-1099: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the element pointer extracted at line 1069.

orderedIndexItemGetElement is called twice on the same entry. The values from line 1069 are still valid here. Drop the second call and use zset_ptr and zset_ele_len.

♻️ Proposed simplification
     if (o->type == OBJ_ZSET) {
         /* zset data is copied */
-        const char *ptr;
-        size_t ele_len;
-        orderedIndexItemGetElement((const OrderedIndexItem *)entry, &ptr, &ele_len);
-        key = sdsnewlen(ptr, ele_len);
+        key = sdsnewlen(zset_ptr, zset_ele_len);
         if (!data->only_keys) {
             char buf[MAX_LONG_DOUBLE_CHARS];
             int len = ld2string(buf, sizeof(buf), orderedIndexItemGetScore((const OrderedIndexItem *)entry), LD_STR_AUTO);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/db.c` around lines 1091 - 1099, In the OBJ_ZSET branch, remove the
redundant orderedIndexItemGetElement call and reuse the previously extracted
zset_ptr and zset_ele_len values when constructing key with sdsnewlen. Keep the
existing score serialization logic unchanged.
src/lazyfree.c (1)

145-147: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

orderedIndexLength over-estimates the free effort for a B+tree.

This function estimates the number of allocations to free. The skiplist allocated one node per element, so the element count was a good proxy. A B+tree packs many elements into each leaf node, so the number of allocations is closer to length / fanout. zs->ht also has no entryDestructor, so its entries cost nothing to free.

The result is that freeObjAsync crosses LAZYFREE_THRESHOLD and dispatches a bio job for sorted sets that are cheap to free inline. The behavior is safe but adds background-job overhead. If the ordered index exposes a node or allocation count, use it here.

#!/bin/bash
# Look for a node-count or allocation-count accessor on the ordered index.
rg -n 'orderedIndex[A-Za-z]*\(' src/ordered_index.h
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lazyfree.c` around lines 145 - 147, Update the B+tree branch in the
lazy-free size estimation around orderedIndexLength to use the ordered index’s
node or allocation-count accessor from ordered_index.h instead of the element
count. Keep the existing zset hash-table handling unchanged, and ensure the
estimate reflects allocations that actually require freeing so cheap sorted sets
remain eligible for inline cleanup.
src/rdb.c (1)

958-982: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update the stale skiplist wording in the save comment.

Lines 964-969 mention "skiplist" three times. The backend is now the ordered index. Update the wording so the rationale matches the implementation.

📝 Proposed comment update
-            /* We save the skiplist elements from the greatest to the smallest
-             * (that's trivial since the elements are already ordered in the
-             * skiplist): this improves the load process, since the next loaded
-             * element will always be the smaller, so adding to the skiplist
-             * will always immediately stop at the head, making the insertion
-             * O(1) instead of O(log(N)). */
+            /* We save the elements from the greatest to the smallest (that is
+             * trivial since the ordered index already keeps them sorted): this
+             * improves the load process, since every next loaded element is
+             * smaller than the previous one, which is the optimal insertion
+             * order for the ordered index. */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rdb.c` around lines 958 - 982, Update the save-order comment above
orderedIndexInitIterator to replace stale skiplist terminology with
ordered-index terminology, while preserving the explanation that reverse-order
serialization enables O(1) insertion during loading.
src/t_zset.c (2)

43-96: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the stale duplicate comment above zsetLexCompare.

Line 76 is the old comment for the previous two-sds signature. Lines 77-78 describe the new raw-buffer signature. Keep only the second comment.

♻️ Proposed cleanup
-/* Compare two sds strings handling shared.minstring/maxstring as -inf/+inf. */
 /* Compare a raw element (ptr+len) against an sds range bound.
  * Either side may be shared.minstring/maxstring as -inf/+inf sentinels. */
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/t_zset.c` around lines 43 - 96, Remove the stale “Compare two sds
strings…” comment immediately preceding zsetLexCompare, preserving only the
comment documenting its raw element buffer and sds range-bound signature.

1404-1411: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Confirm that hashtableSize() is the correct emptiness test after a range delete.

Line 1414 uses hashtableSize(zs->ht) == 0 to decide whether to delete the key. The delete callback removes each item from the hashtable, so the hashtable size and the ordered-index length must stay equal. If orderedIndexDeleteRangeBy*() can skip the callback for any item, the two counters diverge and the key survives with an empty ordered index. Use orderedIndexLength(zs->oi) == 0 or zsetLength(zobj) == 0 to test the authoritative counter.

♻️ Proposed change
         hashtableResumeAutoShrink(zs->ht);
-        if (hashtableSize(zs->ht) == 0) {
+        if (orderedIndexLength(zs->oi) == 0) {
             dbDelete(c->db, key);
             keyremoved = 1;
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/t_zset.c` around lines 1404 - 1411, Update the post-range-delete
emptiness check in the BTREE branch to use the authoritative ordered-set count,
such as orderedIndexLength(zs->oi) or zsetLength(zobj), instead of
hashtableSize(zs->ht). Keep the existing key-deletion behavior while ensuring
skipped delete callbacks cannot leave an empty ordered index retained.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/debug.c`:
- Around line 1189-1193: Declare orderedIndexGetHeight in ordered_index.h with
the definition’s matching signature, then remove the block-scope extern from the
OBJ_ENCODING_BTREE branch in src/debug.c. Keep the existing call through the
ordered index unchanged so it uses the shared header declaration and
compile-time type checking.

In `@src/fbtree.c`:
- Line 1330: Define SCORE_SIZE once in src/fbtree.h and export it for shared
use. Remove the local definition in src/fbtree.c at lines 1330-1330 and the
local definition in src/ordered_index.c at lines 22-22, ensuring
findChildIndexByScore, leafNodeBinarySearchByScore, leafCmpByScore,
packScoreElement, and unpackScore all use the shared score-prefix width.

In `@src/module.c`:
- Around line 5096-5100: Track ordered-index iterator initialization explicitly
in the zset range state: add or reuse a flag set whenever
orderedIndexInitIterator() runs, clear it in zsetKeyReset(), and update
VM_ZsetRangeStop() to call orderedIndexResetIterator() only when that flag is
set rather than checking the current encoding.

In `@src/object.c`:
- Around line 1240-1254: Update the OBJ_ENCODING_BTREE memory-sampling logic to
pass each hashtable entry through orderedIndexItemGetElement() before calling
sdsAllocSize(), since next points to an OrderedIndexItem rather than an sds.
Preserve the existing sampling and aggregate size calculation in the BTREE
branch.

In `@src/ordered_index.c`:
- Around line 183-213: Extract the duplicated lex-bound construction from
orderedIndexDeleteRangeByLex and orderedIndexCountLexRange into one helper that
returns min_packed, max_packed, and effective max_ex, preserving the minstring,
maxstring, and next-score-prefix sentinel rules. Replace both inline
implementations with calls to this helper, and add the same full-range fast path
for min == minstring and max == maxstring to orderedIndexDeleteRangeByLex so
deletion and counting use identical bounds.
- Around line 469-504: Validate the far lexicographical bound in
orderedIndexSeekToLexRange after applying the offset, matching the out-of-range
reset behavior of orderedIndexSeekToScoreRange. Ensure both forward and reverse
seeks reset the iterator when the resulting element lies beyond max or min, so
orderedIndexNext returns NULL rather than an element outside the requested
range; first preserve any caller-side checks only if they already guarantee this
behavior.

In `@src/rdb.c`:
- Around line 2121-2128: In the zset restore flow around orderedIndexInsert and
hashtableAdd, detect whether the element already exists before inserting it into
the ordered index, then report corruption and release resources through the
existing cleanup path. Verify orderedIndexFree cleanup behavior as needed, and
remove the stale comment claiming sdsele is released with o because it is
already freed unconditionally.

In `@src/server.c`:
- Around line 636-653: Add a debug assertion in zsetExtractElement before the
packed fbtree-item branch uses the score prefix, validating that the SDS length
is at least FBTREE_SCORE_SIZE. Keep the existing packed-item offset and length
behavior unchanged while making undersized or misclassified inputs fail loudly
in debug builds.

In `@src/server.h`:
- Around line 1499-1520: Update the comment above zsetMarkLookupKey,
zsetUnmarkLookupKey, and zsetIsLookupKey to document that aux bit 0 is reserved
for lookup keys on SDS values reaching zsetHashtableType, packed fbtree items
must keep it clear, and these helpers are not safe during concurrent reads.
Verify all aux-bit users for conflicts and inspect every
zsetMarkLookupKey/zsetUnmarkLookupKey window to ensure no SDS accessor,
especially sdslen, runs while an SDS_TYPE_5 key is marked.

In `@src/t_zset.c`:
- Around line 1331-1338: The ownership comment above zsetIndexDeleteCallback is
incorrect: update it to state that the ordered index retains responsibility for
freeing deleted items, consistent with zsetRemoveFromIndex and
orderedIndexDeleteRangeBy*. Keep hashtableDelete unchanged, and document at the
const-to-sds cast that the callback’s const item is intentionally discarded
because the hashtable API requires a mutable key.

In `@src/unit/test_fbtree.cpp`:
- Around line 9-13: Refactor src/unit/test_fbtree.cpp to follow the minimal C++
test style: replace all std::vector<std::string> usage in collectForward,
collectBackward, and property tests with zmalloc-backed sds arrays, replace
std::sort and lambda comparators with qsort and a named sds comparison function,
and replace every auto declaration with explicit types. Remove the now-unused
STL headers, following collectIndexToSds and sortSdsArray in
test_ordered_index.cpp as the implementation pattern.

---

Minor comments:
In @.config/typos.toml:
- Around line 18-19: Remove the Ba entry from the typo configuration while
preserving the Addd exception and existing file exclusions.

In `@src/fbtree.c`:
- Around line 1388-1399: In fbtreeSeekToScore and fbtreeSeekToValue, remove the
assignments that set it->fbt to NULL when the index is missing or has no root.
Preserve the iterator’s existing fbt reference while using its state and
current_leaf fields to represent the empty-tree result, matching
fbtreeSeekToRank and allowing subsequent seeks to reuse the iterator.
- Around line 1330-1381: Document in fbtree.h that every score-based entry point
requires keys/values to be at least SCORE_SIZE bytes long, including
fbtreeSeekToScore, fbtreeDeleteRangeByScore, and fbtreeCountRangeByScore. Add a
debug-build assertion in leafNodeBinarySearchByScore validating each searched
leaf value meets this minimum before the fixed-width memcmp, while leaving
general insertion support for shorter strings unchanged.
- Around line 2554-2557: Make the defragmentation callback contract explicit and
safe: update the fbtreeDefragScan documentation in fbtree.h and the
OrderedIndexDefragCallback documentation in ordered_index.h to state that
callbacks are mandatory, and ensure orderedIndexScanDefrag does not pass a NULL
callback through defragItemCallback. Alternatively, add NULL guards before
invoking item_callback in fbtreeDefragScan and the forwarded callback path while
preserving existing defragmentation behavior.

In `@src/module.c`:
- Around line 223-231: Update the comment on the OrderedIndexIterator field oi
in the zset iterator structure to say it is used for BTREE encoding instead of
skiplist encoding; leave the field and surrounding comments unchanged.

In `@src/ordered_index.c`:
- Around line 242-245: Update orderedIndexGetIndex to assert that the rank
returned by fbtreeGetIndexOfItem is nonnegative before casting it to unsigned
long, enforcing the documented requirement that the item exists in the index.
- Around line 108-115: Update orderedIndexUpdateScore to check the boolean
result of fbtreeDelete before inserting new_packed; if deletion fails because
the item is absent, signal the documented caller error using the existing
assertion/error-handling convention instead of inserting. Only call fbtreeInsert
after successful deletion.

In `@src/ordered_index.h`:
- Around line 227-232: Document the NULLability contract for callback in
orderedIndexScanDefrag: either state that callers must provide a non-NULL
callback, consistent with defragItemCallback and fbtreeDefragScan, or make
callback optional by adding the necessary NULL checks before invocation.

In `@src/unit/test_fbtree.cpp`:
- Around line 3559-3565: Remove the five stale comment blocks in the edge-range
deletion test section, including those before the unrelated test statements and
LookupWithParentPrefixExceedingChildPrefix. Do not add replacement comments or
restore tests; leave the existing test implementations unchanged.

In `@src/unit/test_ordered_index.cpp`:
- Around line 1266-1272: Extend the ordered-index lex-seek tests around
orderedIndexInitIterator and seekToLexRange by using an index containing members
beyond the requested max, such as apple through elderberry. Seek the range
["banana", "cherry"] with offset 5 and assert orderedIndexNext returns nullptr,
ensuring the far-bound check is exercised rather than index exhaustion.

In `@tests/integration/convert-ziplist-zset-on-load.tcl`:
- Line 22: Update the sorted-set encoding test labels and comments surrounding
assert_encoding in convert-ziplist-zset-on-load.tcl, replacing skiplist
references with the public btree encoding name while preserving the existing
assertions and test behavior.

In `@tests/unit/sort.tcl`:
- Around line 174-217: Rename the three test labels in the diff from “skiplist”
to “btree” while preserving their existing test logic and assertions, so each
test name accurately reflects the forced and asserted encoding.

---

Nitpick comments:
In `@src/db.c`:
- Around line 1091-1099: In the OBJ_ZSET branch, remove the redundant
orderedIndexItemGetElement call and reuse the previously extracted zset_ptr and
zset_ele_len values when constructing key with sdsnewlen. Keep the existing
score serialization logic unchanged.

In `@src/fbtree_internal.h`:
- Around line 9-13: Add <assert.h> to the include list in fbtree_internal.h so
its static_assert uses are self-contained for any translation unit that includes
the header directly.
- Around line 20-24: Add an explicit preprocessor `#else` branch after the
UINT64_MAX and UINT32_MAX cases in the EMBED_PREFIX_LEN configuration, emitting
`#error` for unsupported pointer widths so the build fails with a clear cause
instead of leaving EMBED_PREFIX_LEN undefined.
- Around line 21-23: Correct the stale comments in the EMBED_PREFIX_LEN
definitions to consistently describe the 2048-byte innerNode limit used by the
corresponding assertions, including the 64-bit comment. Update the
MAX_TREE_DEPTH comment to explain the rationale for choosing depth 16 instead of
referencing depth 6 or 61^6; leave the constants and assertions unchanged.

In `@src/fbtree.c`:
- Around line 2601-2622: Update fbtreeEstimateStructureMemory’s leaf-count
extrapolation to guard against items_seen being zero before dividing by the
sampled fill. When all sampled leaves report no items, use a safe finite leaf
estimate instead of evaluating the zero divisor; preserve the existing exact
estimate for fully traversed leaves and the current extrapolation for positive
items_seen.
- Around line 2296-2302: Annotate validateFail with the compiler printf-format
attribute using fmt as the format parameter and the variadic arguments as the
checked arguments. Preserve the existing validation and vsnprintf behavior while
enabling compile-time format checking for future callers.
- Around line 684-717: Wrap all four test wrapper
functions—featureSearchSIMD_test_wrapper, featureSearchSIMD_avx2_test_wrapper,
featureSearchSIMD_sse2_test_wrapper, and
featureSearchSIMD_scalar_test_wrapper—in the repository’s existing
unit-test-only preprocessor conditional, identified from other C sources, so
none are compiled or exported in release builds.
- Around line 1527-1544: Add an assertion that *path_depth is less than
MAX_TREE_DEPTH immediately before the path and path_idx writes in
descendSubPath. Apply the same pre-write bound assertion to the corresponding
array writes in buildBoundaryPaths, fbtreeDeleteRangeByRank, and
fbtreeDefragScan, preserving the existing traversal behavior.

In `@src/fbtree.h`:
- Around line 69-73: Keep the fbtreeDebugValidate declaration in only one header
to eliminate the conflicting API descriptions. Since the diff places it in the
public header, remove the duplicate prototype and associated contradictory
comment from fbtree_internal.h, preserving the public declaration and its
documented signature.

In `@src/lazyfree.c`:
- Around line 145-147: Update the B+tree branch in the lazy-free size estimation
around orderedIndexLength to use the ordered index’s node or allocation-count
accessor from ordered_index.h instead of the element count. Keep the existing
zset hash-table handling unchanged, and ensure the estimate reflects allocations
that actually require freeing so cheap sorted sets remain eligible for inline
cleanup.

In `@src/ordered_index.c`:
- Around line 333-355: In seekForBound, merge the duplicated !reverse &&
!inclusive and reverse && inclusive branches into one reverse == inclusive
condition containing the shared fbtreeNext/fbtreePrev adjustment. Consolidate
both behavioral explanations into a single comment while leaving the other cases
unchanged.
- Around line 226-245: Constify the read-only fbtree APIs used by
orderedIndexLength, orderedIndexGetByIndex, orderedIndexGetFirst,
orderedIndexGetLast, and the query functions near lines 256–270, including
fbtreeLength, fbtreeGetAtRank, fbtreePeekMin, fbtreePeekMax,
fbtreeCountRangeByScore, and fbtreeCountRangeByValue. Update their declarations
and definitions to accept const fbtreeIndex pointers, then remove the non-const
casts at each call site while preserving behavior.

In `@src/ordered_index.h`:
- Around line 26-33: Add an explicit <stdint.h> include alongside the standard
headers in ordered_index.h so the uint64_t used by OrderedIndexIterator is
defined without relying on sds.h’s transitive includes.

In `@src/rdb.c`:
- Around line 958-982: Update the save-order comment above
orderedIndexInitIterator to replace stale skiplist terminology with
ordered-index terminology, while preserving the explanation that reverse-order
serialization enables O(1) insertion during loading.

In `@src/server.c`:
- Line 634: Remove the local FBTREE_SCORE_SIZE definition in server.c and expose
the packed score-size constant from the owning ordered-index/fbtree header,
preferably ordered_index.h or fbtree.h. Include that header in server.c and
update its hash/compare callbacks to use the shared FBTREE_SCORE_SIZE symbol,
preserving the [8B score][element] layout.

In `@src/t_zset.c`:
- Around line 43-96: Remove the stale “Compare two sds strings…” comment
immediately preceding zsetLexCompare, preserving only the comment documenting
its raw element buffer and sds range-bound signature.
- Around line 1404-1411: Update the post-range-delete emptiness check in the
BTREE branch to use the authoritative ordered-set count, such as
orderedIndexLength(zs->oi) or zsetLength(zobj), instead of
hashtableSize(zs->ht). Keep the existing key-deletion behavior while ensuring
skipped delete callbacks cannot leave an empty ordered index retained.

In `@src/unit/test_fbtree.cpp`:
- Around line 822-858: Reduce the item count in DeepTree4Levels to the smallest
value that produces a four-level tree instead of NODE_SIZE * NODE_SIZE *
NODE_SIZE + 10000. Replace the implicit depth assumption with an assertion on
fbtreeHeight(fbt), while preserving the existing validity, length, lookup, and
iterator checks.

In `@tests/integration/convert-ziplist-zset-on-load.tcl`:
- Line 22: Rename the stale test titles to use the btree encoding name: update
tests/integration/convert-ziplist-zset-on-load.tcl lines 22-22 to “converts to
btree when zset-max-ziplist-entries is exceeded,” tests/unit/keyspace.tcl lines
321-321 to “COPY basic usage for btree sorted set,” and
tests/unit/moduleapi/scan.tcl lines 43-43 to “Module scan zset btree.”
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1817a15d-52f2-45de-b7bf-dc895ac14cba

📥 Commits

Reviewing files that changed from the base of the PR and between 49d7d96 and 68307ab.

📒 Files selected for processing (35)
  • .config/typos.toml
  • cmake/Modules/SourceFiles.cmake
  • src/Makefile
  • src/aof.c
  • src/db.c
  • src/debug.c
  • src/defrag.c
  • src/fbtree.c
  • src/fbtree.h
  • src/fbtree_internal.h
  • src/geo.c
  • src/lazyfree.c
  • src/module.c
  • src/object.c
  • src/ordered_index.c
  • src/ordered_index.h
  • src/rdb.c
  • src/server.c
  • src/server.h
  • src/sort.c
  • src/t_zset.c
  • src/unit/Makefile
  • src/unit/test_fbtree.cpp
  • src/unit/test_ordered_index.cpp
  • src/unit/wrappers.h
  • src/valkey-check-rdb.c
  • tests/integration/convert-ziplist-zset-on-load.tcl
  • tests/integration/dismiss-mem.tcl
  • tests/support/util.tcl
  • tests/unit/aofrw.tcl
  • tests/unit/keyspace.tcl
  • tests/unit/moduleapi/scan.tcl
  • tests/unit/scan.tcl
  • tests/unit/sort.tcl
  • tests/unit/type/zset.tcl

Comment thread src/debug.c Outdated
Comment on lines +1189 to +1193
if (o->encoding == OBJ_ENCODING_BTREE) {
/* Not declared in ordered_index.h — debug-only introspection. */
extern int orderedIndexGetHeight(const OrderedIndex *oi);
serverLog(LL_WARNING, "Index height: %d", orderedIndexGetHeight(((const zset *)o->ptr)->oi));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Declare orderedIndexGetHeight in ordered_index.h instead of using a block-scope extern.

src/debug.c already includes ordered_index.h at line 31. A local extern declaration bypasses the type check against the definition, so a signature change in ordered_index.c compiles and links without error and produces undefined behavior at the call site. The code also only compiles under UNSAFE_CRASH_REPORT, so a linkage break (for example if the definition is static) is not caught by normal builds.

Add the prototype to ordered_index.h and delete the local extern.

#!/bin/bash
# Check the definition, its linkage, and whether the header already declares it.
rg -n -B2 -A6 'orderedIndexGetHeight' src/ordered_index.c src/ordered_index.h src/fbtree.h src/fbtree.c 2>/dev/null
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/debug.c` around lines 1189 - 1193, Declare orderedIndexGetHeight in
ordered_index.h with the definition’s matching signature, then remove the
block-scope extern from the OBJ_ENCODING_BTREE branch in src/debug.c. Keep the
existing call through the ordered index unchanged so it uses the shared header
declaration and compile-time type checking.

Comment thread src/fbtree.c
it->state = (rank == 0) ? ITER_BEFORE_START : ITER_AT_POSITION;
}

#define SCORE_SIZE sizeof(double) /* Normalized score prefix size */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

SCORE_SIZE has two independent definitions across the producer-consumer boundary. src/ordered_index.c writes the packed key as [8-byte sortable score][element], and src/fbtree.c reads exactly SCORE_SIZE bytes back in findChildIndexByScore, leafNodeBinarySearchByScore, and leafCmpByScore. Each file defines the constant separately, one as sizeof(double) and one as the literal 8. If either definition changes, the two sides silently disagree on the key layout, and score comparisons read the wrong bytes. No compiler check or unit test would catch the divergence. Define the constant once and share it.

  • src/fbtree.c#L1330-L1330: remove the local #define SCORE_SIZE sizeof(double) and use the shared definition exported from src/fbtree.h.
  • src/ordered_index.c#L22-L22: remove the local #define SCORE_SIZE 8 and use the same shared definition from src/fbtree.h, so the packing in packScoreElement and the unpacking in unpackScore cannot drift from the tree's score-prefix width.
📍 Affects 2 files
  • src/fbtree.c#L1330-L1330 (this comment)
  • src/ordered_index.c#L22-L22
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fbtree.c` at line 1330, Define SCORE_SIZE once in src/fbtree.h and export
it for shared use. Remove the local definition in src/fbtree.c at lines
1330-1330 and the local definition in src/ordered_index.c at lines 22-22,
ensuring findChildIndexByScore, leafNodeBinarySearchByScore, leafCmpByScore,
packScoreElement, and unpackScore all use the shared score-prefix width.

Comment thread src/module.c
Comment on lines +5096 to +5100
/* Reset the ordered index iterator if one was active. */
if (key->value->encoding == OBJ_ENCODING_BTREE &&
key->u.zset.type != VALKEYMODULE_ZSET_RANGE_NONE) {
orderedIndexResetIterator(&key->u.zset.oi);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

VM_ZsetRangeStop() can reset an uninitialized iterator.

The guard tests the current encoding of key->value. It does not test whether key->u.zset.oi was ever initialized. A module can start a range on a LISTPACK-encoded sorted set, then call VM_ZsetAdd() enough times to convert the value to BTREE through zsetAdd(), then call VM_ZsetRangeStop(). In that sequence, orderedIndexResetIterator() runs on an OrderedIndexIterator that zsetInitScoreRange() and zsetInitLexRange() never initialized.

Track the iterator state explicitly instead of deriving it from the encoding. Set a flag when orderedIndexInitIterator() runs, clear it in zsetKeyReset(), and test that flag here.

#!/bin/bash
# Check zsetKeyReset and whether OrderedIndexIterator tolerates reset before init.
rg -nP -B3 -A20 'static\s+void\s+zsetKeyReset' src/module.c
fd -t f 'ordered_index\.(c|h)$' --exec rg -n -B8 -A25 'orderedIndexResetIterator|orderedIndexInitIterator' {}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/module.c` around lines 5096 - 5100, Track ordered-index iterator
initialization explicitly in the zset range state: add or reuse a flag set
whenever orderedIndexInitIterator() runs, clear it in zsetKeyReset(), and update
VM_ZsetRangeStop() to call orderedIndexResetIterator() only when that flag is
set rather than checking the current encoding.

Comment thread src/object.c Outdated
Comment on lines +1240 to +1254
} else if (o->encoding == OBJ_ENCODING_BTREE) {
zset *zs = objectGetVal(o);
hashtableIterator iter;
hashtableInitIterator(&iter, zs->ht, 0);
void *next;

asize += sizeof(zset) + orderedIndexEstimateStructureMemory(zs->oi) + hashtableMemUsage(zs->ht);
/* The hashtable entries are the packed items shared with the
* ordered index, so sampling them covers the member payloads. */
while (hashtableNext(&iter, &next) && samples < sample_size) {
elesize += sdsAllocSize((sds)next);
samples++;
znode = znode->level[0].forward;
}
if (samples) asize += (double)elesize / samples * hashtableSize(ht);
hashtableCleanupIterator(&iter);
if (samples) asize += (double)elesize / samples * hashtableSize(zs->ht);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Verify that sdsAllocSize((sds)next) is valid for a packed OrderedIndexItem.

The hashtable entries are packed OrderedIndexItem pointers, not sds pointers. src/t_zset.c line 1336 states that the element starts at offset 8 inside the packed item. sdsAllocSize() dereferences s[-1] to read the sds header flags. If next points to the start of the item allocation, this read is out of bounds and the computed size is wrong.

Every other call site in this PR uses orderedIndexItemGetElement() to read the member. Use the same accessor here, or use an ordered-index memory API for the item.

🐛 Proposed fix using the ordered-index accessor
             while (hashtableNext(&iter, &next) && samples < sample_size) {
-                elesize += sdsAllocSize((sds)next);
+                const char *ele_ptr;
+                size_t ele_len;
+                orderedIndexItemGetElement((const OrderedIndexItem *)next, &ele_ptr, &ele_len);
+                elesize += ele_len;
                 samples++;
             }
#!/bin/bash
# Inspect the OrderedIndexItem layout and accessors to confirm whether the item pointer is a valid sds.
fd -t f 'ordered_index\.(c|h)$'
fd -t f 'ordered_index\.(c|h)$' --exec rg -n -C8 'OrderedIndexItem|orderedIndexItemGetElement|orderedIndexItemCreate|zsetExtractElement|offsetof' {}
# Check any memory-usage helper already provided for items.
rg -nP 'orderedIndexItem[A-Za-z]*Mem|orderedIndexEstimate|orderedIndexItemAllocSize' --type=c --type=cpp
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/object.c` around lines 1240 - 1254, Update the OBJ_ENCODING_BTREE
memory-sampling logic to pass each hashtable entry through
orderedIndexItemGetElement() before calling sdsAllocSize(), since next points to
an OrderedIndexItem rather than an sds. Preserve the existing sampling and
aggregate size calculation in the BTREE branch.

Comment thread src/ordered_index.c Resolved
Comment thread src/rdb.c Resolved
Comment thread src/server.c Resolved
Comment thread src/server.h Resolved
Comment thread src/t_zset.c Resolved
Comment thread src/unit/test_fbtree.cpp Resolved
@codecov

codecov Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.94914% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.61%. Comparing base (fd3d2f9) to head (806cc9f).
⚠️ Report is 1 commits behind head on unstable.

Files with missing lines Patch % Lines
src/module.c 0.00% 44 Missing ⚠️
src/db.c 75.00% 3 Missing ⚠️
src/ordered_index.c 99.22% 2 Missing ⚠️
src/unit/test_ordered_index.cpp 99.94% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #4359      +/-   ##
============================================
+ Coverage     77.21%   78.61%   +1.39%     
============================================
  Files           162      166       +4     
  Lines         81842    88242    +6400     
============================================
+ Hits          63198    69372    +6174     
- Misses        18644    18870     +226     
Files with missing lines Coverage Δ
src/aof.c 80.33% <100.00%> (+0.02%) ⬆️
src/debug.c 55.95% <100.00%> (+0.07%) ⬆️
src/defrag.c 80.13% <100.00%> (-1.00%) ⬇️
src/fbtree.c 95.52% <ø> (ø)
src/geo.c 93.95% <100.00%> (-0.37%) ⬇️
src/lazyfree.c 88.38% <100.00%> (ø)
src/object.c 92.81% <100.00%> (+3.78%) ⬆️
src/rdb.c 77.16% <100.00%> (-0.24%) ⬇️
src/server.c 89.61% <100.00%> (+0.07%) ⬆️
src/server.h 100.00% <100.00%> (ø)
... and 8 more

... and 19 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/t_zset.c (1)

215-222: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the stale skiplist rationale.

The comment describes conversion to a skiplist and skiplist RDB validation. This code now validates listpack scores before BTREE conversion through OrderedIndex. Update the comment to describe the current invariant and failure path.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/t_zset.c` around lines 215 - 222, Update the comment above the listpack
score validation function to reference validation before BTREE conversion
through OrderedIndex instead of skiplist conversion or skiplist RDB loading.
Describe that rejecting NAN scores preserves the OrderedIndex invariant and
prevents the subsequent conversion failure path, while retaining the existing
structural-layout and return-value details.
src/debug.c (1)

1781-1781: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Remove the duplicate bt_frame_state definition.

bt_frame_state is defined twice. Builds with USE_LIBBACKTRACE fail with a redefinition error. Keep one definition.

Proposed fix
 static struct backtrace_state *bt_frame_state = NULL;
-static struct backtrace_state *bt_frame_state = NULL;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/debug.c` at line 1781, Remove the duplicate definition of the file-scope
variable bt_frame_state in src/debug.c, retaining exactly one static struct
backtrace_state *bt_frame_state declaration so USE_LIBBACKTRACE builds no longer
encounter a redefinition.
🧹 Nitpick comments (1)
tests/unit/type/zset.tcl (1)

2666-2737: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove duplicate XX test coverage.

The test at Line 2666 duplicates the complete test at Line 2593. Lines 721-722 and Lines 868-869 also repeat the prior assertion. Keep one assertion for each case.

  • tests/unit/type/zset.tcl#L2666-L2737: Remove the duplicate ZRANGE with/without XX test block.
  • tests/unit/type/zset.tcl#L721-L722: Remove the repeated ZREVRANGEBYSCORE assertion.
  • tests/unit/type/zset.tcl#L868-L869: Remove the repeated ZREVRANGEBYLEX assertion.

As per coding guidelines, keep changes minimal and easy to backport.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/type/zset.tcl` around lines 2666 - 2737, Remove the duplicate
ZRANGE with/without XX test block in tests/unit/type/zset.tcl lines 2666-2737,
retaining the earlier coverage. Also remove the repeated ZREVRANGEBYSCORE
assertion at tests/unit/type/zset.tcl lines 721-722 and the repeated
ZREVRANGEBYLEX assertion at lines 868-869; make no other changes.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/debug.c`:
- Line 1781: Remove the duplicate definition of the file-scope variable
bt_frame_state in src/debug.c, retaining exactly one static struct
backtrace_state *bt_frame_state declaration so USE_LIBBACKTRACE builds no longer
encounter a redefinition.

In `@src/t_zset.c`:
- Around line 215-222: Update the comment above the listpack score validation
function to reference validation before BTREE conversion through OrderedIndex
instead of skiplist conversion or skiplist RDB loading. Describe that rejecting
NAN scores preserves the OrderedIndex invariant and prevents the subsequent
conversion failure path, while retaining the existing structural-layout and
return-value details.

---

Nitpick comments:
In `@tests/unit/type/zset.tcl`:
- Around line 2666-2737: Remove the duplicate ZRANGE with/without XX test block
in tests/unit/type/zset.tcl lines 2666-2737, retaining the earlier coverage.
Also remove the repeated ZREVRANGEBYSCORE assertion at tests/unit/type/zset.tcl
lines 721-722 and the repeated ZREVRANGEBYLEX assertion at lines 868-869; make
no other changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 06cecbf6-597a-4bba-b3b5-15d1393435c8

📥 Commits

Reviewing files that changed from the base of the PR and between 68307ab and 511080b.

📒 Files selected for processing (19)
  • src/Makefile
  • src/aof.c
  • src/db.c
  • src/debug.c
  • src/defrag.c
  • src/lazyfree.c
  • src/module.c
  • src/object.c
  • src/rdb.c
  • src/server.c
  • src/server.h
  • src/sort.c
  • src/t_zset.c
  • src/unit/Makefile
  • src/valkey-check-rdb.c
  • tests/support/util.tcl
  • tests/unit/aofrw.tcl
  • tests/unit/scan.tcl
  • tests/unit/type/zset.tcl
🚧 Files skipped from review as they are similar to previous changes (13)
  • src/server.c
  • src/lazyfree.c
  • src/sort.c
  • src/aof.c
  • tests/unit/aofrw.tcl
  • tests/unit/scan.tcl
  • src/rdb.c
  • src/valkey-check-rdb.c
  • tests/support/util.tcl
  • src/Makefile
  • src/defrag.c
  • src/db.c
  • src/module.c

@valkey-review-bot valkey-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two always-on source-policy issues remain in the new low-level fbtree implementation.

Comment thread src/fbtree.c Resolved
Comment thread src/fbtree.c Resolved
dubey02 and others added 2 commits August 9, 2026 07:09
…4363)

Fixes the three Daily CI failures on the zset-btree branch (run
31152425315): `ZRANGE basics - btree`, `ZREVRANGE basics - btree`, and
`ZSETs ZRANK augmented skip list stress testing - btree` on
test-alpine-jemalloc, test-alpine-libc-malloc, and test-alpine-32bit.

### Root cause

`fbtreeIterator` is declared as `typedef uint64_t fbtreeIterator[3]` and
`fbtree.c` accesses it through the internal `iter` struct via
`iteratorFromOpaque()` (fbtree.c line 61). That access violates strict
aliasing, so it is UB in every build. It turns into a miscompilation
when the optimizer sees both sides of the punning in one scope: the
Makefile adds `-flto=auto` at `-O3`, which merges the
`genericZrangebyrankCommand -> orderedIndexSeekToIndex ->
fbtreeSeekToRank -> fbtreeNext` chain. Alpine gcc 15.2 concludes the
seek stores through `iter *` cannot alias the `uint64_t[3]` stack object
and elides them. The iterator behaves as never seeked, which matches the
failures exactly: unseeked `fbtreeNext()` starts at the leftmost leaf
(`ZRANGE ztmp 1 -1` returns `a b c`) and unseeked `fbtreePrev()` at the
rightmost (`ZREVRANGE ztmp 1 -1` returns `d c b`). glibc jobs passing
today is an inlining accident, not safety.

### Fix

`__attribute__((may_alias))` on the internal `iter` struct. Supported by
gcc and clang, generates no code, changes no layout, and only exempts
accesses through `iter *` inside fbtree.c from type-based alias
analysis. A code comment explains why the attribute must stay.

### Validation (Docker, Alpine musl gcc 15.2.0, default `-O3 -flto`
flags)

| Cell | Result |
|---|---|
| Unfixed, default flags | 3 zset failures identical to CI |
| Unfixed, `-fno-strict-aliasing` | 0 failures |
| Unfixed, `-O3 -fno-lto` | 0 failures (isolates the trigger to LTO +
strict aliasing) |
| Union-based opaque typedef (alternative fix) | still 3 failures,
rejected |
| This fix, 64-bit musl | full zset unit green (348 tests) |
| This fix, 32-bit musl, `-Werror` + `USE_LIBBACKTRACE=yes` | full zset
unit green |
| This fix, gtest unit binary on Alpine (includes all of test_fbtree.cpp
and test_ordered_index.cpp) | 598 pass, 3 skipped, 0 fail |
| This fix, Ubuntu 24.04 glibc | zset unit green, no regression |

### Notes on the other failing Daily jobs (not addressed here)

- test-ubuntu-32bit `Active defrag - AOF loading`: pre-existing flake
tracked in #3954, occurrences predate this branch. The test loads plain
SET commands so the zset defrag rewrite is not exercised.
- test-ubuntu-io-threads and test-ubuntu-tls-io-threads: fail
identically on the unstable nightly baseline.
- test-alpine-32bit logging.tcl backtrace tests: likely a side effect of
the miscompiled binary, worth rechecking after this lands.

Separate note: `hashtable.h` uses the same `uint64_t[N]` opaque idiom
with the same cast pattern, so the same latent UB exists there. It has
not miscompiled yet. I will file a separate issue for it.

Signed-off-by: Abhishek Kumar <[email protected]>
dubey02 and others added 3 commits August 10, 2026 14:59
serverassert.h is a drop-in replacement for assert.h: it undefines and
redefines assert() to route through _serverAssert so failures produce a
crash report in the server log instead of a bare SIGABRT. fbtree.c
included both headers, which worked only because serverassert.h happened
to come last and reclaim the macro.

Drop the assert.h include and move serverassert.h before
fbtree_internal.h, since the internal header relies on static_assert
which serverassert.h also provides. A comment documents the ordering
requirement.

Signed-off-by: Abhishek Kumar <[email protected]>
Co-authored-by: Madelyn Olson <[email protected]>
Signed-off-by: Abhishek Kumar <[email protected]>
@madolson

Copy link
Copy Markdown
Member

@madolson madolson changed the title Merge zset-btree: ZSET B+ tree implementation Replace the ZSET skiplist with a B+ tree behind an ordered index Aug 11, 2026
@madolson
madolson merged commit a34bb4c into unstable Aug 11, 2026
141 of 145 checks passed
madolson added a commit to jsoref/valkey that referenced this pull request Aug 11, 2026
Resolve the conflict caused by upstream drift since this PR was opened:

- src/t_zset.c: the skiplist was replaced by a B+ tree (valkey-io#4206, valkey-io#4359), so
  zslUpdateScore and its "Otherwise the skiplist is modified by removing
  and re-adding a new element" comment no longer exist. Drop that hunk.
  The other two t_zset.c hunks (zsetRank and addZpopInitialReply) still
  apply unchanged.

Additionally fix seven sentence-initial "Otherwise" sites added upstream
after this PR was opened, so the sweep is complete against unstable:

- src/cluster_legacy.c, src/config.c, src/dict.h, src/functions.c,
  src/modules/lua/engine_lua.c, src/replication.c, src/vset.c

Verified: builds clean, clang-format-18 reports no diff across the 45
changed src/ files, server starts, ZADD/ZRANGE/ZPOPMIN/ZRANK behave
normally. Every edit lands inside a comment except the valkey-cli --help
text. Zero sentence-initial "Otherwise" without a comma remain.

Signed-off-by: Madelyn Olson <[email protected]>
@madolson madolson added release-notes This issue should get a line item in the release notes needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. labels Aug 12, 2026
@madolson

Copy link
Copy Markdown
Member

@rainsupreme when you're back, please update the docs here: valkey-io/valkey-doc#466

@enjoy-binbin
enjoy-binbin deleted the zset-btree branch August 18, 2026 22:40
rainsupreme added a commit to valkey-rainfall/valkey-doc that referenced this pull request Aug 19, 2026
The sorted set skiplist was replaced with a B+ tree in
valkey-io/valkey#4359. Update two places in valkey-doc:

1. commands/object-encoding.md: OBJECT ENCODING now returns 'btree'
   for normal sorted sets. Keep 'skiplist' as a historical note
   following the existing zipmap precedent.

2. topics/sorted-sets.md: Replace 'skip list' with 'B+ tree' in the
   implementation note. The O(log N) claim remains correct.

3. wordlist: Add 'btree' so the spellcheck workflow passes.

Closes valkey-io#466

Signed-off-by: Rain Valentine <[email protected]>
madolson pushed a commit to valkey-io/valkey-doc that referenced this pull request Aug 20, 2026
The sorted set skiplist was replaced with a B+ tree in
valkey-io/valkey#4359. Update two places in valkey-doc:

1. commands/object-encoding.md: OBJECT ENCODING now returns 'btree' for
normal sorted sets. Keep 'skiplist' as a historical note following the
existing zipmap precedent.

2. topics/sorted-sets.md: Replace 'skip list' with 'B+ tree' in the
implementation note. The O(log N) claim remains correct.

3. wordlist: Add 'btree' so the spellcheck workflow passes.

Closes #466

Signed-off-by: Rain Valentine <[email protected]>
rainsupreme added a commit to valkey-rainfall/valkey-perf-dashboard that referenced this pull request Aug 24, 2026
Companion to conductress fbtree heap-profiler category: zset B+ tree
node allocations (post valkey-io/valkey#4359) get their own band
instead of falling into 'other'.

Signed-off-by: Rain Valentine <[email protected]>
rainsupreme added a commit to rainsupreme/valkey-conductress that referenced this pull request Aug 24, 2026
Since valkey-io/valkey#4359 replaced the zset skiplist with a B+ tree,
ZADD memory-sweep node allocations fell through to 'other'. Add an
'fbtree' category matching the public fbtree* entry points plus the
static node constructors (for non-inlined builds).

- skiplist category kept: sweeps span pre-#4359 commits
- packed score+member items (sdsnewlen in ordered_index.c) stay in
  'sds', consistent with skiplist-era member SDS accounting
- raw_stacks store resolved function names, so existing sweep data
  gains the fbtree band on re-export without re-running

Signed-off-by: Rain Valentine <[email protected]>
sarthakaggarwal97 added a commit that referenced this pull request Sep 16, 2026
Move the sorted set B+ tree note (#4359) to Behavior Changes: OBJECT
ENCODING now reports btree instead of skiplist, which is a client-visible
output change and matters more for upgrade decisions than the speedup.

Drop the notes for #3366 and #3791, neither of which is user-facing.
#3366 replaces dict with a wrapper around hashtable; scoping the
configured hash seed to data hashtables keeps hash-seed doing exactly
what valkey.conf documents it to do, and stops the seed leaking into
internal tables already populated during startup. #3791 makes the ranged
memory-release helper a no-op on non-jemalloc builds to match existing
behavior.

Add two changes that triage left out:
- #3533 fixed an undersized madvise range in dismissHashtable, so only
  about an eighth of the bucket array was hinted after fork. The fix
  cuts real copy-on-write overhead during background saves.
- #4566 logs the module version on load, which is operator-visible.

Signed-off-by: Sarthak Aggarwal <[email protected]>
(cherry picked from commit 097567a)
sarthakaggarwal97 added a commit that referenced this pull request Sep 16, 2026
Remove three entries whose changes shipped before 9.2.0, so 9.1 users
don't see them advertised as new:
- #3533 (dismissHashtable madvise size) was backported to 9.1 and is in
  the 9.1.0, 9.1.1 and 9.1.2 tags. It was added here by mistake.
- #3551 (hashtable iterator invalidate on exhaustion) is likewise in
  9.1.0; it just never made the 9.1 notes.
- #3586 (valkey-cli --cluster fix slot spreading) is already documented
  in both the 9.0 and 9.1 release notes and shipped in 9.0.6 and 9.1.0.

Fix the #4076 config name: the registered config is
priority-preemptive-poll-interval-us, not preemptive-poll-interval-us,
so the name as written would be rejected by CONFIG SET.

Rewrite the #4005 entry, which described only the internal tagging. The
user-facing surface is two new configs, priority-subnets and
maxclients-reserved, which together cap normal clients at maxclients
minus the reserved count so administrative clients keep guaranteed
slots, plus a connected_priority_clients field in INFO clients.

Move the sorted set B+ tree note (#4359) back to Performance. Listing it
as a behavior change for its OBJECT ENCODING output while #3212 changes
hash encoding output from hashtable to listpack in the Performance
section was inconsistent; both now sit together.

Drop the Redis comparison from the #4629 entry, which no other entry in
the 9.0, 9.1 or 9.2 notes makes.

Signed-off-by: Sarthak Aggarwal <[email protected]>
currantw added a commit to valkey-io/valkey-glide that referenced this pull request Oct 9, 2026
Valkey 9.2 replaces the skiplist for large sorted sets with a B+ tree
(valkey-io/valkey#4359), so OBJECT ENCODING now returns "btree" instead
of "skiplist". Expect "skiplist" below 9.2.0 and "btree" from 9.2.0 on
in the Java, Node, and Python tests.

In the Python tests, compute each version-dependent expected encoding
once and assert against it, instead of repeating the assert in if/else
branches.

Go, Rust, and core tests only check string encodings and are not
affected.

Refs #7198

Signed-off-by: currantw <[email protected]>
rogerrum pushed a commit to rogerrum/k8s-gitops that referenced this pull request Nov 24, 2026
…0 ) (#3831)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [ghcr.io/valkey-io/valkey](https://github.com/valkey-io/valkey) | minor | `9.1.3` → `9.2.0` |

---

### Release Notes

<details>
<summary>valkey-io/valkey (ghcr.io/valkey-io/valkey)</summary>

### [`v9.2.0`](https://github.com/valkey-io/valkey/releases/tag/9.2.0)

[Compare Source](https://github.com/valkey-io/valkey/compare/9.1.4...9.2.0)

## Valkey 9.2.0 GA  -  Released Wed 18 November 2026

Upgrade urgency LOW: This is the first stable release of Valkey 9.2.

##### Behavior Changes

- `ZRANGEBYSCORE`, `ZREVRANGEBYSCORE`, `ZCOUNT`, and `ZRANGESTORE` now reject a bare `(` or an empty string as a score bound instead of silently treating it as 0 by [@&#8203;AlisinaDevelo](https://github.com/AlisinaDevelo) ([#&#8203;4054](https://github.com/valkey-io/valkey/issues/4054))
- Path Hash deletion commands now remove the key when the last path is deleted, following the Hash key lifecycle and emitting a generic del event by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;5068](https://github.com/valkey-io/valkey/issues/5068))
- Active expiration of keys and hash fields now increments the dirty counter, so save points (and thus BGSAVE) may trigger more often by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3118](https://github.com/valkey-io/valkey/issues/3118))

##### New Features and Enhanced Behavior

- Add new `DELEX` command to conditionally delete a string key when its value matches (`IFEQ`) or differs from (`IFNE`) a given value by [@&#8203;lightsigma96](https://github.com/lightsigma96) ([#&#8203;4607](https://github.com/valkey-io/valkey/issues/4607))
- Add Zstd as a streaming compression codec for RDB persistence and replication, offering better compression ratios than LZ4 by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;3798](https://github.com/valkey-io/valkey/issues/3798))
- Support streaming-compressed RDB preambles in AOF bases, so compressed full-sync RDB files can be reused directly as AOF bases by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;4754](https://github.com/valkey-io/valkey/issues/4754))
- `ACL GENPASS` and the hash function seed draw randomness from the configured OpenSSL 3 provider when built with TLS, supporting deployments that require a validated crypto module by [@&#8203;MarkAtwood](https://github.com/MarkAtwood) ([#&#8203;4339](https://github.com/valkey-io/valkey/issues/4339))
- Support forkless full synchronization to replicas, serving disk and diskless full syncs from a background-thread snapshot without forking by [@&#8203;nitaicaro](https://github.com/nitaicaro) ([#&#8203;4797](https://github.com/valkey-io/valkey/issues/4797))
- Add ACL DIGEST command that returns a fingerprint of the ACL rules currently in effect, useful to verify what ACL LOAD applied by [@&#8203;melancholictheory](https://github.com/melancholictheory) ([#&#8203;4446](https://github.com/valkey-io/valkey/issues/4446))
- Add forkless RDB snapshots, opt-in via the new `forkless-infrastructure-enabled` and `bgsave-default-method` configs, with new INFO persistence fields reporting the save method and progress by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;4460](https://github.com/valkey-io/valkey/issues/4460))
- Add the `XACKDEL` and `XDELEX` stream commands with `KEEPREF`, `DELREF` and `ACKED` modes to acknowledge and delete messages once consumer groups no longer need them by [@&#8203;nickiaq](https://github.com/nickiaq) ([#&#8203;4629](https://github.com/valkey-io/valkey/issues/4629))
- Support a secondary server certificate via `tls-alt-cert-file`, `tls-alt-key-file` and `tls-alt-key-file-pass`, e.g. a post-quantum certificate alongside RSA, with matching INFO TLS fields by [@&#8203;pkhartsk](https://github.com/pkhartsk) ([#&#8203;3717](https://github.com/valkey-io/valkey/issues/3717))
- Add ACL roles: named, reusable sets of ACL selectors managed with `ACL SETROLE`/`DELROLE`/`GETROLE`/`ROLES` and assigned to users with `role:<name>`, in commands, the ACL file and valkey.conf by [@&#8203;yang-z-o](https://github.com/yang-z-o) ([#&#8203;3967](https://github.com/valkey-io/valkey/issues/3967))
- Add a `maxmemory-scripts` config to limit memory used by cached `EVAL` scripts, and mark `SCRIPT LOAD` as DENYOOM so it respects the global maxmemory limit by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;866](https://github.com/valkey-io/valkey/issues/866))
- Add Path Hash, a new radix-tree-backed data type with `PH*` commands for exact lookup, longest-prefix matching, and prefix traversal over binary-safe paths by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;4506](https://github.com/valkey-io/valkey/issues/4506))
- Support whole-stream LZ4 compression of RDB files via the new `rdbcompression lz4` option; the default per-string LZF behavior is unchanged by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;3531](https://github.com/valkey-io/valkey/issues/3531))
- Add server-side hot key detection with new `HOTKEYS GET`/`RESET` commands, enabled by setting `hotkeys-top-k` by [@&#8203;alon-arenberg](https://github.com/alon-arenberg) ([#&#8203;3708](https://github.com/valkey-io/valkey/issues/3708))
- Add optional replication throttling (`repl-throttling-enabled`) that slows client writes when a replica falls behind, avoiding disconnects and full syncs by [@&#8203;harrylin98](https://github.com/harrylin98) ([#&#8203;4356](https://github.com/valkey-io/valkey/issues/4356))
- Prioritize system-critical events (cluster heartbeats, replication, slot migration) over heavy client traffic, tunable via the new `priority-preemptive-poll-interval-us` config by [@&#8203;satheeshaGowda](https://github.com/satheeshaGowda) ([#&#8203;4076](https://github.com/valkey-io/valkey/issues/4076))
- Reserve connection slots for administrative clients: connections from the CIDR ranges listed in the new `priority-subnets` config are tagged as prioritized, `maxclients-reserved` caps normal clients at `maxclients` minus that many slots, and `INFO clients` reports `connected_priority_clients` by [@&#8203;satheeshaGowda](https://github.com/satheeshaGowda) ([#&#8203;4005](https://github.com/valkey-io/valkey/issues/4005))
- Add `INCREX` command to atomically increment a key by an integer or float while setting its expiration, with `NX`/`XX` conditions by [@&#8203;GavinDmello](https://github.com/GavinDmello) ([#&#8203;3253](https://github.com/valkey-io/valkey/issues/3253))

##### Performance and Efficiency Improvements

- Fix long stalls in `SRANDMEMBER`, `ZRANDMEMBER`, `HRANDFIELD` and `SPOP` on a small key whose hashtable is still shrinking from a much larger size by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5170](https://github.com/valkey-io/valkey/issues/5170))
- Stop treating `LINDEX`, `LRANGE` and `LPOS` as format-changing commands during forkless background iteration, so list reads no longer get write-style handling by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;5283](https://github.com/valkey-io/valkey/issues/5283))
- Keep the forkless save queue growing under write load by not counting keys expedited by writes as leftover work by [@&#8203;taham0](https://github.com/taham0) ([#&#8203;5298](https://github.com/valkey-io/valkey/issues/5298))
- Make BCAST client tracking cost scale with the prefixes a key matches instead of all registered prefixes, so many unmatched prefixes no longer slow writes and the event loop by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5183](https://github.com/valkey-io/valkey/issues/5183))
- Reclaim memory from sorted sets that shrink or have frequent score updates by compacting sparse B+tree leaves on delete by [@&#8203;rainsupreme](https://github.com/rainsupreme) ([#&#8203;4526](https://github.com/valkey-io/valkey/issues/4526))
- Speed up sorted set score updates in listpack encoding by replacing the score in place when the member keeps its position by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;3491](https://github.com/valkey-io/valkey/issues/3491))
- Fix quadratic slowdown in `HRANDFIELD` and `SRANDMEMBER` with counts on collections whose elements differ only in letter case by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5167](https://github.com/valkey-io/valkey/issues/5167))
- Bound the time spent per cycle evicting keys from the client tracking table, avoiding long stalls after lowering `tracking-table-max-keys` by [@&#8203;tanmayBeginsJourney](https://github.com/tanmayBeginsJourney) ([#&#8203;4775](https://github.com/valkey-io/valkey/issues/4775))
- Speed up the `INFO` command by around 5% by pre-allocating the output buffer by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;3413](https://github.com/valkey-io/valkey/issues/3413))
- Reclaim client-side caching tracking table entries left by disconnected clients, fixing a memory leak under read-heavy workloads, and include the tracking table in active defrag by [@&#8203;rayjinghaolei](https://github.com/rayjinghaolei) ([#&#8203;4190](https://github.com/valkey-io/valkey/issues/4190))
- Speed up `ZPOPMIN` and `ZPOPMAX` on B+tree encoded sorted sets by detaching edge items without a key search or copy by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;4852](https://github.com/valkey-io/valkey/issues/4852))
- Counting a hash's fields with expirations is now O(1) for hashtable-encoded hashes by tracking the volatile set size on each mutation by [@&#8203;frostzt](https://github.com/frostzt) ([#&#8203;4829](https://github.com/valkey-io/valkey/issues/4829))
- Speed up AOF command propagation by serializing commands directly into the AOF buffer, removing an allocation and copy per command by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;3496](https://github.com/valkey-io/valkey/issues/3496))
- Cache the earliest event-loop timer to avoid an O(N) scan per iteration, reducing overhead with many timers such as RDMA connections by [@&#8203;royenheart](https://github.com/royenheart) ([#&#8203;4354](https://github.com/valkey-io/valkey/issues/4354))
- Speed up HGETALL, HKEYS and HVALS with exact-length reply headers, fused bulk replies, and entry prefetching by [@&#8203;jjuleslasarte](https://github.com/jjuleslasarte) ([#&#8203;4417](https://github.com/valkey-io/valkey/issues/4417))
- Eliminate false sharing in per-thread memory usage counters, improving throughput with I/O threads on SMT x86 systems by [@&#8203;omerrubi-amzn](https://github.com/omerrubi-amzn) ([#&#8203;4107](https://github.com/valkey-io/valkey/issues/4107))
- Read-only list iteration (e.g. LRANGE, LPOS) no longer decompresses and recompresses quicklist nodes in place, cutting CPU cost on compressed lists by [@&#8203;murphyjacob4](https://github.com/murphyjacob4) ([#&#8203;4782](https://github.com/valkey-io/valkey/issues/4782))
- Speed up ZSCAN on btree-encoded sorted sets by avoiding temporary member and score copies and prefetching items by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;4856](https://github.com/valkey-io/valkey/issues/4856))
- Reduce cache-line false sharing on IO thread activity and job counters for better multi-threaded IO performance by [@&#8203;omerrubi-amzn](https://github.com/omerrubi-amzn) ([#&#8203;4976](https://github.com/valkey-io/valkey/issues/4976))
- PHDELPREFIX now bounds its temporary path copies to 64KiB per batch, avoiding large untracked memory spikes on long shared prefixes by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5179](https://github.com/valkey-io/valkey/issues/5179))
- Speed up radix tree lookups and inserts by using SIMD-optimized memchr() for child-edge search by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;3472](https://github.com/valkey-io/valkey/issues/3472))
- Improve replica processing speed by parsing multiple commands from the replication stream at once by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3597](https://github.com/valkey-io/valkey/issues/3597))
- Reduce memory usage by sharing pubsub pattern and WATCH key objects across clients subscribing to or watching the same name by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4072](https://github.com/valkey-io/valkey/issues/4072))
- Large sorted sets are now backed by a B+ tree instead of a skiplist; OBJECT ENCODING reports `btree` instead of `skiplist` by [@&#8203;ranshid](https://github.com/ranshid) ([#&#8203;4359](https://github.com/valkey-io/valkey/issues/4359))
- Save the cluster config file from a background thread when `cluster-config-save-behavior` is best-effort, avoiding main-thread latency spikes from slow disk I/O by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;2555](https://github.com/valkey-io/valkey/issues/2555))
- Speed up `HMGET`, `SMISMEMBER` and `ZMSCORE` on large hashtable-encoded keys with batched lookups that overlap memory accesses by [@&#8203;chzhoo](https://github.com/chzhoo) ([#&#8203;4017](https://github.com/valkey-io/valkey/issues/4017))
- Extend memory prefetching to hash, set and sorted set member lookups when io-threads are enabled, improving performance for 30 field/member commands on large keys by [@&#8203;roshkhatri](https://github.com/roshkhatri) ([#&#8203;3940](https://github.com/valkey-io/valkey/issues/3940))
- `MEMORY PURGE` now also releases free pages from the glibc main arena back to the OS, reclaiming memory held by libc-internal allocations by [@&#8203;webbsssss](https://github.com/webbsssss) ([#&#8203;3640](https://github.com/valkey-io/valkey/issues/3640))
- Speed up command propagation to replicas by batching each command's RESP frame into a single replication buffer write by [@&#8203;hpatro](https://github.com/hpatro) ([#&#8203;4044](https://github.com/valkey-io/valkey/issues/4044))
- Reduce lseek system calls during disk-based replication by seeking only when a write blocks or is partial by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4053](https://github.com/valkey-io/valkey/issues/4053))
- Reduce event-loop overhead by refreshing cached daylight-saving info once per second instead of on every wakeup by [@&#8203;hpatro](https://github.com/hpatro) ([#&#8203;4086](https://github.com/valkey-io/valkey/issues/4086))
- Speed up keyspace event notifications by skipping work when there are no subscribers and avoiding unnecessary allocations by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4285](https://github.com/valkey-io/valkey/issues/4285))
- Speed up exact `XTRIM MAXLEN = 0` by about 2.5x by clearing the whole stream in one step instead of removing entries individually by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;4161](https://github.com/valkey-io/valkey/issues/4161))
- Cluster bus reads, writes, and inbound TLS accepts can now run on the shared I/O thread pool, with new `CLUSTER INFO` offload statistics by [@&#8203;hpatro](https://github.com/hpatro) ([#&#8203;3438](https://github.com/valkey-io/valkey/issues/3438))
- Small hashes with field expiration now use the memory-efficient listpack encoding instead of always converting to a hashtable by [@&#8203;frostzt](https://github.com/frostzt) ([#&#8203;3212](https://github.com/valkey-io/valkey/issues/3212))
- Reduce per-command overhead by skipping post-command bookkeeping when no propagation, module, or invalidation work is pending by [@&#8203;ahmetalicc](https://github.com/ahmetalicc) ([#&#8203;4257](https://github.com/valkey-io/valkey/issues/4257))

##### Bug Fixes

- Fix `PFMERGE` with no source keys bypassing ACL key permissions and failing in `COMMAND GETKEYS`, and a crash in module commands whose keynum key spec starts past the last argument by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5087](https://github.com/valkey-io/valkey/issues/5087))
- Fix `SCRIPT KILL` and `FUNCTION KILL` not stopping Lua scripts that loop inside nested coroutines, and script timeouts not being detected when work is spread across coroutines by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5108](https://github.com/valkey-io/valkey/issues/5108))
- Fix a server crash in `SORT` and `SORT_RO` with `BY` or `GET` patterns when an element is 2 GiB or larger by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5146](https://github.com/valkey-io/valkey/issues/5146))
- Fix `ValkeyModule_Calloc` and `ValkeyModule_TryCalloc` returning an undersized buffer when `nmemb * size` overflows by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5155](https://github.com/valkey-io/valkey/issues/5155))
- Fix `EXEC` succeeding after a key that was already expired at `WATCH` time is overwritten, which can happen on replicas by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5169](https://github.com/valkey-io/valkey/issues/5169))
- Fix a crash on the first `FUNCTION LOAD` after startup when the shebang engine name contains a NUL byte by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5115](https://github.com/valkey-io/valkey/issues/5115))
- Fix a crash in a cluster replica whose primary was removed from the nodes table when another primary claims an unassigned slot by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5184](https://github.com/valkey-io/valkey/issues/5184))
- Fix an active defrag crash when a large set, sorted set or list is replaced by a hashtable-encoded hash while it is being defragmented by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5164](https://github.com/valkey-io/valkey/issues/5164))
- Fix an out-of-bounds write in `PFADD` and `PFMERGE` on a corrupted sparse HyperLogLog ending in a truncated XZERO opcode by rejecting it as invalid by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5124](https://github.com/valkey-io/valkey/issues/5124))
- Fix a server abort in `PFADD` and `PFMERGE` on short sparse HyperLogLogs when `hll-sparse-max-bytes` is set to 31 or less by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5138](https://github.com/valkey-io/valkey/issues/5138))
- Fix forkless saves writing corrupted set members to the RDB when `ZUNION`, `ZINTER`, `ZINTERCARD` or `ZDIFF` reads the same set concurrently by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5110](https://github.com/valkey-io/valkey/issues/5110))
- Fix a crash when the Lua debugger is started on an empty or newline-only script by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5117](https://github.com/valkey-io/valkey/issues/5117))
- Fix a cluster node failing to restart with an assertion after a gossip entry carrying the MYSELF flag adds a second myself node to nodes.conf by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5134](https://github.com/valkey-io/valkey/issues/5134))
- Fix `ACL LOAD` not disconnecting default user clients subscribed to channels the reloaded rules no longer allow by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5085](https://github.com/valkey-io/valkey/issues/5085))
- Fix a Sentinel crash when a monitored replica's `INFO` reply contains no `master_host` by [@&#8203;smkher](https://github.com/smkher) ([#&#8203;4929](https://github.com/valkey-io/valkey/issues/4929))
- Fix throttled write commands being executed twice when using RDMA with IO threads by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5160](https://github.com/valkey-io/valkey/issues/5160))
- Fail `CONFIG REWRITE` when the old config file reads short instead of writing uninitialized memory into the new config file by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5158](https://github.com/valkey-io/valkey/issues/5158))
- Fix Lua `server.error_reply()` returning stale heap memory as the error message when given a string of 2 GiB or more by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5122](https://github.com/valkey-io/valkey/issues/5122))
- Fix a use-after-free in streams when `XADD` creates a new node, which could leave a dangling pointer hit by later reads such as `XRANGE` by [@&#8203;Baraa-Hasheesh](https://github.com/Baraa-Hasheesh) ([#&#8203;4711](https://github.com/valkey-io/valkey/issues/4711))
- Fix `XINFO GROUPS` and `XINFO STREAM ... FULL` reporting too-high consumer group lag after `XTRIM` or a trimming `XADD` removes unread entries by [@&#8203;Sasidharan3094](https://github.com/Sasidharan3094) ([#&#8203;4983](https://github.com/valkey-io/valkey/issues/4983))
- Fix forkless background iteration being left inside an open `MULTI` after a script or `MULTI`/`EXEC` when there are no replicas and AOF is off by [@&#8203;harrylin98](https://github.com/harrylin98) ([#&#8203;5316](https://github.com/valkey-io/valkey/issues/5316))
- Fix use of uninitialized variables in `valkey-cli` cluster key migration when `SELECT` fails on the source node by [@&#8203;PoisonGodv](https://github.com/PoisonGodv) ([#&#8203;5311](https://github.com/valkey-io/valkey/issues/5311))
- Fix an assertion failure when `FLUSHALL` or `SHUTDOWN` cancels a failed forkless save that still has a `FLUSHDB` or `SWAPDB` queued by [@&#8203;dgershko](https://github.com/dgershko) ([#&#8203;5326](https://github.com/valkey-io/valkey/issues/5326))
- Fix AOF load failure after a crash leaves a torn annotation at the end of the file; it is now treated as a short read and can be truncated by `aof-load-truncated` or `valkey-check-aof --fix` by [@&#8203;sumitk163](https://github.com/sumitk163) ([#&#8203;5349](https://github.com/valkey-io/valkey/issues/5349))
- Fix Lua `server.log()` blocking the server for seconds when called with thousands of arguments, with no `-BUSY` reply or `SCRIPT KILL` by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5104](https://github.com/valkey-io/valkey/issues/5104))
- Bound the number of memory regions the crash report's fast memory test records on Linux to avoid overflowing its region list by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;5379](https://github.com/valkey-io/valkey/issues/5379))
- Fix a replica assertion when a timed-out script ends while the replication throttler holds the primary client, possible right after a failover with `repl-throttling-enabled yes` by [@&#8203;asagege](https://github.com/asagege) ([#&#8203;5389](https://github.com/valkey-io/valkey/issues/5389))
- Fix a primary assertion when `FLUSHDB` runs right at the end of a forkless full sync by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5365](https://github.com/valkey-io/valkey/issues/5365))
- Fix a primary assertion when a module thread holding the GIL performs a replicated write during a forkless save or full sync; affects modules that set `VALKEYMODULE_OPTIONS_HANDLE_FORKLESS` by [@&#8203;Baraa-Hasheesh](https://github.com/Baraa-Hasheesh) ([#&#8203;5432](https://github.com/valkey-io/valkey/issues/5432))
- Fix `CONFIG SET priority-subnets` demoting replica and slot migration connections from high priority, and fix drift in the active priority client counter by [@&#8203;satheeshaGowda](https://github.com/satheeshaGowda) ([#&#8203;4681](https://github.com/valkey-io/valkey/issues/4681))
- Fix a source primary assertion on the next `CLUSTER MIGRATESLOTS` and a pipe descriptor leak after a slot migration snapshot fails to fork, such as during a forkless BGSAVE by [@&#8203;Baraa-Hasheesh](https://github.com/Baraa-Hasheesh) ([#&#8203;5359](https://github.com/valkey-io/valkey/issues/5359))
- Fix excessive copy-on-write memory during fork-based saves and a data race in forkless saves under an LFU `maxmemory-policy` by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5445](https://github.com/valkey-io/valkey/issues/5445))
- Fix a use-after-free crash when a blocked client's re-executed command evicts the client still executing a command under `maxmemory-clients` by [@&#8203;nadav-levanoni](https://github.com/nadav-levanoni) ([#&#8203;5435](https://github.com/valkey-io/valkey/issues/5435))
- Fix access to a freed database when `FLUSHDB` and `SWAPDB` in the same transaction terminate a background iteration by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;5462](https://github.com/valkey-io/valkey/issues/5462))
- Reject module write commands while the server is paused for writes, preventing a crash from module timer callbacks during `CLIENT PAUSE WRITE` or `CLUSTER FAILOVER` by [@&#8203;smkher](https://github.com/smkher) ([#&#8203;3645](https://github.com/valkey-io/valkey/issues/3645))
- Fix event loop busy-spinning on virtual machines by not using raw TSC for the monotonic clock when the kernel clocksource is not tsc by [@&#8203;quanyeyang](https://github.com/quanyeyang) ([#&#8203;4707](https://github.com/valkey-io/valkey/issues/4707))
- Fix a crash in `ValkeyModule_HashHasStringRef` on a missing or expired field and correct wrong return values in the hash stringRef module APIs by [@&#8203;ShubhamTaple](https://github.com/ShubhamTaple) ([#&#8203;4504](https://github.com/valkey-io/valkey/issues/4504))
- Fix a server abort on a RESTORE payload declaring a string length that overflows the allocation size; such payloads are now rejected as bad data by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4733](https://github.com/valkey-io/valkey/issues/4733))
- Fix ZINTER/ZINTERSTORE returning input-order-dependent scores when a weighted term is 0\*inf; a NaN weighted score now counts as 0, matching ZUNION by [@&#8203;leomurillo](https://github.com/leomurillo) ([#&#8203;4997](https://github.com/valkey-io/valkey/issues/4997))
- Fix crashes, lookup hangs, and duplicate set members when keys or elements reach 2 GiB, caused by storing string lengths in a 32-bit integer by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5133](https://github.com/valkey-io/valkey/issues/5133))
- Fix module global defrag resuming on the wrong module or with a stale cursor when `MODULE UNLOAD` runs between defrag cycles by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5154](https://github.com/valkey-io/valkey/issues/5154))
- Propagate `PFADD` elements applied before a corrupted-HLL INVALIDOBJ error so replicas and the AOF stay consistent with the primary by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5128](https://github.com/valkey-io/valkey/issues/5128))
- Fix a server crash in `SCRIPT DEBUG SYNC` mode when a debugger command arrives split across more than one read by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5127](https://github.com/valkey-io/valkey/issues/5127))
- Fix a server panic when a Lua script returns or raises an error table whose metatable has an `__index` metamethod that raises an error by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5118](https://github.com/valkey-io/valkey/issues/5118))
- Fix forkless BGSAVE producing a corrupt snapshot when `SWAPDB` runs without being replicated, such as from a script with replication disabled by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5116](https://github.com/valkey-io/valkey/issues/5116))
- Let `FLUSHALL` and `SHUTDOWN` cancel a forkless save that is finalizing its file, so a stale snapshot can no longer overwrite the newer dump.rdb by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5121](https://github.com/valkey-io/valkey/issues/5121))
- Fix a server crash when a module never sets a postponed reply length; the leftover placeholder is now filled with an empty array by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5159](https://github.com/valkey-io/valkey/issues/5159))
- Fix a memory leak when `server.register_function` named arguments are repeated in a different letter case by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5120](https://github.com/valkey-io/valkey/issues/5120))
- Preserve expired but not yet reaped hash fields across listpack-to-hashtable conversion so their deletion is properly reaped and propagated by [@&#8203;frostzt](https://github.com/frostzt) ([#&#8203;4704](https://github.com/valkey-io/valkey/issues/4704))
- Fix a double-decremented item count when background iteration is terminated with a SWAPDB or FLUSHDB event queued by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;4750](https://github.com/valkey-io/valkey/issues/4750))
- Fix `GEOSEARCH` returning empty results for exact zero-distance matches on builds where floating-point contraction breaks the latitude distance calculation by [@&#8203;Baraa-Hasheesh](https://github.com/Baraa-Hasheesh) ([#&#8203;4777](https://github.com/valkey-io/valkey/issues/4777))
- Reject inline commands containing a raw NUL byte with a protocol error instead of leaving the connection stalled by [@&#8203;cjx-zar](https://github.com/cjx-zar) ([#&#8203;4759](https://github.com/valkey-io/valkey/issues/4759))
- Fix a memory leak on normal shutdown caused by I/O worker threads not being terminated and cleaned up by [@&#8203;roshkhatri](https://github.com/roshkhatri) ([#&#8203;4710](https://github.com/valkey-io/valkey/issues/4710))
- `XACKDEL` with `KEEPREF` now replies 1 instead of -1 when acknowledging an entry whose stream message was already deleted, matching the ACKED and DELREF modes by [@&#8203;adityamukesh](https://github.com/adityamukesh) ([#&#8203;4843](https://github.com/valkey-io/valkey/issues/4843))
- Fix listpack encoding incompatibility that caused RDB load and replication failures for entries of certain lengths between 9.0 and 9.1.x by [@&#8203;jjuleslasarte](https://github.com/jjuleslasarte) ([#&#8203;4819](https://github.com/valkey-io/valkey/issues/4819))
- Reject relative expire times in `SET`/`GETEX`, `RESTORE`, and `ValkeyModule_SetExpire` that overflow when added to the current time, preventing server aborts from negative expires by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;4880](https://github.com/valkey-io/valkey/issues/4880))
- `ACL DIGEST` now includes role definitions, so editing a role's rules changes the reported fingerprint by [@&#8203;melancholictheory](https://github.com/melancholictheory) ([#&#8203;4694](https://github.com/valkey-io/valkey/issues/4694))
- Fix a server crash when loading an ACL file containing a selector with an unmatched parenthesis by [@&#8203;magic-peach](https://github.com/magic-peach) ([#&#8203;4214](https://github.com/valkey-io/valkey/issues/4214))
- Fix a segfault on Alpine/musl when Lua is built as a module, caused by a symbol clash on an internal clock function by [@&#8203;mohammedgqudah](https://github.com/mohammedgqudah) ([#&#8203;4270](https://github.com/valkey-io/valkey/issues/4270))
- Fix lex range seeks, NaN score bound handling, and a memory leak in B+tree sorted sets, and resolve `ZRANGEBYLEX` LIMIT offsets in logarithmic time by [@&#8203;xiaocj](https://github.com/xiaocj) ([#&#8203;4644](https://github.com/valkey-io/valkey/issues/4644))
- Fix expired hash fields left untracked after listpack-to-hashtable conversion, which could crash the server on a later write and leave fields that are never reaped by [@&#8203;beyondwin](https://github.com/beyondwin) ([#&#8203;4894](https://github.com/valkey-io/valkey/issues/4894))
- Restore acceptance of hexadecimal float sorted set scores (such as `0x10`), keeping replication and AOF replay compatible with Valkey 9.0 by [@&#8203;quanyeyang](https://github.com/quanyeyang) ([#&#8203;4875](https://github.com/valkey-io/valkey/issues/4875))
- Sorted set range commands with a negative `LIMIT` offset now return an empty result instead of a spurious element on btree-encoded keys by [@&#8203;xiaocj](https://github.com/xiaocj) ([#&#8203;4637](https://github.com/valkey-io/valkey/issues/4637))
- Fix `HSETEX` and `HGETEX` failing to parse their arguments when the key is named `fields` by [@&#8203;sebxt](https://github.com/sebxt) ([#&#8203;4945](https://github.com/valkey-io/valkey/issues/4945))
- Fix a crash when active defrag's deferred keys outlive a keyspace replacement such as FLUSHDB/FLUSHALL ASYNC, SWAPDB, or a replica's pre-sync flush by [@&#8203;taham0](https://github.com/taham0) ([#&#8203;4968](https://github.com/valkey-io/valkey/issues/4968))
- Fix `LSET` on 64-bit builds silently modifying the wrong element for out-of-range indexes instead of returning an index out of range error by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;4823](https://github.com/valkey-io/valkey/issues/4823))
- Fix a heap buffer overflow in cluster Pub/Sub message construction; oversized PUBLISH and SPUBLISH payloads are now rejected with an error in cluster mode by [@&#8203;roshkhatri](https://github.com/roshkhatri) ([#&#8203;5030](https://github.com/valkey-io/valkey/issues/5030))
- Lex range commands on btree-encoded sorted sets with mixed scores now match listpack results, preventing primary/replica divergence via ZREMRANGEBYLEX and ZRANGESTORE by [@&#8203;pirate329](https://github.com/pirate329) ([#&#8203;4954](https://github.com/valkey-io/valkey/issues/4954))
- Fix a memory leak when `GEOSEARCH` or `GEOSEARCHSTORE` is given repeated `BYPOLYGON` options by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;4995](https://github.com/valkey-io/valkey/issues/4995))
- `DEBUG RELOAD` and `DEBUG LOADAOF` now return a LOADING error while the dataset is loading, avoiding a possible panic by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4877](https://github.com/valkey-io/valkey/issues/4877))
- Fix a memory leak in `ValkeyModule_GetCommandKeysWithFlags` when introspecting commands with large key lists by [@&#8203;christopherlim98](https://github.com/christopherlim98) ([#&#8203;5046](https://github.com/valkey-io/valkey/issues/5046))
- `MEMORY USAGE` now counts hash fields that have expired but not yet been reaped, fixing under-reported sizes by [@&#8203;sushilpaneru1](https://github.com/sushilpaneru1) ([#&#8203;5092](https://github.com/valkey-io/valkey/issues/5092))
- Fix a crash in `ValkeyModule_Call` when script-mode validation fails and error replies were not requested by [@&#8203;dvkashapov](https://github.com/dvkashapov) ([#&#8203;5091](https://github.com/valkey-io/valkey/issues/5091))
- High-priority socket events are no longer drained when the event loop caller did not request file event processing by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;5098](https://github.com/valkey-io/valkey/issues/5098))
- Fix a crash when a replication role change command such as `REPLICAOF` or `CLUSTER REPLICATE` arrives over a replication link by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5187](https://github.com/valkey-io/valkey/issues/5187))
- `FUNCTION RESTORE` now applies the same library load timeout as `FUNCTION LOAD`, so a never-returning library can no longer block the server forever by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5181](https://github.com/valkey-io/valkey/issues/5181))
- Fix a buffer overflow in valkey-benchmark when `--num-functions` is large enough to overflow the generated script buffer by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5175](https://github.com/valkey-io/valkey/issues/5175))
- Fix a valkey-check-rdb crash with `--stats` on RDB files whose highest selected database contains no keys by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5177](https://github.com/valkey-io/valkey/issues/5177))
- Fix a crash on the importing primary when an atomic slot migration fails while its writes are paused by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5182](https://github.com/valkey-io/valkey/issues/5182))
- Fix `GEOSEARCH BYPOLYGON` missing matching members when the polygon's vertex centroid falls outside the valid latitude range by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5174](https://github.com/valkey-io/valkey/issues/5174))
- Fix a primary abort when `CLUSTER SETSLOT` runs inside MULTI or a script on a primary with online replicas by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5141](https://github.com/valkey-io/valkey/issues/5141))
- Fix a memory leak when deleting or replacing Lua functions with long names or descriptions by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5109](https://github.com/valkey-io/valkey/issues/5109))
- A refused oversized `XADD` no longer creates an empty stream key that replicas and the AOF never receive by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5178](https://github.com/valkey-io/valkey/issues/5178))
- Prevent a replica crash when the primary wrongly replies +CONTINUE to a full resync request; the replica now drops the link and retries by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5126](https://github.com/valkey-io/valkey/issues/5126))
- FUNCTION LOAD no longer aborts the server when a library calls `server.log()` at its top level, including when loading from RDB or AOF by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5114](https://github.com/valkey-io/valkey/issues/5114))
- RESET on a slot migration connection now returns an error instead of crashing the server with an assertion failure by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5140](https://github.com/valkey-io/valkey/issues/5140))
- DEBUG SLOTMIGRATION with missing arguments now returns an error instead of crashing the server by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5147](https://github.com/valkey-io/valkey/issues/5147))
- KEYS on a flushed database no longer leaks a rehashing pause that permanently stops rehashing and can eventually crash the server by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5166](https://github.com/valkey-io/valkey/issues/5166))
- Automatic RDB snapshots and AOF rewrites are no longer postponed while a forked SCRIPT DEBUG session is open by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5153](https://github.com/valkey-io/valkey/issues/5153))
- Fix an integer overflow in quicklist node merging that could crash the server on lists loaded with nodes over 4GiB via RESTORE or replication by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5163](https://github.com/valkey-io/valkey/issues/5163))
- Fix a stack buffer overflow when replying with hundreds of empty strings (e.g. MGET) while reply copy avoidance is active by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5151](https://github.com/valkey-io/valkey/issues/5151))
- CLUSTER SLOT-STATS ORDERBY no longer replies with uninitialized slot entries when a node's primary is itself a replica that claims slots by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5131](https://github.com/valkey-io/valkey/issues/5131))
- Fix a race with TLS and io-threads where an IO thread still writing to a client could modify the main thread's event loop by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5156](https://github.com/valkey-io/valkey/issues/5156))
- Fix a replica crash when a script exceeding busy-reply-threshold ends during CLIENT PAUSE WRITE with a pending replicated write by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5150](https://github.com/valkey-io/valkey/issues/5150))
- In cluster mode, one cross-slot command in a script no longer makes every later script and function call fail until restart by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5191](https://github.com/valkey-io/valkey/issues/5191))
- Fix a use-after-free crash when a forkless save is running while a swapdb-mode full sync swaps in the primary's keyspace on a replica by [@&#8203;nitaicaro](https://github.com/nitaicaro) ([#&#8203;5082](https://github.com/valkey-io/valkey/issues/5082))
- Fix a replica assertion crash when the primary writes a key still in use by a forkless (consistent) save by [@&#8203;harrylin98](https://github.com/harrylin98) ([#&#8203;5206](https://github.com/valkey-io/valkey/issues/5206))
- Fix a dangling pointer when a key is deleted during a forkless save, which could crash or silently corrupt the iteration by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;4996](https://github.com/valkey-io/valkey/issues/4996))
- Clear the script debugger input buffer after a "max client buffer reached" error so later debugger commands in the same session do not keep failing by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5129](https://github.com/valkey-io/valkey/issues/5129))
- MODULE LOAD is now rejected during async replication loading and atomic slot migration to avoid unexpected module behavior by [@&#8203;KIvanow](https://github.com/KIvanow) ([#&#8203;3039](https://github.com/valkey-io/valkey/issues/3039))
- Reject CLUSTER ADDSLOTS/DELSLOTS/ADDSLOTSRANGE/DELSLOTSRANGE/FLUSHSLOTS on replicas, preventing an assertion failure on a later CLUSTER REPLICATE by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4020](https://github.com/valkey-io/valkey/issues/4020))
- Fix a crash when processing a heartbeat from a cluster node whose role is locally unknown, such as after loading an incomplete nodes.conf by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4091](https://github.com/valkey-io/valkey/issues/4091))
- Fix wrong results or debug-build assertions in cluster mode when the server inspects keys outside the executing command's slot, such as WATCHed keys checked during EXEC by [@&#8203;nitaicaro](https://github.com/nitaicaro) ([#&#8203;4380](https://github.com/valkey-io/valkey/issues/4380))
- Fix stream commands that mutate consumer-group or PEL state (`XGROUP`, `XSETID`, `XREADGROUP`, `XACK`, `XCLAIM`, `XAUTOCLAIM`) not triggering `WATCH` and client-side tracking invalidation by [@&#8203;Tarte12](https://github.com/Tarte12) ([#&#8203;3459](https://github.com/valkey-io/valkey/issues/3459))
- Fix a server crash on FUNCTION DELETE or FUNCTION LOAD REPLACE after loading a library with function names differing only in case by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;3925](https://github.com/valkey-io/valkey/issues/3925))
- Client-side tracking no longer records routing-only tokens such as the CLUSTERSCAN cursor as tracked keys by [@&#8203;nmvk](https://github.com/nmvk) ([#&#8203;3699](https://github.com/valkey-io/valkey/issues/3699))
- Reject malformed slot entries in the cluster config file as a corrupt config instead of asserting or invoking undefined behavior by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4100](https://github.com/valkey-io/valkey/issues/4100))
- Fix a TLS busy loop that consumed 100% CPU when a connection's read or write handler was removed while OpenSSL was waiting for the opposite event by [@&#8203;yairgott](https://github.com/yairgott) ([#&#8203;3510](https://github.com/valkey-io/valkey/issues/3510))
- Client eviction no longer disconnects extra clients when a large client's close is deferred but its memory is already scheduled to be freed by [@&#8203;dhruv2x](https://github.com/dhruv2x) ([#&#8203;4152](https://github.com/valkey-io/valkey/issues/4152))
- Fix a crash caused by a NULL pointer dereference when all timer events in an event loop are pending deletion by [@&#8203;royenheart](https://github.com/royenheart) ([#&#8203;4351](https://github.com/valkey-io/valkey/issues/4351))
- Rework iteration over clients blocked on ready keys to simplify and harden an earlier use-after-free fix by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4472](https://github.com/valkey-io/valkey/issues/4472))
- Fix a race in RDB string compression that could produce corrupt, unloadable RDB files when compression runs concurrently, without increasing copy-on-write by [@&#8203;dubey02](https://github.com/dubey02) ([#&#8203;4539](https://github.com/valkey-io/valkey/issues/4539))
- Fix dropped field TTLs and a possible crash when loading a hash with field expiration converts it to a hashtable mid-load (e.g. via RESTORE) by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;4669](https://github.com/valkey-io/valkey/issues/4669))
- Reject a repeated `CLUSTER SYNCSLOTS ESTABLISH` on the same connection, which could lead to a use-after-free crash on disconnect by [@&#8203;Pyolar](https://github.com/Pyolar) ([#&#8203;4670](https://github.com/valkey-io/valkey/issues/4670))
- Fix wrong `ZCOUNT` results and incorrect `ZREMRANGEBYSCORE` deletions when members sharing a boundary score span multiple btree leaves by [@&#8203;rainsupreme](https://github.com/rainsupreme) ([#&#8203;4554](https://github.com/valkey-io/valkey/issues/4554))
- Fix `SORT` key extraction so a `STORE` destination named like an option can no longer bypass ACL checks and write to an unauthorized key by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;4665](https://github.com/valkey-io/valkey/issues/4665))

##### Command and API Updates

- Correct the `since` version of the `SISMEMBER` `XX` option to 9.2.0 in the command metadata by [@&#8203;PoisonGodv](https://github.com/PoisonGodv) ([#&#8203;5310](https://github.com/valkey-io/valkey/issues/5310))
- Allow null in the reply schemas of `GEOHASH`, `OBJECT FREQ`, `OBJECT IDLETIME` and `OBJECT REFCOUNT` for missing members and keys by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5209](https://github.com/valkey-io/valkey/issues/5209))
- Correct the `SENTINEL GET-MASTER-ADDR-BY-NAME` reply schema to allow the null reply returned for an unknown primary name by [@&#8203;rainsupreme](https://github.com/rainsupreme) ([#&#8203;5246](https://github.com/valkey-io/valkey/issues/5246))
- Correct command metadata to describe the `ZINCRBY` increment and `ZINTER`/`ZINTERSTORE`/`ZUNION`/`ZUNIONSTORE` weights as doubles instead of integers by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5210](https://github.com/valkey-io/valkey/issues/5210))
- Correct command metadata so the `numfields` count argument of hash field commands is no longer associated with a key specification by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5211](https://github.com/valkey-io/valkey/issues/5211))
- Correct expiry command metadata to show that `XX` can be combined with `GT` or `LT`, rather than all four conditions being mutually exclusive by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5213](https://github.com/valkey-io/valkey/issues/5213))
- Mark the `RESTORE` and `RESTORE-ASKING` `IDLETIME` and `FREQ` options as mutually exclusive in command metadata by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5212](https://github.com/valkey-io/valkey/issues/5212))
- Correct the `HEXPIRE`, `HPEXPIRE`, `HEXPIREAT`, and `HPEXPIREAT` command summaries to say they set expiration on hash fields, not the hash object by [@&#8203;poiuj](https://github.com/poiuj) ([#&#8203;4783](https://github.com/valkey-io/valkey/issues/4783))
- Add `LBOUND`, `UBOUND`, `SATURATE`, `ENX`, and `PERSIST` options to `INCREX` for bounded increments and conditional expiration control by [@&#8203;murphyjacob4](https://github.com/murphyjacob4) ([#&#8203;4679](https://github.com/valkey-io/valkey/issues/4679))
- Correct `SENTINEL SIMULATE-FAILURE` metadata so `COMMAND DOCS` shows the required mode argument and its tokens by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5208](https://github.com/valkey-io/valkey/issues/5208))
- Rename the Path Hash command `PHEXISTS` to `PHPATHEXISTS` to clarify that it checks a path rather than a hash field by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;5069](https://github.com/valkey-io/valkey/issues/5069))
- Add `PHPATHSCAN` for ordered incremental path iteration and change `PHSCAN` to iterate fields and values at an exact path by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;5066](https://github.com/valkey-io/valkey/issues/5066))
- Remove `PHLONGEST` in favor of `PHPREFIXES`, which now returns matches longest-first with paging and an `EXCLUDESELF` option by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;5070](https://github.com/valkey-io/valkey/issues/5070))
- Replace `PHCARD` with `PHPATHCOUNT`, which can also count only the paths under a given prefix by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;5071](https://github.com/valkey-io/valkey/issues/5071))
- Replace `PHDELPREFIX` with `PHPATHDEL key path [WITHSUBPATHS]`, which deletes an exact path or its whole subtree and returns the number of deleted paths by [@&#8203;yangbodong22011](https://github.com/yangbodong22011) ([#&#8203;5067](https://github.com/valkey-io/valkey/issues/5067))
- Mark the absolute timestamp arguments of `HEXPIREAT` and `HPEXPIREAT` as `unix-time` in `COMMAND DOCS`, matching `EXPIREAT` and `PEXPIREAT` by [@&#8203;rainsupreme](https://github.com/rainsupreme) ([#&#8203;5245](https://github.com/valkey-io/valkey/issues/5245))
- Correct `ZADD` and `LCS` metadata so `COMMAND DOCS` and valkey-cli hints no longer present `NX` with `GT`/`LT` or `LEN` with `IDX` as valid combinations by [@&#8203;rainsupreme](https://github.com/rainsupreme) ([#&#8203;5244](https://github.com/valkey-io/valkey/issues/5244))
- `MOVE` accepts a new optional `REPLACE` argument to overwrite an existing key in the destination database by [@&#8203;bandalgomsu](https://github.com/bandalgomsu) ([#&#8203;2993](https://github.com/valkey-io/valkey/issues/2993))
- WAIT and WAITAOF now reject numreplicas values that are negative or exceed INT_MAX, fixing an integer overflow that broke blocking by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3407](https://github.com/valkey-io/valkey/issues/3407))
- Add CONFIG INFO subcommand returning config metadata such as type, flags, valid enum values and numeric ranges by [@&#8203;nitaicaro](https://github.com/nitaicaro) ([#&#8203;3050](https://github.com/valkey-io/valkey/issues/3050))
- Add the `IFNE` option to `SET` to set a key only when its current value differs from the given comparison value by [@&#8203;arshidkv12](https://github.com/arshidkv12) ([#&#8203;3105](https://github.com/valkey-io/valkey/issues/3105))
- Add `IFEQ`, `IFNE`, `NX` and `XX` conditions to `EXEC`, enabling optimistic locking for multi-key transactions without `WATCH` by [@&#8203;bandalgomsu](https://github.com/bandalgomsu) ([#&#8203;4019](https://github.com/valkey-io/valkey/issues/4019))
- Add an optional `XX` flag to `SISMEMBER` that returns -1 when the key does not exist, distinguishing a missing key from a missing member by [@&#8203;li-benson](https://github.com/li-benson) ([#&#8203;2972](https://github.com/valkey-io/valkey/issues/2972))
- Handle NOT_KEY key-specs more defensively so COMMAND GETKEYS and ACL key checks consistently treat routing-only tokens as non-keys by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3675](https://github.com/valkey-io/valkey/issues/3675))
- Fix DEBUG HELP to show the correct DELAY-RDB-CLIENT-FREE-SECONDS name and document the SET-DISABLE-DENY-SCRIPTS subcommand by [@&#8203;xiejing-dev](https://github.com/xiejing-dev) ([#&#8203;4099](https://github.com/valkey-io/valkey/issues/4099))
- Add XX option to the ZRANGE family of commands to distinguish a non-existent key (nil) from an empty result by [@&#8203;youngmore1024](https://github.com/youngmore1024) ([#&#8203;2978](https://github.com/valkey-io/valkey/issues/2978))
- Fix the reply schemas of the ZRANGE family of commands to allow the null reply returned with the XX option by [@&#8203;murphyjacob4](https://github.com/murphyjacob4) ([#&#8203;4275](https://github.com/valkey-io/valkey/issues/4275))
- Fix the `XPENDING` reply schema to describe the summary reply returned when a consumer group has no pending messages by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;4653](https://github.com/valkey-io/valkey/issues/4653))

##### Cluster and Replication

- Fix `HSETEX` and `MSETEX` with a repeated EX, PX or EXAT option being rejected by replicas and lost on AOF reload by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5088](https://github.com/valkey-io/valkey/issues/5088))
- Reject inbound cluster bus packets larger than 16MB, except Pub/Sub and module messages, so a peer cannot make a node buffer up to 4GB from a single header by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5065](https://github.com/valkey-io/valkey/issues/5065))
- Fix replicas retrying full sync in a loop when the primary rejects `PSYNC` and the replica falls back to `SYNC` by [@&#8203;murphyjacob4](https://github.com/murphyjacob4) ([#&#8203;5280](https://github.com/valkey-io/valkey/issues/5280))
- Strip every repeated `LIMIT` when propagating `XADD` and `XTRIM`, so tools replaying the replication stream no longer get a syntax error by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;4893](https://github.com/valkey-io/valkey/issues/4893))
- Fix shutdown-triggered failover promoting a replica that has `cluster-replica-no-failover yes` by [@&#8203;simonasr](https://github.com/simonasr) ([#&#8203;5033](https://github.com/valkey-io/valkey/issues/5033))
- Fix replication throttling starting earlier than intended when the replica output buffer limit is set below `repl-backlog-size` by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;5338](https://github.com/valkey-io/valkey/issues/5338))
- Fix Sentinel counting stale primary-down reports from peers toward quorum, which could trigger an unwanted failover of a healthy primary by [@&#8203;akasakariko](https://github.com/akasakariko) ([#&#8203;4913](https://github.com/valkey-io/valkey/issues/4913))
- Sentinel refuses to start when its config directory is not writable, instead of silently failing to save state by [@&#8203;sgissi](https://github.com/sgissi) ([#&#8203;5376](https://github.com/valkey-io/valkey/issues/5376))
- Fix replicas reporting duplicate import-aborted module events for one slot import when `FLUSHALL` on the primary fails an atomic slot migration by [@&#8203;sarthakaggarwal97](https://github.com/sarthakaggarwal97) ([#&#8203;5367](https://github.com/valkey-io/valkey/issues/5367))
- Fix `MSETEX` in cluster mode skipping `MOVED` and `CROSSSLOT` checks and its writes not being forwarded during atomic slot migration by [@&#8203;bhuvanprakash](https://github.com/bhuvanprakash) ([#&#8203;4951](https://github.com/valkey-io/valkey/issues/4951))
- Fix replication of `HDEL` commands generated by active hash field expiration during a forkless full sync by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;5460](https://github.com/valkey-io/valkey/issues/5460))
- Decouple `rdbcompression` (on-disk RDB format) from `repl-compression` (replication wire format) so setting one no longer affects the other during a full sync by [@&#8203;zuiderkwast](https://github.com/zuiderkwast) ([#&#8203;4749](https://github.com/valkey-io/valkey/issues/4749))
- Avoid rapid failover election restarts by fast-failing only on NACK reasons that a new election epoch can actually fix by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4700](https://github.com/valkey-io/valkey/issues/4700))
- Prevent a failover auth NACK for an old election from being counted against the current election by echoing the rejected request epoch by [@&#8203;xdk-amz](https://github.com/xdk-amz) ([#&#8203;4654](https://github.com/valkey-io/valkey/issues/4654))
- Keep a replica's connection to its primary on the main thread so replication flow control works when I/O threads are enabled by [@&#8203;chky1386](https://github.com/chky1386) ([#&#8203;4765](https://github.com/valkey-io/valkey/issues/4765))
- `HDEL`, `HGETDEL`, `HPERSIST`, and `HEXPIRE` no longer propagate fields they treat as expired, preventing replica and AOF-reload divergence by [@&#8203;xdk-amz](https://github.com/xdk-amz) ([#&#8203;4772](https://github.com/valkey-io/valkey/issues/4772))
- `COPY` of a hash now includes expired-but-unreaped fields so their deletion is propagated and replicas stay in sync by [@&#8203;pirate329](https://github.com/pirate329) ([#&#8203;4939](https://github.com/valkey-io/valkey/issues/4939))
- Fix atomic slot migration not replicating evictions on the import target, which let replicas grow far past `maxmemory` by [@&#8203;shanezx-sc](https://github.com/shanezx-sc) ([#&#8203;4920](https://github.com/valkey-io/valkey/issues/4920))
- Fix cluster config saving to avoid publishing truncated `nodes.conf` files, losing the startup lock after the first save, and failing every save on SMB filesystems such as Azure Files; the lock now lives on a separate `nodes.conf.lock` file by [@&#8203;KewangZhili](https://github.com/KewangZhili) ([#&#8203;4489](https://github.com/valkey-io/valkey/issues/4489))
- Fix failover election fast-fail double-counting a voter that rejected the request and was later marked FAIL, which could abandon a winnable election by [@&#8203;xdk-amz](https://github.com/xdk-amz) ([#&#8203;4655](https://github.com/valkey-io/valkey/issues/4655))
- Fix atomic slot migration with `cluster-databases` > 1 applying writes made during the snapshot to the wrong database on the target by [@&#8203;pirate329](https://github.com/pirate329) ([#&#8203;4952](https://github.com/valkey-io/valkey/issues/4952))
- Ignore new nodes gossiped by a sender still in handshake so a forged MEET packet cannot fill the cluster node table by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5145](https://github.com/valkey-io/valkey/issues/5145))
- Ignore invalid ping extension values from cluster peers that would corrupt nodes.conf and prevent the node from restarting by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5137](https://github.com/valkey-io/valkey/issues/5137))
- Bound the bytes the cluster bus reads per event so a peer with a constant read backlog cannot starve clients, cron and heartbeats by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5161](https://github.com/valkey-io/valkey/issues/5161))
- Fix incorrect missing-key handling of replicated MULTI/EXEC transactions during a forkless full sync by [@&#8203;JimB123](https://github.com/JimB123) ([#&#8203;5205](https://github.com/valkey-io/valkey/issues/5205))
- Cluster replicas now redirect keyless commands like SCAN and FLUSHDB to the primary for clients with CAPA REDIRECT that have not sent READONLY by [@&#8203;yanamolo](https://github.com/yanamolo) ([#&#8203;3505](https://github.com/valkey-io/valkey/issues/3505))
- Changing cluster-require-full-coverage via CONFIG SET now updates the cluster state immediately instead of waiting for the next cron cycle by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3676](https://github.com/valkey-io/valkey/issues/3676))
- Fix CLUSTER BUMPEPOCH getting stuck when a dead node holds an equal or abnormally high config epoch; a single bump now overtakes it by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4092](https://github.com/valkey-io/valkey/issues/4092))
- Replicas now retry PSYNC when the primary replies -BUSY instead of downgrading to legacy SYNC, which broke WAIT, PSYNC and FAILOVER by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4140](https://github.com/valkey-io/valkey/issues/4140))
- SYNC/PSYNC from a replica with a down primary link now consistently returns -NOMASTERLINK, avoiding an unnecessary full sync fallback by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4148](https://github.com/valkey-io/valkey/issues/4148))
- Add cluster-replica-priority config so operators can rank which replicas are preferred during automatic cluster failover by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;2204](https://github.com/valkey-io/valkey/issues/2204))
- Speed up recovery from split-vote failover elections with a new FAILOVER_AUTH_NACK message that lets a replica detect an unwinnable election and immediately retry with a higher epoch by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3833](https://github.com/valkey-io/valkey/issues/3833))
- Add optional per-target `AUTH username password` to `CLUSTER MIGRATESLOTS`, with credentials redacted from the slow log and MONITOR by [@&#8203;nemtsv](https://github.com/nemtsv) ([#&#8203;3538](https://github.com/valkey-io/valkey/issues/3538))
- Compress the full-sync RDB payload with LZ4 when `rdbcompression lz4` is set and every attaching replica advertises support, reducing sync bandwidth with safe fallback to plaintext by [@&#8203;roshkhatri](https://github.com/roshkhatri) ([#&#8203;4075](https://github.com/valkey-io/valkey/issues/4075))
- Add an `if-empty` value to `cluster-replica-no-failover` so a replica that has never received data from its primary refuses automatic failover, preventing silent data loss by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4425](https://github.com/valkey-io/valkey/issues/4425))
- Add optional LZ4 streaming compression for steady-state replication via the new `repl-compression` config, negotiated per replica so older or opted-out replicas keep receiving plaintext by [@&#8203;roshkhatri](https://github.com/roshkhatri) ([#&#8203;3853](https://github.com/valkey-io/valkey/issues/3853))
- Fix `CLUSTERSCAN` fingerprints to derive from the hash-seed config so cursors survive failover between nodes sharing a seed by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3679](https://github.com/valkey-io/valkey/issues/3679))
- Replicas trigger a failover check immediately when cluster-replica-no-failover is disabled at runtime, instead of waiting for the next cron tick by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;3827](https://github.com/valkey-io/valkey/issues/3827))
- Validate node IDs and shard IDs received in cluster messages before applying them, dropping the link on invalid data to protect cluster state by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4065](https://github.com/valkey-io/valkey/issues/4065))
- Drop the cluster link when a gossip section contains invalid node IDs, instead of keeping the connection to a corrupted sender alive by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4077](https://github.com/valkey-io/valkey/issues/4077))
- Persist nodes.conf promptly when a node's address is updated through the gossip section by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4089](https://github.com/valkey-io/valkey/issues/4089))
- Reject malformed node IDs in the open-slots RDB aux field instead of creating an illegal cluster node by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4098](https://github.com/valkey-io/valkey/issues/4098))
- Strip the redundant LIMIT option when rewriting XADD/XTRIM for propagation, so the rewritten command is valid for tools that replay it by [@&#8203;cjx-zar](https://github.com/cjx-zar) ([#&#8203;4063](https://github.com/valkey-io/valkey/issues/4063))
- Persist non-default cluster-replica-priority to nodes.conf so it survives restarts instead of waiting for the next gossip round by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4454](https://github.com/valkey-io/valkey/issues/4454))
- Clear a stale primary-failure gossip flag on replicas so later failovers don't incorrectly skip the election delay by [@&#8203;charsyam](https://github.com/charsyam) ([#&#8203;4533](https://github.com/valkey-io/valkey/issues/4533))
- Fix a node staying stuck in PFAIL when its PING is lost while the peer's own traffic keeps the cluster link alive by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4171](https://github.com/valkey-io/valkey/issues/4171))
- `CLUSTER SYNCSLOTS FINISH` now rejects clients outside the slot migration stream, preventing misuse of the import state machine by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;4330](https://github.com/valkey-io/valkey/issues/4330))

##### Configuration

- Fix `notify-keyspace-events` dropping the `n` (new key) flag from `CONFIG GET` and `CONFIG REWRITE` when `A` is also set by [@&#8203;pirate329](https://github.com/pirate329) ([#&#8203;5199](https://github.com/valkey-io/valkey/issues/5199))
- CONFIG REWRITE now quotes the replicaof host, so hosts with spaces or newlines no longer corrupt the config file by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5176](https://github.com/valkey-io/valkey/issues/5176))
- Rename the `bgsave-default-method` config to `forkless-policy` with values `require-fork` and `prefer-forkless` by [@&#8203;madolson](https://github.com/madolson) ([#&#8203;5261](https://github.com/valkey-io/valkey/issues/5261))
- `commandlog-request-larger-than` and `commandlog-reply-larger-than` now accept memory units such as 10mb by [@&#8203;enjoy-binbin](https://github.com/enjoy-binbin) ([#&#8203;2648](https://github.com/valkey-io/valkey/issues/2648))
- `cluster-announce-ip` now must be a valid IP address or hostname, rejecting values like `ip:port` that broke cluster bus addressing by [@&#8203;AlisinaDevelo](https://github.com/AlisinaDevelo) ([#&#8203;4055](https://github.com/valkey-io/valkey/issues/4055))
- Reject an empty `tls-ca-cert-dir` at startup and `CONFIG SET` time instead of silently accepting it and failing every client handshake later by [@&#82…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-doc-pr This change needs to update a documentation page. Remove label once doc PR is open. release-notes This issue should get a line item in the release notes run-extra-tests Run extra tests on this PR (Runs all tests from daily except valgrind and RESP)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants