-
Notifications
You must be signed in to change notification settings - Fork 255
chore: add test scenarios and docs for redis read replicas #3177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Noroth
wants to merge
4
commits into
main
Choose a base branch
from
ludwig/eng-9915-redis-read-replica-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+526
−14
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d10244
chore: add test scenario for readonly replicas
Noroth 51b8090
chore: improve docs
Noroth 57e5586
Merge branch 'main' into ludwig/eng-9915-redis-read-replica-support
Noroth 7179acd
Merge branch 'main' into ludwig/eng-9915-redis-read-replica-support
SkArchon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,23 +1,56 @@ | ||
| # wait for the docker-compose depends_on to spin up the redis nodes usually takes this long | ||
| sleep 10 | ||
|
|
||
| node_1_ip=$(getent hosts redis-cluster-node-1 | awk '{ print $1 }') | ||
| node_2_ip=$(getent hosts redis-cluster-node-2 | awk '{ print $1 }') | ||
| node_3_ip=$(getent hosts redis-cluster-node-3 | awk '{ print $1 }') | ||
| resolve() { | ||
| getent hosts "$1" | awk '{ print $1 }' | ||
| } | ||
|
|
||
| master_ips="" | ||
| for node in redis-cluster-node-1 redis-cluster-node-2 redis-cluster-node-3; do | ||
| ip=$(resolve $node) | ||
| if [ -z "$ip" ]; then | ||
| echo "$node did not resolve, cannot create the cluster" | ||
| exit 1 | ||
| fi | ||
| master_ips="$master_ips $ip" | ||
| done | ||
|
|
||
| # Nodes 4-6 only run when the redis-cluster-replicas compose profile is enabled, so they are | ||
| # picked up when they resolve and left out of the cluster otherwise. | ||
| replica_ips="" | ||
| replica_count=0 | ||
| for node in redis-cluster-node-4 redis-cluster-node-5 redis-cluster-node-6; do | ||
| ip=$(resolve $node) | ||
| if [ -z "$ip" ]; then | ||
| continue | ||
| fi | ||
| replica_ips="$replica_ips $ip" | ||
| replica_count=$((replica_count + 1)) | ||
| done | ||
|
|
||
| # redis-cli spreads replicas evenly over the masters, so it takes one each or none at all. | ||
| replicas_per_master=0 | ||
| if [ "$replica_count" -eq 3 ]; then | ||
| replicas_per_master=1 | ||
| elif [ "$replica_count" -ne 0 ]; then | ||
| echo "Only $replica_count of the 3 replica nodes are running, creating the cluster without replicas" | ||
| replica_ips="" | ||
| fi | ||
|
|
||
| node_ips="$master_ips $replica_ips" | ||
|
|
||
| # Prepare the nodes for the cluster | ||
| for ip in $node_1_ip $node_2_ip $node_3_ip; do | ||
| for ip in $node_ips; do | ||
| echo "Emptying db 0 of Redis node at $ip and resetting cluster" | ||
| redis-cli -h $ip -p 6379 FLUSHDB | ||
| redis-cli -h $ip -p 6379 CLUSTER RESET | ||
| redis-cli -h $ip -p 6379 CONFIG SET cluster-announce-ip "$ip" | ||
| done | ||
|
|
||
| # Create the cluster | ||
| # Create the cluster. The masters come first, so the replica nodes that follow become their | ||
| # replicas, which is what read_only=true routing needs to be exercised. | ||
| redis-cli --cluster create \ | ||
| $node_1_ip:6379 \ | ||
| $node_2_ip:6379 \ | ||
| $node_3_ip:6379 \ | ||
| --cluster-replicas 0 --cluster-yes | ||
| $(for ip in $node_ips; do printf '%s:6379 ' "$ip"; done) \ | ||
| --cluster-replicas $replicas_per_master --cluster-yes | ||
|
|
||
| echo "Redis Cluster setup complete!" | ||
| echo "Redis Cluster setup complete!" |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.