-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update slotmap when slot is not served by any node (#192)
The sync-API will update the slotmap before attempting to send a command when the slot is not served by any cluster node. The async-API will initate the slotmap update in parallell so that the next command might have an updated slotmap. This also fix an additional issue by using the correct function name for redisClusterUpdateSlotmap(). The former name cluster_update_route() is not defined when HIRCLUSTER_NO_OLD_NAMES is defined, which would break the build. Co-authored-by: Viktor Söderqvist <[email protected]>
- Loading branch information
1 parent
0a4deb6
commit 0196253
Showing
6 changed files
with
177 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash | ||
|
||
# Usage: $0 /path/to/clusterclient-async | ||
|
||
clientprog=${1:-./clusterclient-async} | ||
testname=slots-not-served-test-async | ||
|
||
# Sync processes waiting for CONT signals. | ||
perl -we 'use sigtrap "handler", sub{exit}, "CONT"; sleep 1; die "timeout"' & | ||
syncpid1=$!; | ||
|
||
# Start simulated redis node #1 | ||
timeout 5s ./simulated-redis.pl -p 7401 -d --sigcont $syncpid1 <<'EOF' & | ||
# The initial slotmap is not covering all slots. | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 1, ["127.0.0.1", 7401, "nodeid7401"]]] | ||
EXPECT CLOSE | ||
# Slotmap update due to slot not served. | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 16383, ["127.0.0.1", 7401, "nodeid7401"]]] | ||
EXPECT ["GET", "foo"] | ||
SEND "bar" | ||
EXPECT CLOSE | ||
EOF | ||
server1=$! | ||
|
||
# Wait until node is ready to accept client connections | ||
wait $syncpid1; | ||
|
||
# Run client | ||
timeout 3s "$clientprog" --events 127.0.0.1:7401 > "$testname.out" <<'EOF' | ||
GET foo | ||
# Allow slotmap update to finish. | ||
!sleep | ||
GET foo | ||
EOF | ||
clientexit=$? | ||
|
||
# Wait for server to exit | ||
wait $server1; server1exit=$? | ||
|
||
# Check exit statuses | ||
if [ $server1exit -ne 0 ]; then | ||
echo "Simulated server #1 exited with status $server1exit" | ||
exit $server1exit | ||
fi | ||
if [ $clientexit -ne 0 ]; then | ||
echo "$clientprog exited with status $clientexit" | ||
exit $clientexit | ||
fi | ||
|
||
# Check the output from clusterclient | ||
expected="Event: slotmap-updated | ||
Event: ready | ||
error: slot not served by any node | ||
Event: slotmap-updated | ||
bar | ||
Event: free-context" | ||
|
||
echo "$expected" | diff -u - "$testname.out" || exit 99 | ||
|
||
# Clean up | ||
rm "$testname.out" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
|
||
# Usage: $0 /path/to/clusterclient-binary | ||
|
||
clientprog=${1:-./clusterclient} | ||
testname=slots-not-served-test | ||
|
||
# Sync processes waiting for CONT signals. | ||
perl -we 'use sigtrap "handler", sub{exit}, "CONT"; sleep 1; die "timeout"' & | ||
syncpid1=$!; | ||
|
||
# Start simulated redis node #1 | ||
timeout 5s ./simulated-redis.pl -p 7401 -d --sigcont $syncpid1 <<'EOF' & | ||
# The initial slotmap is not covering all slots. | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 1, ["127.0.0.1", 7401, "nodeid7401"]]] | ||
EXPECT CLOSE | ||
# Slotmap update due to the slot for `foo1` is not served. | ||
# The reply is still missing slots. | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 1, ["127.0.0.1", 7401, "nodeid7401"]]] | ||
EXPECT CLOSE | ||
# Slotmap update due to the slot for `foo2` is not served. | ||
# The reply now has full slot coverage. | ||
EXPECT CONNECT | ||
EXPECT ["CLUSTER", "SLOTS"] | ||
SEND [[0, 16383, ["127.0.0.1", 7401, "nodeid7401"]]] | ||
EXPECT CLOSE | ||
EXPECT CONNECT | ||
EXPECT ["GET", "foo2"] | ||
SEND "bar2" | ||
EXPECT CLOSE | ||
EOF | ||
server1=$! | ||
|
||
# Wait until node is ready to accept client connections | ||
wait $syncpid1; | ||
|
||
# Run client | ||
timeout 3s "$clientprog" --events 127.0.0.1:7401 > "$testname.out" <<'EOF' | ||
GET foo1 | ||
GET foo2 | ||
EOF | ||
clientexit=$? | ||
|
||
# Wait for server to exit | ||
wait $server1; server1exit=$? | ||
|
||
# Check exit statuses | ||
if [ $server1exit -ne 0 ]; then | ||
echo "Simulated server #1 exited with status $server1exit" | ||
exit $server1exit | ||
fi | ||
if [ $clientexit -ne 0 ]; then | ||
echo "$clientprog exited with status $clientexit" | ||
exit $clientexit | ||
fi | ||
|
||
# Check the output from clusterclient | ||
expected="Event: slotmap-updated | ||
Event: ready | ||
Event: slotmap-updated | ||
error: slot not served by any node | ||
Event: slotmap-updated | ||
bar2 | ||
Event: free-context" | ||
|
||
echo "$expected" | diff -u - "$testname.out" || exit 99 | ||
|
||
# Clean up | ||
rm "$testname.out" |