The oslo_db.api Module

Multiple DB API backend support.

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.

class 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.

Parameters:
  • 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
Default backend_mapping:
 

None

Default lazy:

False

classmethod from_config(conf, backend_mapping=None, lazy=False)

Initialize DBAPI instance given a config instance.

Parameters:
  • 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()
Parameters:f (function.) – database api method.
class 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, retry_on_request=False, exception_checker=<function <lambda> at 0x7f69e705d8c0>)

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:

Parameters:
  • 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

Table Of Contents

Previous topic

The oslo_db._i18n Module

Next topic

The oslo_db.concurrency Module

Project Source

This Page