redis/tests/unit/cluster
zhaozhao.zz bb2b6e2927
fix scripts access wrong slot if they disagree with pre-declared keys (#12906)
Regarding how to obtain the hash slot of a key, there is an optimization
in `getKeySlot()`, it is used to avoid redundant hash calculations for
keys: when the current client is in the process of executing a command,
it can directly use the slot of the current client because the slot to
access has already been calculated in advance in `processCommand()`.

However, scripts are a special case where, in default mode or with
`allow-cross-slot-keys` enabled, they are allowed to access keys beyond
the pre-declared range. This means that the keys they operate on may not
belong to the slot of the pre-declared keys. Currently, when the
commands in a script are executed, the slot of the original client
(i.e., the current client) is not correctly updated, leading to
subsequent access to the wrong slot.

This PR fixes the above issue. When checking the cluster constraints in
a script, the slot to be accessed by the current command is set for the
original client (i.e., the current client). This ensures that
`getKeySlot()` gets the correct slot cache.

Additionally, the following modifications are made:

1. The 'sort' and 'sort_ro' commands use `getKeySlot()` instead of
`c->slot` because the client could be an engine client in a script and
can lead to potential bug.
2. `getKeySlot()` is also used in pubsub to obtain the slot for the
channel, standardizing the way slots are retrieved.
2024-01-15 09:57:12 +08:00
..
announced-endpoints.tcl Add announced-endpoints test to all_tests and fix tls related tests (#12927) 2024-01-09 18:18:59 -08:00
cli.tcl redis-cli adds -4 / -6 options to determine IPV4 / IPV6 priority in DNS lookup (#11315) 2023-12-24 10:40:34 +02:00
cluster-response-tls.tcl Support TLS service when "tls-cluster" is not enabled and persist both plain and TLS port in nodes.conf (#12233) 2023-06-26 07:43:38 -07:00
failure-marking.tcl When one shard, sole primary node marks potentially failed replica as FAIL instead of PFAIL (#12824) 2024-01-11 15:48:19 -08:00
hostnames.tcl Make nodename test more consistent (#12330) 2023-06-20 18:00:55 -07:00
human-announced-nodename.tcl Make nodename test more consistent (#12330) 2023-06-20 18:00:55 -07:00
links.tcl Attempt to solve MacOS CI issues in GH Actions (#12013) 2023-04-12 09:19:21 +03:00
misc.tcl Exclude aux fields from "cluster nodes" and "cluster replicas" output (#12166) 2023-05-23 18:32:37 +03:00
multi-slot-operations.tcl Adding missing test cases for Addslot Command (#12288) 2023-06-11 08:36:26 +03:00
scripting.tcl fix scripts access wrong slot if they disagree with pre-declared keys (#12906) 2024-01-15 09:57:12 +08:00
slot-ownership.tcl bugfix:del keys in slot replicate to replica, and trigger other invalidations (#11084) 2022-08-28 11:37:26 +03:00