Commit e6a41f4d authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

Remove multi-DB config for production

Not feasible to use multiple DBs for read or write operations at
present. We're going to have to revisit this at some point. We leave
most of the code in place but commented out.
parent fe6b97b2
Pipeline #52955 passed with stages
in 35 seconds
......@@ -16,16 +16,23 @@ if (isinstance(is_priority_server, str) and
is_priority_server.lower() in ['true', 't']):
PRIORITY_SERVER = True
## If priority server, do some things
#if PRIORITY_SERVER:
# # Add custom permissions for API
# default_perms = list(REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'])
# default_perms = ['api.permissions.IsPriorityUser'] + default_perms
# REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'] = tuple(default_perms)
#
# # Don't do anything to databases. Priority servers use the master
# # for both read and write operations
#else:
# If priority server, only allow priority users
if PRIORITY_SERVER:
# Add custom permissions for API
default_perms = list(REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'])
default_perms = ['api.permissions.IsPriorityUser'] + default_perms
REST_FRAMEWORK['DEFAULT_PERMISSION_CLASSES'] = tuple(default_perms)
# TP, March 2019: for now, it looks infeasible to use multiple databases
# since there are many operations which normal LVC users can do that
# do a write and then a read very soon after. And we can't rely on
# the read replica being updated quickly enough for that to work.
# So there are several workflows that need to be redone in order for
# this to be possible, but it's not obvious that they even can be
# reworked properly. I.e. this is a much bigger project than expected
# so we're going to have to revisit it at some point. We'll leave the
# config here for now.
# # If not a priority server, we use the read-only replica database
# # for reads and master for writes.
# # The username, password, and database name are all replicated
......
import logging
from django.conf import settings
# Set up logger
logger = logging.getLogger(__name__)
class NonPriorityRouter(object):
"""For non-priority production workers in a swarm container deployment"""
def db_for_read(self, model, **hints):
# For API throttle caches and sessions, we want to always read out
# of the master (or use a separate database)
if (model._meta.db_table == settings.CACHES['throttles']['LOCATION']):
return 'default'
elif (model._meta.app_label == 'user_sessions' and
model._meta.model_name == 'session'):
return 'default'
# Otherwise, use the read replica
return 'read_replica'
def db_for_write(self, model, **hints):
return 'default'
def allow_relation(self, obj1, obj2, **hints):
return True
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment