bigchaindb/bigchaindb/backend
Vanshdeep Singh 5bfa8e29d8 Crash recovery mechanism (#2045)
* Crash recovery mechanism

* Propogate exception

* Added docs and crash receovery during block write

* Fix flake8 issue

* Remove approach 1 for crash recovery, recover db on 'bigchiandb start'

* Fix CI build issues

* Remove documentation
2018-02-21 10:50:12 +01:00
..
localmongodb Crash recovery mechanism (#2045) 2018-02-21 10:50:12 +01:00
mongodb Merge branch 'master' into tendermint 2017-11-30 18:17:36 +01:00
rethinkdb Pre commit styling (#1914) 2017-11-30 15:04:14 +01:00
README.md Abstract db layer cherrypick docs (#932) 2016-12-12 18:28:43 +01:00
__init__.py Resolves #948 2017-01-16 07:12:25 -05:00
admin.py Added tests 2017-01-25 12:36:08 +01:00
changefeed.py fixed typo 2016-12-14 13:28:37 +01:00
connection.py Flat UTXO collection and first integration with Tendermint™ (#1822) 2017-11-10 17:53:57 +01:00
exceptions.py Enable Auth over TLS connections (#1552) 2017-06-22 16:32:04 +02:00
query.py Crash recovery mechanism (#2045) 2018-02-21 10:50:12 +01:00
schema.py Merge branch 'master' into bug/1592/metadata-text-search 2017-11-09 17:39:35 +05:30
utils.py Pre commit styling (#1914) 2017-11-30 15:04:14 +01:00

README.md

Backend Interfaces

Structure

  • changefeed.py: Changefeed-related interfaces
  • connection.py: Database connection-related interfaces
  • query.py: Database query-related interfaces, dispatched through single-dispatch
  • schema.py: Database setup and schema-related interfaces, dispatched through single-dispatch

Built-in implementations (e.g. RethinkDB's) are provided in sub-directories and have their connection type's location exposed as BACKENDS in connection.py.

Single-Dispatched Interfaces

The architecture of this module is based heavily upon Python's newly-introduced single-dispatch generic functions. Single-dispatch is convenient, because it allows Python, rather than something we design ourselves, to manage the dispatching of generic functions based on certain conditions being met (e.g. the database backend to use).

To see what this looks like in BigchainDB, first note that our backend interfaces have been configured to dispatch based on a backend's connection type.

Call bigchaindb.backend.connect() to create an instance of a Connection:

from bigchaindb.backend import connect
connection = connect()  # By default, uses the current configuration for backend, host, port, etc.

Then, we can call a backend function by directly calling its interface:

from bigchaindb.backend import query
query.write_transaction(connection, ...)

Notice that we don't need to care about which backend implementation to use or how to access it. Code can simply call the base interface function with a Connection instance, and single-dispatch will handle routing the call to the actual implementation.

BigchainDB will load and register the configured backend's implementation automatically (see bigchaindb.backend.connect()), so you should always just be able to call an interface function if you have a Connection instance. A few helper utilities (see backend/utils.py) are also provided to make registering new backend implementations easier.