mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
saves
This commit is contained in:
parent
5275747c50
commit
b8cecb3448
@ -55,6 +55,12 @@ config = {
|
|||||||
log_config['handlers']['console']['level']).lower(),
|
log_config['handlers']['console']['level']).lower(),
|
||||||
'workers': None, # if None, the value will be cpu_count * 2 + 1
|
'workers': None, # if None, the value will be cpu_count * 2 + 1
|
||||||
},
|
},
|
||||||
|
"ctl_config": {
|
||||||
|
"login": "admin",
|
||||||
|
"host": "admin:pass@127.0.0.1:3301",
|
||||||
|
"service": "tarantoolctl connect",
|
||||||
|
"init_file": "init_db.txt"
|
||||||
|
},
|
||||||
'wsserver': {
|
'wsserver': {
|
||||||
'scheme': 'ws',
|
'scheme': 'ws',
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import tarantool
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
from planetmint.backend.tarantool.utils import run
|
from planetmint.backend.tarantool.utils import run
|
||||||
|
|
||||||
@ -27,37 +26,30 @@ BACKENDS = { # This is path to MongoDBClass
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def init_tarantool():
|
|
||||||
init_lua_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tarantool", "init_db.lua")
|
|
||||||
tarantool_root = os.path.join(pathlib.Path.home(), 'tarantool')
|
|
||||||
snap = os.path.join(pathlib.Path.home(), 'tarantool_snap')
|
|
||||||
if os.path.exists(tarantool_root) is not True:
|
|
||||||
run(["mkdir", tarantool_root])
|
|
||||||
run(["mkdir", snap])
|
|
||||||
run(["tarantool", init_lua_path], tarantool_root)
|
|
||||||
else:
|
|
||||||
raise Exception("There is a instance of tarantool already created in %s" + snap)
|
|
||||||
|
|
||||||
|
|
||||||
def drop_tarantool():
|
|
||||||
drop_lua_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tarantool", "drop_db.lua")
|
|
||||||
tarantool_root = os.path.join(pathlib.Path.home(), 'tarantool')
|
|
||||||
init_lua = os.path.join(tarantool_root, 'init_db.lua')
|
|
||||||
if os.path.exists(init_lua) is not True:
|
|
||||||
run(["tarantool", drop_lua_path])
|
|
||||||
else:
|
|
||||||
raise Exception("There is no tarantool spaces to drop")
|
|
||||||
|
|
||||||
|
|
||||||
class TarantoolDB:
|
class TarantoolDB:
|
||||||
def __init__(self, host: str, port: int, user: str, password: str):
|
def __init__(self, host: str, port: int, user: str, password: str, reset_database: bool = False):
|
||||||
# init_tarantool()
|
if reset_database:
|
||||||
|
self.init_database()
|
||||||
self.db_connect = None
|
self.db_connect = None
|
||||||
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
|
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
|
||||||
|
|
||||||
|
def __init_tarantool(self):
|
||||||
|
from planetmint.backend.tarantool.utils import run
|
||||||
|
config = get_planetmint_config_value_or_key_error("ctl_config")
|
||||||
|
with open(config["init_file"], 'r') as file:
|
||||||
|
commands = [line + '\n' for line in file.readlines() if len(str(line)) > 1]
|
||||||
|
file.close()
|
||||||
|
run(commands=commands, config=config)
|
||||||
|
|
||||||
|
def __drop_tarantool(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
return self.db_connect
|
return self.db_connect
|
||||||
|
|
||||||
|
def init_database(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def connect(host: str = None, port: int = None, username: str = "admin", password: str = "pass", backend: str = None):
|
def connect(host: str = None, port: int = None, username: str = "admin", password: str = "pass", backend: str = None):
|
||||||
backend = backend or get_planetmint_config_value_or_key_error('backend') # TODO Rewrite Configs
|
backend = backend or get_planetmint_config_value_or_key_error('backend') # TODO Rewrite Configs
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
box.space.transactions.drop()
|
|
||||||
box.space.output.drop()
|
|
||||||
box.space.inputs.drop()
|
|
||||||
box.space.keys.drop()
|
|
||||||
box.space.abci_chains.drop()
|
|
||||||
box.space.assets.drop()
|
|
||||||
box.space.blocks.drop()
|
|
||||||
box.space.blocks_tx.drop()
|
|
||||||
box.space.elections.drop()
|
|
||||||
box.space.meta_datas.drop()
|
|
||||||
box.space.pre_commits.drop()
|
|
||||||
box.space.validators.drop()
|
|
||||||
box.space.
|
|
||||||
box.space.
|
|
||||||
box.snapshot()
|
|
||||||
@ -31,12 +31,12 @@ meta_datas:create_index('id_search', { type='hash' , parts={'transaction_id'}})
|
|||||||
pre_commits = box.schema.space.create('pre_commits' , {engine='memtx' , is_sync=false})
|
pre_commits = box.schema.space.create('pre_commits' , {engine='memtx' , is_sync=false})
|
||||||
pre_commits:format({{name='commit_id', type='string'}, {name='height',type='integer'}, {name='transactions',type=any}})
|
pre_commits:format({{name='commit_id', type='string'}, {name='height',type='integer'}, {name='transactions',type=any}})
|
||||||
pre_commits:create_index('id_search', {type ='hash' , parts={'commit_id'}})
|
pre_commits:create_index('id_search', {type ='hash' , parts={'commit_id'}})
|
||||||
pre_commits:create_index('height_search', {type ='tree',unique=false, parts={'height'}})
|
pre_commits:create_index('height_search', {type ='tree',unique=true, parts={'height'}})
|
||||||
|
|
||||||
validators = box.schema.space.create('validators' , {engine = 'memtx' , is_sync = false})
|
validators = box.schema.space.create('validators' , {engine = 'memtx' , is_sync = false})
|
||||||
validators:format({{name='validator_id' , type='string'},{name='height',type='integer'},{name='validators' , type='any'}})
|
validators:format({{name='validator_id' , type='string'},{name='height',type='integer'},{name='validators' , type='any'}})
|
||||||
validators:create_index('id_search' , {type='hash' , parts={'validator_id'}})
|
validators:create_index('id_search' , {type='hash' , parts={'validator_id'}})
|
||||||
validators:create_index('height_search' , {type='tree', unique=false, parts={'height'}})
|
validators:create_index('height_search' , {type='tree', unique=true, parts={'height'}})
|
||||||
|
|
||||||
transactions = box.schema.space.create('transactions',{engine='memtx' , is_sync=false})
|
transactions = box.schema.space.create('transactions',{engine='memtx' , is_sync=false})
|
||||||
transactions:format({{name='transaction_id' , type='string'}, {name='operation' , type='string'}, {name='version' ,type='string'}, {name='asset_id', type='string'}})
|
transactions:format({{name='transaction_id' , type='string'}, {name='operation' , type='string'}, {name='version' ,type='string'}, {name='asset_id', type='string'}})
|
||||||
@ -48,8 +48,8 @@ transactions:create_index('both_search' , {type = 'tree',unique=false, parts={'a
|
|||||||
|
|
||||||
inputs = box.schema.space.create('inputs')
|
inputs = box.schema.space.create('inputs')
|
||||||
inputs:format({{name='transaction_id' , type='string'}, {name='fulfillment' , type='string'}, {name='owners_before' , type='array'}, {name='fulfills_transaction_id', type = 'string'}, {name='fulfills_output_index', type = 'string'}, {name='input_id', type='string'}})
|
inputs:format({{name='transaction_id' , type='string'}, {name='fulfillment' , type='string'}, {name='owners_before' , type='array'}, {name='fulfills_transaction_id', type = 'string'}, {name='fulfills_output_index', type = 'string'}, {name='input_id', type='string'}})
|
||||||
inputs:create_index('spent_search' , {type = 'hash', parts={'fulfills_transaction_id', 'fulfills_output_index'}})
|
|
||||||
inputs:create_index('delete_search' , {type = 'hash', parts={'input_id'}})
|
inputs:create_index('delete_search' , {type = 'hash', parts={'input_id'}})
|
||||||
|
inputs:create_index('spent_search' , {type = 'tree', unique=false, parts={'fulfills_transaction_id', 'fulfills_output_index'}})
|
||||||
inputs:create_index('id_search', {type = 'tree', unique=false, parts = {'transaction_id'}})
|
inputs:create_index('id_search', {type = 'tree', unique=false, parts = {'transaction_id'}})
|
||||||
|
|
||||||
outputs = box.schema.space.create('outputs')
|
outputs = box.schema.space.create('outputs')
|
||||||
@ -58,10 +58,10 @@ outputs:create_index('unique_search' ,{type='hash', parts={'output_id'}})
|
|||||||
outputs:create_index('id_search' ,{type='tree', unique=false, parts={'transaction_id'}})
|
outputs:create_index('id_search' ,{type='tree', unique=false, parts={'transaction_id'}})
|
||||||
|
|
||||||
keys = box.schema.space.create('keys')
|
keys = box.schema.space.create('keys')
|
||||||
keys:format({{name = 'transaction_id', type = 'string'} ,{name = 'output_id', type = 'string'}, {name = 'public_key', type = 'string'}})
|
keys:format({{name = 'id', type='string'}, {name = 'transaction_id', type = 'string'} ,{name = 'output_id', type = 'string'}, {name = 'public_key', type = 'string'}})
|
||||||
keys:create_index('keys_search', {type = 'hash', parts={'public_key'}})
|
keys:create_index('id_search', {type = 'hash', parts={'id'}})
|
||||||
|
keys:create_index('keys_search', {type = 'tree', unique=false, parts={'public_key'}})
|
||||||
keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}})
|
keys:create_index('txid_search', {type = 'tree', unique=false, parts={'transaction_id'}})
|
||||||
keys:create_index('id_search', {type = 'tree', unique=false, parts={'output_id'}})
|
keys:create_index('output_search', {type = 'tree', unique=false, parts={'output_id'}})
|
||||||
|
|
||||||
local console = require('console')
|
box.schema.user.passwd('pass')
|
||||||
console.start()
|
|
||||||
@ -1,22 +1,17 @@
|
|||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def run(command, path=None):
|
def run(commands: list, config: dict):
|
||||||
if path is not None:
|
sshProcess = subprocess.Popen(['%s %s' % (config["service"], config["host"])],
|
||||||
os.chdir(path)
|
stdin=subprocess.PIPE,
|
||||||
p = subprocess.Popen(
|
stdout=subprocess.PIPE,
|
||||||
command
|
universal_newlines=True,
|
||||||
)
|
bufsize=0,
|
||||||
|
shell=True)
|
||||||
|
|
||||||
# output, error = p.communicate() # TODO Here was problem that we are waiting for outputs
|
for cmd in commands:
|
||||||
# if p.returncode != 0:
|
sshProcess.stdin.write(cmd)
|
||||||
# print(str(p.returncode) + "\n" + str(output) + "\n" + str(error))
|
sshProcess.stdin.close()
|
||||||
else:
|
# TODO To add here Exception Handler for stdout
|
||||||
p = subprocess.Popen(
|
# for line in sshProcess.stdout:
|
||||||
command
|
# print(line)
|
||||||
)
|
|
||||||
|
|
||||||
# output, error = p.communicate()
|
|
||||||
# if p.returncode != 0:
|
|
||||||
# print(str(p.returncode) + "\n" + str(output) + "\n" + str(error))
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user