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

Add db read replica 3 #9453

Merged
merged 2 commits into from
Sep 15, 2021
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 app/app/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def db_for_read(self, model, **hints):
Reads go to a randomly-chosen replica if backend node
Else go to default DB
"""
replicas = ['read_replica_1', 'read_replica_2']
replicas = ['read_replica_1', 'read_replica_2', 'read_replica_3']
return random.choice(replicas)

def db_for_write(self, model, **hints):
Expand All @@ -23,7 +23,7 @@ def allow_relation(self, obj1, obj2, **hints):
Relations between objects are allowed if both objects are
in the primary/replica pool.
"""
db_set = {'default', 'read_replica_1', 'read_replica_2'}
db_set = {'default', 'read_replica_1', 'read_replica_2', 'read_replica_3'}
if obj1._state.db in db_set and obj2._state.db in db_set:
return True
return True # TODO: be more stringent about this IFF we ever have a situation in which diff tables are on diff DBs
Expand Down
3 changes: 2 additions & 1 deletion app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@
DATABASES = {
'default': env.db(),
'read_replica_1': env.db('READ_REPLICA_1_DATABASE_URL'),
'read_replica_2': env.db('READ_REPLICA_2_DATABASE_URL')
'read_replica_2': env.db('READ_REPLICA_2_DATABASE_URL'),
'read_replica_3': env.db('READ_REPLICA_3_DATABASE_URL')
}
DATABASE_ROUTERS = ['app.db.PrimaryDBRouter']

Expand Down