forked from LBRYCommunity/lbry-sdk
add ELASTIC_HOST and ELASTIC_PORT settings to hub
This commit is contained in:
parent
d025ee9dbe
commit
7832c62c5d
5 changed files with 25 additions and 8 deletions
|
@ -27,6 +27,8 @@ def main():
|
||||||
coin_class = get_coin_class(args.spvserver)
|
coin_class = get_coin_class(args.spvserver)
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logging.info('lbry.server starting')
|
logging.info('lbry.server starting')
|
||||||
|
logging.getLogger('aiohttp').setLevel(logging.WARNING)
|
||||||
|
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
|
||||||
try:
|
try:
|
||||||
server = Server(Env(coin_class))
|
server = Server(Env(coin_class))
|
||||||
server.run()
|
server.run()
|
||||||
|
|
|
@ -33,7 +33,7 @@ class StreamResolution(str):
|
||||||
|
|
||||||
|
|
||||||
class SearchIndex:
|
class SearchIndex:
|
||||||
def __init__(self, index_prefix: str, search_timeout=3.0):
|
def __init__(self, index_prefix: str, search_timeout=3.0, elastic_host='localhost', elastic_port=9200):
|
||||||
self.search_timeout = search_timeout
|
self.search_timeout = search_timeout
|
||||||
self.sync_timeout = 600 # wont hit that 99% of the time, but can hit on a fresh import
|
self.sync_timeout = 600 # wont hit that 99% of the time, but can hit on a fresh import
|
||||||
self.search_client: Optional[AsyncElasticsearch] = None
|
self.search_client: Optional[AsyncElasticsearch] = None
|
||||||
|
@ -44,13 +44,17 @@ class SearchIndex:
|
||||||
self.short_id_cache = LRUCache(2 ** 17) # never invalidated, since short ids are forever
|
self.short_id_cache = LRUCache(2 ** 17) # never invalidated, since short ids are forever
|
||||||
self.search_cache = LRUCache(2 ** 17)
|
self.search_cache = LRUCache(2 ** 17)
|
||||||
self.resolution_cache = LRUCache(2 ** 17)
|
self.resolution_cache = LRUCache(2 ** 17)
|
||||||
|
self._elastic_host = elastic_host
|
||||||
|
self._elastic_port = elastic_port
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
if self.sync_client:
|
if self.sync_client:
|
||||||
return
|
return
|
||||||
self.sync_client = AsyncElasticsearch(timeout=self.sync_timeout)
|
hosts = [{'host': self._elastic_host, 'port': self._elastic_port}]
|
||||||
self.search_client = AsyncElasticsearch(timeout=self.search_timeout)
|
self.sync_client = AsyncElasticsearch(hosts, timeout=self.sync_timeout)
|
||||||
|
self.search_client = AsyncElasticsearch(hosts, timeout=self.search_timeout)
|
||||||
while True:
|
while True:
|
||||||
|
self.logger.info("DOITDOITDOIT\n\n\n\n%s:%i\n\n\n", self._elastic_host, self._elastic_port)
|
||||||
try:
|
try:
|
||||||
await self.sync_client.cluster.health(wait_for_status='yellow')
|
await self.sync_client.cluster.health(wait_for_status='yellow')
|
||||||
break
|
break
|
||||||
|
|
|
@ -8,8 +8,9 @@ from multiprocessing import Process
|
||||||
import apsw
|
import apsw
|
||||||
from elasticsearch import AsyncElasticsearch
|
from elasticsearch import AsyncElasticsearch
|
||||||
from elasticsearch.helpers import async_bulk
|
from elasticsearch.helpers import async_bulk
|
||||||
|
from lbry.wallet.server.env import Env
|
||||||
from .search import extract_doc, SearchIndex
|
from lbry.wallet.server.coin import LBC
|
||||||
|
from lbry.wallet.server.db.elasticsearch.search import extract_doc, SearchIndex
|
||||||
|
|
||||||
INDEX = 'claims'
|
INDEX = 'claims'
|
||||||
|
|
||||||
|
@ -48,7 +49,9 @@ ORDER BY claim.height desc
|
||||||
|
|
||||||
|
|
||||||
async def consume(producer):
|
async def consume(producer):
|
||||||
es = AsyncElasticsearch()
|
env = Env(LBC)
|
||||||
|
logging.info("ES sync host: %s:%i", env.elastic_host, env.elastic_port)
|
||||||
|
es = AsyncElasticsearch([{'host': env.elastic_host, 'port': env.elastic_port}])
|
||||||
try:
|
try:
|
||||||
await async_bulk(es, producer, request_timeout=120)
|
await async_bulk(es, producer, request_timeout=120)
|
||||||
await es.indices.refresh(index=INDEX)
|
await es.indices.refresh(index=INDEX)
|
||||||
|
@ -57,7 +60,8 @@ async def consume(producer):
|
||||||
|
|
||||||
|
|
||||||
async def make_es_index():
|
async def make_es_index():
|
||||||
index = SearchIndex('')
|
env = Env(LBC)
|
||||||
|
index = SearchIndex('', elastic_host=env.elastic_host, elastic_port=env.elastic_port)
|
||||||
try:
|
try:
|
||||||
return await index.start()
|
return await index.start()
|
||||||
finally:
|
finally:
|
||||||
|
@ -83,6 +87,9 @@ def __run(args, shard):
|
||||||
|
|
||||||
def run_elastic_sync():
|
def run_elastic_sync():
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
logging.getLogger('aiohttp').setLevel(logging.WARNING)
|
||||||
|
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
|
||||||
|
|
||||||
logging.info('lbry.server starting')
|
logging.info('lbry.server starting')
|
||||||
parser = argparse.ArgumentParser(prog="lbry-hub-elastic-sync")
|
parser = argparse.ArgumentParser(prog="lbry-hub-elastic-sync")
|
||||||
parser.add_argument("db_path", type=str)
|
parser.add_argument("db_path", type=str)
|
||||||
|
|
|
@ -974,7 +974,9 @@ class LBRYLevelDB(LevelDB):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Search index
|
# Search index
|
||||||
self.search_index = SearchIndex(self.env.es_index_prefix, self.env.database_query_timeout)
|
self.search_index = SearchIndex(
|
||||||
|
self.env.es_index_prefix, self.env.database_query_timeout, self.env.elastic_host, self.env.elastic_port
|
||||||
|
)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
super().close()
|
super().close()
|
||||||
|
|
|
@ -33,6 +33,8 @@ class Env:
|
||||||
self.allow_root = self.boolean('ALLOW_ROOT', False)
|
self.allow_root = self.boolean('ALLOW_ROOT', False)
|
||||||
self.host = self.default('HOST', 'localhost')
|
self.host = self.default('HOST', 'localhost')
|
||||||
self.rpc_host = self.default('RPC_HOST', 'localhost')
|
self.rpc_host = self.default('RPC_HOST', 'localhost')
|
||||||
|
self.elastic_host = self.default('ELASTIC_HOST', 'localhost')
|
||||||
|
self.elastic_port = self.integer('ELASTIC_PORT', 9200)
|
||||||
self.loop_policy = self.set_event_loop_policy()
|
self.loop_policy = self.set_event_loop_policy()
|
||||||
self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK'])
|
self.obsolete(['UTXO_MB', 'HIST_MB', 'NETWORK'])
|
||||||
self.db_dir = self.required('DB_DIRECTORY')
|
self.db_dir = self.required('DB_DIRECTORY')
|
||||||
|
|
Loading…
Reference in a new issue