Skip to content
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

chore: randomize the selection of nodes to balance the load #68

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions housewatch/clickhouse/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def execute_backup(
):
"""
This function will execute a backup on each shard in a cluster
This is very similar to run_query_on_shards but it has very specific things for backups
specifically around base_backup settings
This is very similar to run_query_on_shards but it has very specific params
for backups - specifically around base_backup settings
"""
nodes = get_node_per_shard(cluster)
responses = []
Expand Down
5 changes: 4 additions & 1 deletion housewatch/clickhouse/clusters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from collections import defaultdict
from housewatch.clickhouse.client import run_query

Expand Down Expand Up @@ -38,11 +39,13 @@ def get_node_per_shard(cluster):
preferred = PreferredReplica.objects.filter(cluster=cluster).values_list("replica", flat=True)
for shard, n in shards.items():
preferred_replica_found = False
# shuffle the nodes so we don't always pick the first preferred one
random.shuffle(n)
for node in n:
if node["host_name"] in preferred:
nodes.append((shard, node))
preferred_replica_found = True
break
if not preferred_replica_found:
nodes.append((shard, n[0]))
nodes.append((shard, random.choice(n)))
return nodes
2 changes: 1 addition & 1 deletion housewatch/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


sentry_sdk.init(
dsn="https://6a05afd8bf4e2d54c81833ca1ff98cca@o607503.ingest.sentry.io/4505874503237633",
dsn="https://8874d21e05d62df688505df70c9f053d@o1015702.ingest.us.sentry.io/4507393944846336",
integrations=[DjangoIntegration()],
# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
Expand Down
Loading