mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 15:05:49 +00:00
Merge branch 'planetmint-tarantool' of github.com:liviu-lesan/planetmint into planetmint-tarantool
got new updates, now planetmint work.
This commit is contained in:
commit
2087c81f91
@ -10,6 +10,7 @@ from planetmint.config import Config
|
|||||||
from planetmint.transactions.common.exceptions import ConfigurationError
|
from planetmint.transactions.common.exceptions import ConfigurationError
|
||||||
from planetmint.utils import Lazy
|
from planetmint.utils import Lazy
|
||||||
from planetmint.backend.connection import Connection
|
from planetmint.backend.connection import Connection
|
||||||
|
from planetmint.utils import Lazy
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -17,13 +18,12 @@ logger = logging.getLogger(__name__)
|
|||||||
class TarantoolDBConnection(Connection):
|
class TarantoolDBConnection(Connection):
|
||||||
def __init__(self, host: str = "localhost", port: int = 3303, user: str = None, password: str = None, **kwargs):
|
def __init__(self, host: str = "localhost", port: int = 3303, user: str = None, password: str = None, **kwargs):
|
||||||
try:
|
try:
|
||||||
|
super().__init__(**kwargs)
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
# TODO add user support later on
|
# TODO add user support later on
|
||||||
print(f"host : {host}")
|
print(f"host : {host}")
|
||||||
print(f"port : {port}")
|
print(f"port : {port}")
|
||||||
# TODO : raise configuraiton error if the connection cannot be established
|
|
||||||
self.db_connect = tarantool.connect(host=self.host, port=self.port)
|
|
||||||
self.init_path = Config().get()["database"]["init_config"]["absolute_path"]
|
self.init_path = Config().get()["database"]["init_config"]["absolute_path"]
|
||||||
self.drop_path = Config().get()["database"]["drop_config"]["absolute_path"]
|
self.drop_path = Config().get()["database"]["drop_config"]["absolute_path"]
|
||||||
self.SPACE_NAMES = ["abci_chains", "assets", "blocks", "blocks_tx",
|
self.SPACE_NAMES = ["abci_chains", "assets", "blocks", "blocks_tx",
|
||||||
@ -36,27 +36,27 @@ class TarantoolDBConnection(Connection):
|
|||||||
logger.info('Exception in _connect(): {}')
|
logger.info('Exception in _connect(): {}')
|
||||||
raise ConfigurationError
|
raise ConfigurationError
|
||||||
|
|
||||||
|
def query(self):
|
||||||
|
return Lazy()
|
||||||
|
|
||||||
def _file_content_to_bytes(self, path):
|
def _file_content_to_bytes(self, path):
|
||||||
with open(path, "r") as f:
|
with open(path, "r") as f:
|
||||||
execute = f.readlines()
|
execute = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
return "".join(execute).encode()
|
return "".join(execute).encode()
|
||||||
|
|
||||||
def query(self):
|
def _connect(self):
|
||||||
return Lazy()
|
return tarantool.connect(host=self.host, port=self.port)
|
||||||
|
|
||||||
def _reconnect(self):
|
|
||||||
self.db_connect = tarantool.connect(host=self.host, port=self.port)
|
|
||||||
|
|
||||||
def get_space(self, space_name: str):
|
def get_space(self, space_name: str):
|
||||||
return self.db_connect.space(space_name)
|
return self.conn.space(space_name)
|
||||||
|
|
||||||
def space(self, space_name: str):
|
def space(self, space_name: str):
|
||||||
return self.query().space(space_name)
|
return self.query().space(space_name)
|
||||||
|
|
||||||
def run(self, query, only_data=True):
|
def run(self, query, only_data=True):
|
||||||
try:
|
try:
|
||||||
return query.run(self.db_connect).data if only_data else query.run(self.db_connect)
|
return query.run(self.conn).data if only_data else query.run(self.conn)
|
||||||
except tarantool.error.SchemaError:
|
except tarantool.error.SchemaError:
|
||||||
return None
|
return None
|
||||||
except tarantool.error.OperationalError as op_error:
|
except tarantool.error.OperationalError as op_error:
|
||||||
@ -65,17 +65,15 @@ class TarantoolDBConnection(Connection):
|
|||||||
raise net_error
|
raise net_error
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
return self.db_connect
|
return self.conn
|
||||||
|
|
||||||
def drop_database(self):
|
def drop_database(self):
|
||||||
db_config = Config().get()["database"]
|
db_config = Config().get()["database"]
|
||||||
cmd_resp = self.run_command(command=self.drop_path, config=db_config)
|
cmd_resp = self.run_command(command=self.drop_path, config=db_config)
|
||||||
self._reconnect()
|
|
||||||
|
|
||||||
def init_database(self):
|
def init_database(self):
|
||||||
db_config = Config().get()["database"]
|
db_config = Config().get()["database"]
|
||||||
cmd_resp = self.run_command(command=self.init_path, config=db_config)
|
cmd_resp = self.run_command(command=self.init_path, config=db_config)
|
||||||
self._reconnect()
|
|
||||||
|
|
||||||
def run_command(self, command: str, config: dict):
|
def run_command(self, command: str, config: dict):
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||||
|
|
||||||
"""Query implementation for Tarantool"""
|
"""Query implementation for Tarantool"""
|
||||||
|
|
||||||
from secrets import token_hex
|
from secrets import token_hex
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ from json import dumps, loads
|
|||||||
|
|
||||||
register_query = module_dispatch_registrar(query)
|
register_query = module_dispatch_registrar(query)
|
||||||
|
|
||||||
|
@register_query(TarantoolDBConnection)
|
||||||
def _group_transaction_by_ids(connection, txids: list):
|
def _group_transaction_by_ids(connection, txids: list):
|
||||||
txspace = connection.get_space("transactions")
|
txspace = connection.get_space("transactions")
|
||||||
inxspace = connection.get_space("inputs")
|
inxspace = connection.get_space("inputs")
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import warnings
|
import logging
|
||||||
|
|
||||||
import tarantool
|
import tarantool
|
||||||
from planetmint.backend.utils import module_dispatch_registrar
|
from planetmint.backend.utils import module_dispatch_registrar
|
||||||
from planetmint import backend
|
from planetmint import backend
|
||||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
register_schema = module_dispatch_registrar(backend.schema)
|
register_schema = module_dispatch_registrar(backend.schema)
|
||||||
|
|
||||||
SPACE_NAMES = ("abci_chains", "assets", "blocks", "blocks_tx",
|
SPACE_NAMES = ("abci_chains", "assets", "blocks", "blocks_tx",
|
||||||
@ -162,14 +163,15 @@ def drop_database(connection, not_used=None):
|
|||||||
|
|
||||||
|
|
||||||
@register_schema(TarantoolDBConnection)
|
@register_schema(TarantoolDBConnection)
|
||||||
def create_database(connection, not_used=None):
|
def create_database(connection, dbname):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
For tarantool implementation, this function runs
|
For tarantool implementation, this function runs
|
||||||
create_tables, to initiate spaces, schema and indexes.
|
create_tables, to initiate spaces, schema and indexes.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
create_tables(None, None)
|
logger.info('Create database `%s`.', dbname)
|
||||||
|
create_tables(connection, dbname)
|
||||||
|
|
||||||
|
|
||||||
def run_command_with_output(command):
|
def run_command_with_output(command):
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import aiohttp
|
|||||||
|
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from concurrent.futures import CancelledError
|
from concurrent.futures import CancelledError
|
||||||
from planetmint import config
|
from planetmint.config import Config
|
||||||
from planetmint.web.websocket_dispatcher import Dispatcher
|
from planetmint.web.websocket_dispatcher import Dispatcher
|
||||||
|
|
||||||
|
|
||||||
@ -146,6 +146,6 @@ def start(sync_event_source, loop=None):
|
|||||||
|
|
||||||
app = init_app(tx_source, blk_source, loop=loop)
|
app = init_app(tx_source, blk_source, loop=loop)
|
||||||
aiohttp.web.run_app(app,
|
aiohttp.web.run_app(app,
|
||||||
host=config['wsserver']['host'],
|
host=Config().get()['wsserver']['host'],
|
||||||
port=config['wsserver']['port'],
|
port=Config().get()['wsserver']['port'],
|
||||||
loop=loop)
|
loop=loop)
|
||||||
|
|||||||
3
setup.py
3
setup.py
@ -95,8 +95,7 @@ install_requires = [
|
|||||||
'setproctitle==1.2.2',
|
'setproctitle==1.2.2',
|
||||||
'werkzeug==2.0.3',
|
'werkzeug==2.0.3',
|
||||||
'nest-asyncio==1.5.5',
|
'nest-asyncio==1.5.5',
|
||||||
'protobuf==3.19.0'
|
'protobuf==3.20'
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if sys.version_info < (3, 9):
|
if sys.version_info < (3, 9):
|
||||||
|
|||||||
@ -131,7 +131,7 @@ def _setup_database(_configure_planetmint): # TODO Here is located setup databa
|
|||||||
conn = connect()
|
conn = connect()
|
||||||
|
|
||||||
_drop_db(conn, dbname)
|
_drop_db(conn, dbname)
|
||||||
schema.init_database(conn)
|
schema.init_database(conn, dbname)
|
||||||
print('Finishing init database')
|
print('Finishing init database')
|
||||||
|
|
||||||
yield
|
yield
|
||||||
@ -145,7 +145,8 @@ def _setup_database(_configure_planetmint): # TODO Here is located setup databa
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def _bdb(_setup_database, _configure_planetmint):
|
def _bdb(_setup_database, _configure_planetmint):
|
||||||
from planetmint.backend.connection import connect
|
print(f"BDB CALL")
|
||||||
|
from planetmint.backend import connect
|
||||||
from planetmint.transactions.common.memoize import to_dict, from_dict
|
from planetmint.transactions.common.memoize import to_dict, from_dict
|
||||||
from planetmint.models import Transaction
|
from planetmint.models import Transaction
|
||||||
from .utils import flush_db
|
from .utils import flush_db
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user