Skip to content

MOD-14439 Detect cluster topology changes during a multi-shard command and return an appropriate error - #1930

Merged
galcohen-redislabs merged 3 commits into
masterfrom
gal-14439-cluster-topology-change-during-multi-shard-commands
Apr 14, 2026
Merged

galcohen-redislabs merged 3 commits into
masterfrom
gal-14439-cluster-topology-change-during-multi-shard-commands

Conversation

@galcohen-redislabs

@galcohen-redislabs galcohen-redislabs commented Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Note

Medium Risk
Medium risk because it changes user-visible error mapping for multi-shard executions and could affect client retry/handling logic, though the change is small and covered by an integration test.

Overview
Multi-shard LibMR executions now surface cluster topology changes as a dedicated error. check_and_reply_on_error detects the LibMR error string cluster topology changed and replies with a specific message instead of the generic multi-shard failure.

Adds a new flow test that forces a TS.MRANGE to be in-flight (via DEBUG SLEEP on a remote shard) while calling timeseries.REFRESHCLUSTER, asserting the new error and then verifying MRANGE succeeds after the cluster is refreshed.

Written by Cursor Bugbot for commit 2aadf4a. This will update automatically on new commits. Configure here.

@gabsow

gabsow commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

linter is failing
Run make lint
src/libmr_commands.c:36:36: error: code should be clang-formatted [-Wclang-format-violations]
RedisModule_ReplyWithError(rctx,
^
src/libmr_commands.c:36:41: error: code should be clang-formatted [-Wclang-format-violations]
RedisModule_ReplyWithError(rctx,
^
make: *** [Makefile:370: lint] Error 1
Error: Process completed with exit code 2.

@gabsow gabsow left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How to test this on cluster (important detail)
MR_AbortRunningExecutions() runs inside MR_ClusterFree on the shard that executes timeseries.REFRESHCLUSTER. Each Redis process has its own LibMR state.

So you must race:

TS.MRANGE (or another multi-shard command whose initiator runs on that node), and
timeseries.REFRESHCLUSTER on the same shard,
using two separate connections to that shard (same as in test_ts_libmr_client_disconnect: multiple clients, one Redis thread interleaving commands).
Calling REFRESHCLUSTER only on other shards will not reliably abort the initiator on the MRANGE node.

tests/flow/test_ts_libmr_failiure.py already has cluster + LibMR patterns (testLibmrFail, threading, timeseries.REFRESHCLUSTER); extending that file (or adding a sibling) keeps things consistent.

Suggested test sketch
Define the expected string once, aligned with libmr_commands.c (same idea as SLOT_RANGES_ERROR in test_asm.py):

Must match the string in src/libmr_commands.c (check_and_reply_on_error)

TOPOLOGY_CHANGED_ERR = (
"A multi-shard command failed because the cluster topology has changed"
)
Test body (outline):

env = Env(); skip if not env.is_cluster() or env.shardsCount < 2.
Apply the same guards as testLibmrFail if needed (skipOnSlave, skipOnAOF, etc.).
Create data with a hash tag so MRANGE touches multiple shards (reuse _insert_data / tester1{1} style from test_ts_libmr_failiure.py).
Pick a shard index s (e.g. 1) — the one you will target for both MRANGE and refresh.
mrange_conn = env.getConnection(s) and refresh_conn = env.getConnection(s) (two connections, same shard).
threading.Event() for stop and seen_topology_error.
Thread A: loop until stop: mrange_conn.execute_command('TS.MRANGE', ...) in try/except; on ResponseError, if message equals TOPOLOGY_CHANGED_ERR, set seen_topology_error.
Thread B: loop until stop: refresh_conn.execute_command('timeseries.REFRESHCLUSTER') (tiny sleep(0) optional to avoid burning CPU).
Run for a bounded time (e.g. 2–5 s) or until seen_topology_error, then stop.set(), join threads.
Assert seen_topology_error is set (or assert “seen at least once in N seconds”).
Flakiness: This is probabilistic. Mitigations:

Run the race for a few seconds (CI-friendly cap).
Optionally tighten max idle for that execution if the API allows it on this path (would need a code path that sets LibMR max idle for the query — only if trivial).
If the test is occasionally too strict, you can retry the whole race 2–3 times before failing.
What not to rely on: Slot migration tests in test_asm.py primarily assert Query requires unavailable slots; that path is slot validation, not necessarily the new topology changed LibMR error, so keep this as a separate test focused on REFRESHCLUSTER + MRANGE on the same shard.

@gabsow

gabsow commented Mar 31, 2026

Copy link
Copy Markdown
Collaborator

`# Must match src/libmr_commands.c (check_and_reply_on_error) after MOD-14439 / PR #1930.
TOPOLOGY_CHANGED_USER_ERR = (
"A multi-shard command failed because the cluster topology has changed"
)

def test_libmr_topology_change_during_mrange():
"""
LibMR aborts initiator executions when that node runs timeseries.REFRESHCLUSTER (MR_ClusterFree).
Race TS.MRANGE against REFRESHCLUSTER on two connections to the same shard so refresh can
land while the LibMR execution is still in flight.
"""
env = Env()
if env.shardsCount < 2:
env.skip()
if not env.is_cluster():
env.skip()
env.skipOnSlave()
env.skipOnAOF()

start_ts = 1
samples_count = 10
with env.getClusterConnectionIfNeeded() as r:
    assert r.execute_command("TS.CREATE", "tester1{1}", "LABELS", "name", "bob")
    _insert_data(r, "tester1{1}", start_ts, samples_count, 1)

# Same shard convention as testLibmrFail (1-based shard id for getConnection).
initiator_shard = 1
mrange_conn = env.getConnection(initiator_shard)
refresh_conn = env.getConnection(initiator_shard)

stop = Event()
seen_topology = Event()

def mrange_race_loop():
    while not stop.is_set():
        try:
            mrange_conn.execute_command(
                "TS.mrange",
                start_ts,
                start_ts + samples_count,
                "WITHLABELS",
                "FILTER",
                "name=bob",
            )
        except Exception as e:
            if str(e) == TOPOLOGY_CHANGED_USER_ERR:
                seen_topology.set()

def refresh_race_loop():
    while not stop.is_set():
        try:
            refresh_conn.execute_command("timeseries.REFRESHCLUSTER")
        except Exception:
            pass
        time.sleep(0)  # yield so MRANGE threads can run

race_secs = 15 if (VALGRIND or SANITIZER) else 8
t_mrange = Thread(target=mrange_race_loop)
t_refresh = Thread(target=refresh_race_loop)
t_mrange.start()
t_refresh.start()
time.sleep(race_secs)
stop.set()
t_mrange.join(timeout=60)
t_refresh.join(timeout=60)

env.assertTrue(
    seen_topology.is_set(),
    "Expected TS.MRANGE to observe %r while racing timeseries.REFRESHCLUSTER on the same shard; "
    "requires LibMR MOD-14439 and the topology error mapping in libmr_commands.c."
    % (TOPOLOGY_CHANGED_USER_ERR,),
)

verifyClusterInitialized(env)
expected_res = [
    [
        b"tester1{1}",
        [[b"name", b"bob"]],
        [
            [1, b"1"],
            [2, b"1"],
            [3, b"1"],
            [4, b"1"],
            [5, b"1"],
            [6, b"1"],
            [7, b"1"],
            [8, b"1"],
            [9, b"1"],
            [10, b"1"],
        ],
    ]
]
actual_result = env.getConnection(initiator_shard).execute_command(
    "TS.mrange",
    start_ts,
    start_ts + samples_count,
    "WITHLABELS",
    "FILTER",
    "name=bob",
)
env.assertEqual(actual_result, expected_res)

`

Comment thread src/libmr_commands.c
"did not reply within the given timeframe.");
} else if (cluster_topology_changed) {
RedisModule_ReplyWithError(
rctx, "A multi-shard command failed because the cluster topology has changed");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

about the topology has changed error dont we allredy have retribele erre we used in ASM not meching slot ranges ?

@gabsow gabsow Mar 31, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the SLOT_RANGES_ERROR ("Query requires unavailable slots") is already the established retriable error for transient cluster state issues during multi-shard commands (used in ASM slot migration). The topology change is the same class of problem from the client's perspective: a temporary cluster disruption that the client should retry.

Rather than introducing a new error string, we could just reuse SLOT_RANGES_ERROR here:

} else if (cluster_topology_changed) {
    RedisModule_ReplyWithError(rctx, SLOT_RANGES_ERROR);

This way clients already handling the slot ranges error (like the ASM test does) would automatically handle topology changes too — no new error to document or special-case client-side.

galcohen-redislabs and others added 3 commits April 14, 2026 11:06
* tests: MOD-14439 regression guard for topology error mapping in libmr_commands.c

- Assert LibMR internal string, cluster_topology_changed branch, and user ReplyWithError text in source.
- Document why live MRANGE vs REFRESHCLUSTER race is not in CI (SIGSEGV when cluster is freed mid internal-command batch).

Made-with: Cursor

* tests: MOD-14439 live cluster race test for topology change abort

Replace the static source-code regression guard with a live cluster
test that exercises the MR_AbortRunningExecutions path end-to-end.

The test freezes a remote shard with DEBUG SLEEP, fires TS.MRANGE
(which blocks waiting for that shard), then triggers REFRESHCLUSTER
on the initiator.  With the LibMR fix the client receives the specific
"cluster topology has changed" error; without it the execution falls
through to a generic max-idle timeout.

Made-with: Cursor
@galcohen-redislabs
galcohen-redislabs force-pushed the gal-14439-cluster-topology-change-during-multi-shard-commands branch from 2aadf4a to 4c4ddba Compare April 14, 2026 11:36
@sonarqubecloud

Copy link
Copy Markdown

@galcohen-redislabs
galcohen-redislabs merged commit 306e9d3 into master Apr 14, 2026
34 checks passed
@galcohen-redislabs
galcohen-redislabs deleted the gal-14439-cluster-topology-change-during-multi-shard-commands branch April 14, 2026 17:59
gabsow added a commit that referenced this pull request May 20, 2026
…d and return an appropriate error (#1930)

Co-authored-by: Tom Gabsow <[email protected]>
YaacovHazan pushed a commit to redis/redis that referenced this pull request May 25, 2026
## Summary

Bumps `MODULE_VERSION` for RedisBloom, RedisJSON, and RedisTimeSeries
from `v8.7.91` to `v8.8.0`.

| Module          | From    | To     |
|-----------------|---------|--------|
| RedisBloom      | v8.7.91 | v8.8.0 |
| RedisJSON       | v8.7.91 | v8.8.0 |
| RedisTimeSeries | v8.7.91 | v8.8.0 |

## Module changes (v8.7.91 → v8.8.0)

### RedisBloom
([v8.7.91...v8.8.0](RedisBloom/RedisBloom@v8.7.91...v8.8.0))
- MOD-15418 — fix load rdb mem leak
([#1007](RedisBloom/RedisBloom#1007))
- Revert "fix redis version"
([#1010](RedisBloom/RedisBloom#1010))
- bump version to v8.8.0

### RedisJSON
([v8.7.91...v8.8.0](RedisJSON/RedisJSON@v8.7.91...v8.8.0))
- Revert "fix redis version"
([#1597](RedisJSON/RedisJSON#1597))
- bump version v8.8.0

### RedisTimeSeries
([v8.7.91...v8.8.0](RedisTimeSeries/RedisTimeSeries@v8.7.91...v8.8.0))
- MOD-14439 — Detect cluster topology changes during a multi-shard
command and return an appropriate error
([#1930](RedisTimeSeries/RedisTimeSeries#1930))
- Revert Docker and CI redis-ref from 8.8 back to unstable
([#2033](RedisTimeSeries/RedisTimeSeries#2033))
- bump version v8.8.0

## Test plan
- [ ] CI passes for all three modules at the new pinned version
- [ ] \`make all\` builds RedisBloom, RedisJSON, RedisTimeSeries cleanly
against \`unstable\`
- [ ] Module tests run under \`make test\`

🤖 Generated with [Claude Code](https://claude.com/claude-code)



Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
YaacovHazan pushed a commit to redis/redis that referenced this pull request Jun 14, 2026
## Summary

Bumps the pinned `MODULE_VERSION` for **RedisTimeSeries** from `v8.8.0`
to `v8.9.80`. RedisBloom and RedisJSON are unchanged.

| Module          | From    | To       |
|-----------------|---------|----------|
| RedisTimeSeries | v8.8.0  | v8.9.80  |

> **Note:** `v8.9.80` is the **8.10 LTS branch cut** (targets Redis
8.10) and has diverged from `v8.8.0`. The `v8.8.0...v8.9.80` ancestry
diff contains 37 commits, but **7 are backports already shipped in
`v8.8.0`** (verified with `git cherry`, see below); the **30 genuinely
new** changes are listed here.

## Module changes ([v8.8.0 →
v8.9.80](RedisTimeSeries/RedisTimeSeries@v8.8.0...v8.9.80))

- MOD-14124 — m commands acl
([#1913](RedisTimeSeries/RedisTimeSeries#1913))
- MOD-14250 — missing artifacts logs fix
([#1932](RedisTimeSeries/RedisTimeSeries#1932))
- MOD-14289 — Increase LibMR execution timeout for Valgrind builds
([#1933](RedisTimeSeries/RedisTimeSeries#1933))
- MOD-12726 — unique snapshot name + new output params for nighly event
([#1937](RedisTimeSeries/RedisTimeSeries#1937))
- MOD-14674 — oss refresh list
([#1935](RedisTimeSeries/RedisTimeSeries#1935))
- nightly build, upload snapshot artifact
([#1954](RedisTimeSeries/RedisTimeSeries#1954))
- MOD-14902 — existence check to prevent Timeseries crash when Redis is
not aligned with new redis-core changes
([#1940](RedisTimeSeries/RedisTimeSeries#1940))
- MOD-14850 — Bump libmr
([#1962](RedisTimeSeries/RedisTimeSeries#1962))
- MOD-14715 — add apt retries/timeouts to Debian/Ubuntu Dockerfiles
([#1965](RedisTimeSeries/RedisTimeSeries#1965))
- MOD-15262 — Align TimeSeries with the RedisModule_GetUserUserName API
changes
([#1975](RedisTimeSeries/RedisTimeSeries#1975))
- RED-180951 RED-180027 — fixing bugs and improving the code
([#2004](RedisTimeSeries/RedisTimeSeries#2004))
- MOD-14239 — Ignore known init-rdbchannel migration timeout under
sanitizer
([#1979](RedisTimeSeries/RedisTimeSeries#1979))
- MOD-15105 — make one generic getUser function
([#1981](RedisTimeSeries/RedisTimeSeries#1981))
- MOD-15741 MOD-14091 — add dont-cache command tip to non-cacheable read
commands
([#2031](RedisTimeSeries/RedisTimeSeries#2031))
- MOD-15731 — modules modernization alignment
([#2027](RedisTimeSeries/RedisTimeSeries#2027))
- MOD-15728 — Tal.ba/feat/blocking get
([#2028](RedisTimeSeries/RedisTimeSeries#2028))
- MOD-8187 — fix the aggregation bugs (fix reverse iterator)
([#2036](RedisTimeSeries/RedisTimeSeries#2036))
- MOD-15749 — Link to new version of LibMR with short-form CLUSTERSET
and add tests
([#2034](RedisTimeSeries/RedisTimeSeries#2034))
- Fix REDISMODULE_MAIN typo + drop common.h forward-decl workarounds
([#2044](RedisTimeSeries/RedisTimeSeries#2044))
- CI: switch flow-linux arm64 runner to standard ubuntu-24.04-arm
([#2048](RedisTimeSeries/RedisTimeSeries#2048))
- MOD-15999 — Centralize Redis ref into a single source-of-truth file
for CI
([#2045](RedisTimeSeries/RedisTimeSeries#2045))
- CI: trigger OSS cluster (multi-shard) benchmarks on demand
([#2050](RedisTimeSeries/RedisTimeSeries#2050))
- MOD-15899 — oom try calloc
([#2051](RedisTimeSeries/RedisTimeSeries#2051))
- MOD-8187 — fix non twa aggregation
([#2053](RedisTimeSeries/RedisTimeSeries#2053))
- MOD-16224 — Fix filter-blind neighbor lookups in EMPTY aggregation
([#2056](RedisTimeSeries/RedisTimeSeries#2056))
- MOD-15893 — Nrange new command
([#2052](RedisTimeSeries/RedisTimeSeries#2052))
- MOD-16160 — update blocking get syntax
([#2054](RedisTimeSeries/RedisTimeSeries#2054))
- MOD-16160 — Fix client-side cache tips for TS.BGET and
TS.NRANGE/TS.NREVRANGE
([#2057](RedisTimeSeries/RedisTimeSeries#2057))
- Cut 8.10 LTS branch: bump version to 8.9.80, target Redis 8.10
([27484f7](RedisTimeSeries/RedisTimeSeries@27484f7))
- Fix event-nightly CI on 8.10: read Redis ref from dedicated redis_ref
field
([#2058](RedisTimeSeries/RedisTimeSeries#2058))

<details>
<summary>7 commits excluded — already shipped in v8.8.0 as
backports</summary>

These show up in the `v8.8.0...v8.9.80` ancestry diff with different
SHAs, but `git cherry` confirms their patch content is already in
`v8.8.0`: they were backported to the 8.8 release branch (the "in 8.8
via" PR below), so they are **not** new in this bump.

- MOD-9320 — Multiple aggregators single command
([#1916](RedisTimeSeries/RedisTimeSeries#1916))
→ in 8.8 via
[#1921](RedisTimeSeries/RedisTimeSeries#1921)
- MOD-9320 — rename AGGREGATION token in m commands
([#1926](RedisTimeSeries/RedisTimeSeries#1926))
→ in 8.8 via
[#1927](RedisTimeSeries/RedisTimeSeries#1927)
- MOD-13142 — Allow changing number of threads while pool hasn't started
([#1928](RedisTimeSeries/RedisTimeSeries#1928))
→ in 8.8 via
[#1934](RedisTimeSeries/RedisTimeSeries#1934)
- MOD-14439 — Detect cluster topology changes during a multi-shard
command
([#1930](RedisTimeSeries/RedisTimeSeries#1930))
→ in 8.8 under the same PR
- ci: skip Event CI when PR only changes src/version.h
([#1984](RedisTimeSeries/RedisTimeSeries#1984))
→ in 8.8 via
[#1986](RedisTimeSeries/RedisTimeSeries#1986)
- MOD-15020 — remove bionic os support
([#1983](RedisTimeSeries/RedisTimeSeries#1983))
→ in 8.8 via
[#1996](RedisTimeSeries/RedisTimeSeries#1996)
- MOD-14420 — fix count reducers return wrong NaN
([#2013](RedisTimeSeries/RedisTimeSeries#2013))
→ in 8.8 via
[#2016](RedisTimeSeries/RedisTimeSeries#2016)

</details>

## Test plan
- [ ] CI passes for RedisTimeSeries at the new pinned version
- [ ] `make all` builds RedisTimeSeries cleanly against `unstable`
- [ ] Module tests run under `make test`

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
hanzo-dev pushed a commit to hanzoai/redis that referenced this pull request Sep 11, 2026
## Summary

Bumps `MODULE_VERSION` for RedisBloom, RedisJSON, and RedisTimeSeries
from `v8.7.91` to `v8.8.0`.

| Module          | From    | To     |
|-----------------|---------|--------|
| RedisBloom      | v8.7.91 | v8.8.0 |
| RedisJSON       | v8.7.91 | v8.8.0 |
| RedisTimeSeries | v8.7.91 | v8.8.0 |

## Module changes (v8.7.91 → v8.8.0)

### RedisBloom
([v8.7.91...v8.8.0](RedisBloom/RedisBloom@v8.7.91...v8.8.0))
- MOD-15418 — fix load rdb mem leak
([#1007](RedisBloom/RedisBloom#1007))
- Revert "fix redis version"
([#1010](RedisBloom/RedisBloom#1010))
- bump version to v8.8.0

### RedisJSON
([v8.7.91...v8.8.0](RedisJSON/RedisJSON@v8.7.91...v8.8.0))
- Revert "fix redis version"
([#1597](RedisJSON/RedisJSON#1597))
- bump version v8.8.0

### RedisTimeSeries
([v8.7.91...v8.8.0](RedisTimeSeries/RedisTimeSeries@v8.7.91...v8.8.0))
- MOD-14439 — Detect cluster topology changes during a multi-shard
command and return an appropriate error
([#1930](RedisTimeSeries/RedisTimeSeries#1930))
- Revert Docker and CI redis-ref from 8.8 back to unstable
([#2033](RedisTimeSeries/RedisTimeSeries#2033))
- bump version v8.8.0

## Test plan
- [ ] CI passes for all three modules at the new pinned version
- [ ] \`make all\` builds RedisBloom, RedisJSON, RedisTimeSeries cleanly
against \`unstable\`
- [ ] Module tests run under \`make test\`

🤖 Generated with [Claude Code](https://claude.com/claude-code)



Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants