Skip to content

[req/resp] Fix aggregating unmodifiable collection failiure#4465

Merged
ggivo merged 14 commits intoim/request-response-policy-supportfrom
topic/ggivo/request-response-policy-support
Mar 19, 2026
Merged

[req/resp] Fix aggregating unmodifiable collection failiure#4465
ggivo merged 14 commits intoim/request-response-policy-supportfrom
topic/ggivo/request-response-policy-support

Conversation

@ggivo
Copy link
Copy Markdown
Collaborator

@ggivo ggivo commented Mar 17, 2026

Expected

Collections merged correctly: ["1", "2", "3"]

Actual

java.lang.UnsupportedOperationException
	at java.util.AbstractList.add(AbstractList.java:148)

Reproduce

List<String> first = Collections.emptyList(); // Unmodifiable
List<String> second = Arrays.asList("1", "2");
List<String> third = Arrays.asList("3");

MultiNodeResultAggregator<List<String>> aggregator = new MultiNodeResultAggregator<>(ResponsePolicy.DEFAULT);
aggregator.addSuccess(NODE_1, first);
aggregator.addSuccess(second);
aggregator.addSuccess(NODE_2, third);

aggregator.getResult(); // Throws UnsupportedOperationException

Root Cause

ResponsePolicy.DEFAULT stores first result directly and attempts to modify it. Fails when first result is unmodifiable (e.g., Collections.emptyList()).

Fix

Create new modifiable collection when merging results instead of modifying first result.


Note

Medium Risk
Changes the core multi-node reply aggregation used by cluster broadcast/multi-shard commands; incorrect aggregation behavior could affect command results or error handling, though coverage is added/updated with extensive tests.

Overview
Fixes ResponsePolicy.DEFAULT aggregation so multi-node/broadcast commands no longer try to mutate the first successful reply (which could be an unmodifiable List/Map/Set), instead collecting parts and producing a merged modifiable result when needed.

This replaces the old static ClusterReplyAggregator with a new executors/aggregators framework (sum/min/max/logical/default/first-value), updates MultiNodeResultAggregator (now public/internal) and its usage in ClusterCommandExecutor, and adds/rewrites tests to cover unmodifiable collections and correct merging (including Set<byte[]> dedup via content). Also updates matchers (ByteArrayMapMatcher.contentEquals and new JedisByteMapMatcher) and broadens CI branch triggering to topic/**.

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

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented Mar 17, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 17, 2026

Test Results

   308 files  ± 0     308 suites  ±0   11m 56s ⏱️ +36s
11 136 tests +15  11 080 ✅ +1 432  56 💤  - 1 417  0 ❌ ±0 
 5 851 runs  +21   5 842 ✅ +  504   9 💤  -   483  0 ❌ ±0 

Results for commit 027f77f. ± Comparison against base commit 23f7def.

♻️ This comment has been updated with latest results.

@ggivo ggivo force-pushed the topic/ggivo/request-response-policy-support branch from 7ec1efa to b4d4535 Compare March 17, 2026 16:34
@ggivo ggivo changed the title Topic/ggivo/request response policy support [req/resp] Fix aggregating unmodifiable collection failiure Mar 18, 2026
Copy link
Copy Markdown
Contributor

@uglide uglide left a comment

Choose a reason for hiding this comment

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

Couple of minor issues, otherwise looks good!

Comment thread src/main/java/redis/clients/jedis/executors/aggregators/Aggregator.java Outdated
Comment thread src/main/java/redis/clients/jedis/executors/aggregators/LogicalAndAggregator.java Outdated
@ggivo ggivo force-pushed the topic/ggivo/request-response-policy-support branch from 9a2252b to f64dc15 Compare March 19, 2026 10:46
@ggivo ggivo marked this pull request as ready for review March 19, 2026 11:08
ggivo added 2 commits March 19, 2026 14:12
  - test puts entries into wrong map variable
  - Byte array set dedup skipped when first part empty
  - JedisByteHashMapAggregator.add() and JedisByteMapAggregator.add() skip empty maps
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread src/main/java/redis/clients/jedis/executors/aggregators/Aggregator.java Outdated
@ggivo ggivo merged commit 3d1da01 into im/request-response-policy-support Mar 19, 2026
13 checks passed
ggivo added a commit that referenced this pull request Mar 20, 2026
* Introduce keyless command concept

* Introduce request/response policies to CommandFlagsRegistry and StaticCommandFlagsRegistry

* Update CommandFlagsRegistryGenerator to support request/response policies

* Drop broadcastCommand and executeKeylessCommand from the CommandExecutor interface

The logic on how command should be routed should be decided in CommandExecutor based on command request/response policy and client configuration

* Add isKeyless() to CommandArguments

* Add support for MULTI_SHARD commands

* Get rid of ClusterCommandArguments

* Fix ClusterReplyAggregator

* Expose addHashSlotKey method for special cases like KEYS command

* Allow manual overrides in CommandFlagsRegistryGenerator

* Fix tests

* Add missing exception class

* Clean up after dropping FT.Aggregate iterator

* Fix formatting

* Add missing ClusterAggregationException

* Fix unit tests

* Fix bugs with hash slots

* Add support for arrays in AND&OR aggregations

* Add support for DBSIZE and add more tests

* Optimize hash slot calculation and get rid of processKey() methods

* Deprecate sendCommand() and sendBlockingCommand() as unsafe in cluster mode

* Update tests to reflect the changes

* Resolve merge problems

* Address feedback for CommandFlagsRegistryGenerator
- Remove KEYS override in generator
- Remove validations for KEYS pattern in Cluster
- Implement proper Set/List/Map aggregation infra for default response policy
- Add integration test for CLUSTER SLOT-STATS

* Reformat

* Add missing import to CommandFlagsRegistryGenerator

* Make executeKeylessCommand private

* Extract sendCommand methods deprecation

* Improve CommandFlagsRegistryGenerator

- Handle properly subcommands for HOTKEYS, FT.CURSOR, FT.CONFIG
- Raise an exception if unknown parent command is detected

* Preserve the initial order when executing multi-shard commands

- Adjust the groupArgumentsByKeyValueHashSlotImpl to fix the ordering bug
- Document how performance of MGET can be improved

* Add Connection resolvers

Co-authored-by: ggivo <[email protected]>

* Refactor broadcastCommand and executeMultiShardCommand to use common MultiNodeResultAggregator

* Reformat

* Update tests

* Reformat

* Fix bug in CommandArguments

* Fix bug with SingleConnectionResolver

* Fix bug with roundRobinResolver

* Take into account keyPreProcessor in groupArgumentsByKeyValueHashSlotImpl

* Replace outdated test in ClusterBinaryValuesCommandsTest

* Throw redirection exceptions immediately when followRedirections is false

* Add support for JedisByteHashMap and JedisByteMap in default aggregation

* Reformat

* Mutate exising collection in aggregateDefault()

* Address review suggestions and clean up code

* Make ClusterReplyAggregator pp

* Fix tests

* Fix SinceRedisVersion for clusterSlotStatsAggregation test

* Fix aggregation for WAITAOF command and improve exception message

* fix ClientAuthRedisClusterClientIT.java:[43,13] cannot find symbol

* getKeys now returns unmodifiable list

* CommnadArguments.addHashSlotKey - package private & typesafe

* [req/resp] Reject commands with ALL_NODES,ALL_SHARDS,MULTI_SHARD request policy in Cluster Pipeline (#4466)

* reject commands with ALL_NODES,ALL_SHARDS,MULTI_SHARD request policy in cluster pipeline

* run test on topic branches

* api docs fix

* If the command has keys that route to a single slot, allow it

* [req/resp] Fix  aggregating unmodifiable collection failiure (#4465)

* refactore: fix empty Map/Set should return emtpy not null

refactore: statefull aggregators fix tests

refactore: statefull aggregators

* refactore: statefull aggregators add test for ReplyAggregatorTest

* refactore: MultiNodeResultAggregator to aggregator package and mark with @internal

* refactore:  reuse LogicalAnd & LogicalOr aggregators

* format

* remove ClusterReplyAggregator replaced by aggregators/ClusterReplyAggregator

* triger test

* address review comments and fix Set[byte[]] aggregation

* address review comments

  - test puts entries into wrong map variable
  - Byte array set dedup skipped when first part empty

* address review comments

  - JedisByteHashMapAggregator.add() and JedisByteMapAggregator.add() skip empty maps

* format

* parameterize map test

* remove unused import

* override INFO & FUNCITON_STATS  request policy for cluster to DEFAULT

* formating

---------

Co-authored-by: ggivo <[email protected]>
@ggivo ggivo deleted the topic/ggivo/request-response-policy-support branch March 24, 2026 07:48
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.

2 participants