oslo.db.api

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.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, max_retries, inc_retry_interval, max_retry_interval)

Bases: object

Decorator class. Retry db.api methods, if DBConnectionError() raised.

Retry decorated db.api methods. If we enabled use_db_reconnect in config, this decorator will be applied to all db.api functions, marked with @safe_for_db_retry decorator. Decorator catches DBConnectionError() and retries function in a loop until it succeeds, or until maximum retries count will be reached.

Keyword arguments:

Parameters:
  • retry_interval (int) – 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) – max interval value between retries

Table Of Contents

Previous topic

API

Next topic

oslo.db.concurrency

This Page