oslo_db.api
Module¶A DB backend module should implement a method named ‘get_backend’ which takes no arguments. The method can return any object that implements DB API methods.
oslo_db.api.
DBAPI
(backend_name, backend_mapping=None, lazy=False, **kwargs)¶Bases: object
Initialize the chosen DB API backend.
After initialization API methods is available as normal attributes of
DBAPI
subclass. Database API methods are supposed to be called as
DBAPI instance methods.
backend_name (str) – name of the backend to load
backend_mapping (dict) – backend name -> module/class to load mapping
lazy (bool) – load the DB backend lazily on the first DB API method call
use_db_reconnect (bool) – retry DB transactions on disconnect or not
retry_interval (int) – seconds between transaction retries
inc_retry_interval (bool) – increase retry interval or not
max_retry_interval (int) – max interval value between retries
max_retries (int) – max number of retries before an error is raised
None
False
from_config
(conf, backend_mapping=None, lazy=False)¶Initialize DBAPI instance given a config instance.
conf (oslo.config.cfg.ConfigOpts) – oslo.config config instance
backend_mapping (dict) – backend name -> module/class to load mapping
lazy (bool) – load the DB backend lazily on the first DB API method call
oslo_db.api.
retry_on_deadlock
(f)¶Retry a DB API call if Deadlock was received.
wrap_db_entry will be applied to all db.api functions marked with this decorator.
oslo_db.api.
retry_on_request
(f)¶Retry a DB API call if RetryRequest exception was received.
wrap_db_entry will be applied to all db.api functions marked with this decorator.
oslo_db.api.
safe_for_db_retry
(f)¶Indicate api method as safe for re-connection to database.
Database connection retries will be enabled for the decorated api method. Database connection failure can have many causes, which can be temporary. In such cases retry may increase the likelihood of connection.
Usage:
@safe_for_db_retry
def api_method(self):
self.engine.connect()
f (function.) – database api method.
oslo_db.api.
wrap_db_retry
(retry_interval=1, max_retries=20, inc_retry_interval=True, max_retry_interval=10, retry_on_disconnect=False, retry_on_deadlock=False, exception_checker=<function wrap_db_retry.<lambda>>, jitter=False)¶Bases: object
Retry db.api methods, if db_error raised
Retry decorated db.api methods. This decorator catches db_error and retries function in a loop until it succeeds, or until maximum retries count will be reached.
Keyword arguments:
retry_interval (int or float) – seconds between transaction retries
max_retries (int) – max number of retries before an error is raised
inc_retry_interval (bool) – determine increase retry interval or not
max_retry_interval (int or float) – max interval value between retries
exception_checker (callable) – checks if an exception should trigger a retry
jitter (bool) – determine increase retry interval use jitter or not, jitter is always interpreted as True for a DBDeadlockError
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.