Merge "Moved the thread storage to a per instance level, vs global"
This commit is contained in:
commit
4bcd1030c2
@ -36,7 +36,6 @@ from designate.sqlalchemy.expressions import InsertFromSelect
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOCAL_STORE = threading.local()
|
||||
TSIG_SUPPORTED_ALGORITHMS = ['hmac-md5']
|
||||
|
||||
cfg.CONF.register_group(cfg.OptGroup(
|
||||
@ -59,6 +58,11 @@ cfg.CONF.set_default('connection',
|
||||
class PowerDNSBackend(base.Backend):
|
||||
__plugin_name__ = 'powerdns'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PowerDNSBackend, self).__init__(*args, **kwargs)
|
||||
|
||||
self.local_store = threading.local()
|
||||
|
||||
def start(self):
|
||||
super(PowerDNSBackend, self).start()
|
||||
|
||||
@ -70,10 +74,10 @@ class PowerDNSBackend(base.Backend):
|
||||
# leads to bad things happening.
|
||||
global LOCAL_STORE
|
||||
|
||||
if not hasattr(LOCAL_STORE, 'session'):
|
||||
LOCAL_STORE.session = session.get_session(self.name)
|
||||
if not hasattr(self.local_store, 'session'):
|
||||
self.local_store.session = session.get_session(self.name)
|
||||
|
||||
return LOCAL_STORE.session
|
||||
return self.local_store.session
|
||||
|
||||
# TSIG Key Methods
|
||||
def create_tsigkey(self, context, tsigkey):
|
||||
|
@ -33,7 +33,6 @@ from designate.sqlalchemy.models import SoftDeleteMixin
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
LOCAL_STORE = threading.local()
|
||||
|
||||
cfg.CONF.register_group(cfg.OptGroup(
|
||||
name='storage:sqlalchemy', title="Configuration for SQLAlchemy Storage"
|
||||
@ -81,18 +80,19 @@ class SQLAlchemyStorage(base.Storage):
|
||||
|
||||
self.engine = session.get_engine(self.name)
|
||||
|
||||
self.local_store = threading.local()
|
||||
|
||||
@property
|
||||
def session(self):
|
||||
# NOTE: This uses a thread local store, allowing each greenthread to
|
||||
# have it's own session stored correctly. Without this, each
|
||||
# greenthread may end up using a single global session, which
|
||||
# leads to bad things happening.
|
||||
global LOCAL_STORE
|
||||
|
||||
if not hasattr(LOCAL_STORE, 'session'):
|
||||
LOCAL_STORE.session = session.get_session(self.name)
|
||||
if not hasattr(self.local_store, 'session'):
|
||||
self.local_store.session = session.get_session(self.name)
|
||||
|
||||
return LOCAL_STORE.session
|
||||
return self.local_store.session
|
||||
|
||||
def begin(self):
|
||||
self.session.begin(subtransactions=True)
|
||||
|
Loading…
Reference in New Issue
Block a user