Skip to content

Commit

Permalink
Add db read replica 3 (#9453)
Browse files Browse the repository at this point in the history
* Updating read replica list to include #3

* Adding read_replica_3 to settings
  • Loading branch information
zlsgh authored and Jer-Sch committed Sep 22, 2021
1 parent 3531d95 commit 935c721
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
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

0 comments on commit 935c721

Please sign in to comment.