From 935c72119ac9ca273a1069728ab268204cda8e2d Mon Sep 17 00:00:00 2001 From: Zack Schiller <81022539+zacheryschiller@users.noreply.github.com> Date: Wed, 15 Sep 2021 06:14:11 -0400 Subject: [PATCH] Add db read replica 3 (#9453) * Updating read replica list to include #3 * Adding read_replica_3 to settings --- app/app/db.py | 4 ++-- app/app/settings.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/app/db.py b/app/app/db.py index e52a7e27ed7..3ed9af5ff0c 100644 --- a/app/app/db.py +++ b/app/app/db.py @@ -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): @@ -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 diff --git a/app/app/settings.py b/app/app/settings.py index f941a0cb6cf..938231c3194 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -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']