Skip to content

Commit c82fbde

Browse files
committed
chore: randomize the selection of nodes to balance the load
1 parent 83a4376 commit c82fbde

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

housewatch/clickhouse/backups.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def execute_backup(
3030
):
3131
"""
3232
This function will execute a backup on each shard in a cluster
33-
This is very similar to run_query_on_shards but it has very specific things for backups
34-
specifically around base_backup settings
33+
This is very similar to run_query_on_shards but it has very specific params
34+
for backups - specifically around base_backup settings
3535
"""
3636
nodes = get_node_per_shard(cluster)
3737
responses = []

housewatch/clickhouse/clusters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import random
12
from collections import defaultdict
23
from housewatch.clickhouse.client import run_query
34

@@ -38,11 +39,13 @@ def get_node_per_shard(cluster):
3839
preferred = PreferredReplica.objects.filter(cluster=cluster).values_list("replica", flat=True)
3940
for shard, n in shards.items():
4041
preferred_replica_found = False
42+
# shuffle the nodes so we don't always pick the first preferred one
43+
random.shuffle(n)
4144
for node in n:
4245
if node["host_name"] in preferred:
4346
nodes.append((shard, node))
4447
preferred_replica_found = True
4548
break
4649
if not preferred_replica_found:
47-
nodes.append((shard, n[0]))
50+
nodes.append((shard, random.choice(n)))
4851
return nodes

housewatch/settings/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

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

0 commit comments

Comments
 (0)