Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Preperation to support different database backends #939

Merged
merged 27 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
09376f3
feat, wip, first step towards a generic db interface
merl111 Apr 5, 2019
76542b8
removed old LevelDB implementation
merl111 Apr 14, 2019
4d39469
feat, reworked blockchain db layer
merl111 Apr 14, 2019
bd02494
feat, NotificationDB now uses the new layer too
merl111 Apr 14, 2019
9ebdde6
feat, factory for prefixed db and snapshot. DB unit tests, Notificati…
merl111 Apr 24, 2019
d3aead8
fix, fixed a few things to make UTs pass
merl111 Apr 24, 2019
7771107
fix, added locking, removed unused code
merl111 Apr 25, 2019
c912b2b
fixed typo
merl111 Apr 29, 2019
94017a8
moved AbstractDBInterface to AbstractDBImplementation to avoid confusion
merl111 Apr 29, 2019
7952819
Documented new classes and methods to povide information on how to im…
merl111 Apr 29, 2019
631228f
extended doc strings, made linter happy
merl111 May 10, 2019
5ac7e58
fixed typos, changed DBFactory
merl111 May 14, 2019
11e644b
extended docstrings + fixed minor bugs
merl111 May 15, 2019
2237261
added unit test for db factory, default values for db settings
merl111 May 16, 2019
281264d
corrected database paths in configs
merl111 May 16, 2019
728666b
Merge branch 'development' into alt-db-support
merl111 May 16, 2019
f08dd6b
fixed paths to data directories
merl111 May 20, 2019
df26c05
fix, fixed typos, minor refactoring after review, fixed bug with paths
merl111 May 21, 2019
50a8c7d
made linter happy
merl111 May 21, 2019
71262dd
removed files slipped in through upstream merge
merl111 May 30, 2019
0f12117
Merge remote-tracking branch 'upstream/development' into alt-db-support
merl111 May 30, 2019
50ac3e1
made linter happy...again
merl111 May 30, 2019
5ab843b
Merge remote-tracking branch 'upstream/development' into alt-db-support
merl111 May 30, 2019
98c9ed4
updated import_blocks and export_blocks to new database layer, remove…
merl111 Jun 5, 2019
c5bb6ce
fix, minor fixes
merl111 Jun 5, 2019
939749d
fix, take --datadir intou account when starting np=prompt, removed du…
merl111 Jun 12, 2019
bc6883e
Merge remote-tracking branch 'upstream/development' into alt-db-support
merl111 Jun 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions neo/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ def debug_storage_leveldb_path(self):
def database_properties(self):
return {'blockchain': {'path': self.chain_leveldb_path,
'skip_version_check': False,
'backend': 'leveldb'},
'backend': 'neo.Storage.Implementation.LevelDB.LevelDBImpl.LevelDBImpl'},
merl111 marked this conversation as resolved.
Show resolved Hide resolved

'notification': {'path': self.notification_leveldb_path,
'backend': 'leveldb'},
'backend': 'neo.Storage.Implementation.LevelDB.LevelDBImpl.LevelDBImpl'},

'debug': {'path': self.debug_storage_leveldb_path,
'backend': 'leveldb'}
'backend': 'neo.Storage.Implementation.LevelDB.LevelDBImpl.LevelDBImpl'}
}

# Helpers
Expand Down
12 changes: 6 additions & 6 deletions neo/Storage/Implementation/AbstractDBImplementation.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from abc import ABC, abstractmethod
"""
Description:
Abstract class used to ensure the mandatory methods are overwritten
in everxy new database implementation.
Alternative backends can be added by implementing the required methods
of this abstract class.
Usage:
The dynamically generated class coming from the database factory inherits
from the abstract class, means the generated class cannot be used if not
from the abstract class, means the generated class cannot be used if not
all methods defined in this class are overwritten.

If this class is extended, make sure you extend also all other database
implementations.

For a more detailed information on the methods and how to implement a new
For a more detailed information on the methods and how to implement a new
merl111 marked this conversation as resolved.
Show resolved Hide resolved
database backend check out:
neo.Storage.Implementation.LevelDB.LevelDBClassMethods
merl111 marked this conversation as resolved.
Show resolved Hide resolved
"""
Expand Down Expand Up @@ -48,9 +48,9 @@ def getBatch(self):
raise NotImplementedError

@abstractmethod
def closeDB(self):
def getPrefixedDB(self, prefix):
raise NotImplementedError

@abstractmethod
def getPrefixedDB(self, prefix):
def closeDB(self):
raise NotImplementedError
49 changes: 4 additions & 45 deletions neo/Storage/Implementation/DBFactory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from neo.Storage.Implementation.AbstractDBImplementation import (
AbstractDBImplementation
)
from neo.Settings import settings
from neo.logging import log_manager

from neo.Utils.plugin import load_class_from_path

"""Database factory module

Expand All @@ -27,8 +23,6 @@

"""

logger = log_manager.getLogger()

BC_CONST = 'blockchain'
NOTIF_CONST = 'notification'
DEBUG_CONST = 'debug'
Expand All @@ -50,7 +44,7 @@ def getBlockchainDB(path=None):
if not path:
path = DATABASE_PROPS[BC_CONST]['path']

BlockchainDB = _dbFactory(BC_CONST, DATABASE_PROPS[BC_CONST])
BlockchainDB = load_class_from_path(DATABASE_PROPS[BC_CONST]['backend'])
_blockchain_db_instance = BlockchainDB(path)
return _blockchain_db_instance

Expand All @@ -69,7 +63,7 @@ def getNotificationDB(path=None):
if not path:
path = DATABASE_PROPS[NOTIF_CONST]['path']

NotificationDB = _dbFactory(NOTIF_CONST, DATABASE_PROPS[NOTIF_CONST])
NotificationDB = load_class_from_path(DATABASE_PROPS[NOTIF_CONST]['backend'])
_notif_db_instance = NotificationDB(path)
return _notif_db_instance

Expand All @@ -82,41 +76,6 @@ def getDebugStorageDB():
_debug_db_instance (object): A new debug storage instance.
"""

DebugStorageDB = _dbFactory(DEBUG_CONST, DATABASE_PROPS[DEBUG_CONST])
DebugStorageDB = load_class_from_path(DATABASE_PROPS[DEBUG_CONST]['backend'])
_debug_db_instance = DebugStorageDB(DATABASE_PROPS[DEBUG_CONST]['path'])
return _debug_db_instance


def _dbFactory(dbType, properties):
""" Method to generate a database class.

Args:
dbType (str): Type of the database (Blockchain, Notification, Debug).
properties (dict): The properties defined within the settings module.

Returns:
New database class to instantiate a new database.


"""

if properties['backend'] == 'leveldb':

"""
Module implements the methods used by the dynamically generated class.
"""
import neo.Storage.Implementation.LevelDB.LevelDBClassMethods as functions

methods = [x for x in dir(functions) if not x.startswith('__')]

# build the dict containing all the attributes (methods + members)
attributes = {methods[i]: getattr(
functions, methods[i]) for i in range(0, len(methods))}

# add __init__ method
attributes['__init__'] = attributes.pop(functions._init_method)

return type(
properties['backend'].title() + 'DBImpl' + dbType.title(),
(AbstractDBImplementation,),
attributes)
235 changes: 0 additions & 235 deletions neo/Storage/Implementation/LevelDB/LevelDBClassMethods.py

This file was deleted.

Loading