Skip to content
Snippets Groups Projects
Commit 7399e388 authored by Mariusz Trela's avatar Mariusz Trela
Browse files

Restoring indexes is always done

parent 7ebf112e
No related branches found
No related tags found
3 merge requests!456Release candidate v1 24,!230Setup monitoring with pghero,!144Restoring indexes is always done
This commit is part of merge request !144. Comments created here will be created in the context of that merge request.
...@@ -137,6 +137,30 @@ class DbState: ...@@ -137,6 +137,30 @@ class DbState:
assert not to_locate, "indexes not located: {}".format(to_locate) assert not to_locate, "indexes not located: {}".format(to_locate)
return to_return return to_return
@classmethod
def processing_indexes(cls, is_pre_process, drop, create ):
# sql = "SELECT promoted FROM hive_posts WHERE id = :id"
# curr_amount = DB.query_one(sql, id=record['post_id'])
# new_amount = curr_amount + record['amount']
DB = cls.db()
engine = DB.engine()
log.info("[INIT] Begin %s-initial sync hooks", "pre" if is_pre_process else "post" )
for index in cls._disableable_indexes():
log.info("%s index %s.%s", ( "Drop" if is_pre_process else "Recreate" ), index.table, index.name)
try:
if drop:
sql = "SELECT count(*) FROM pg_class WHERE relname = :relname"
_count = DB.query_one(sql, relname=index.name)
if _count == 1:
index.drop(engine)
except sqlalchemy.exc.ProgrammingError as ex:
log.warning("Ignoring ex: {}".format(ex))
if create:
index.create(engine)
@classmethod @classmethod
def before_initial_sync(cls, last_imported_block, hived_head_block): def before_initial_sync(cls, last_imported_block, hived_head_block):
"""Routine which runs *once* after db setup. """Routine which runs *once* after db setup.
...@@ -150,16 +174,8 @@ class DbState: ...@@ -150,16 +174,8 @@ class DbState:
log.info("[INIT] Skipping pre-initial sync hooks") log.info("[INIT] Skipping pre-initial sync hooks")
return return
engine = cls.db().engine() #is_pre_process, drop, create
log.info("[INIT] Begin pre-initial sync hooks") cls.processing_indexes( True, True, False )
for index in cls._disableable_indexes():
log.info("Drop index %s.%s", index.table, index.name)
try:
index.drop(engine)
except sqlalchemy.exc.ProgrammingError as ex:
log.warning("Ignoring ex: {}".format(ex))
from hive.db.schema import drop_fk, set_logged_table_attribute from hive.db.schema import drop_fk, set_logged_table_attribute
log.info("Dropping FKs") log.info("Dropping FKs")
...@@ -196,22 +212,8 @@ class DbState: ...@@ -196,22 +212,8 @@ class DbState:
synced_blocks = current_imported_block - last_imported_block synced_blocks = current_imported_block - last_imported_block
if synced_blocks >= SYNCED_BLOCK_LIMIT: #is_pre_process, drop, create
engine = cls.db().engine() cls.processing_indexes( False, True, True )
log.info("[INIT] Begin post-initial sync hooks")
for index in cls._disableable_indexes():
log.info("Recreate index %s.%s", index.table, index.name)
try:
index.drop(engine)
except sqlalchemy.exc.ProgrammingError as ex:
log.warning("Ignoring ex: {}".format(ex))
index.create(engine)
log.info("[INIT] Finish post-initial sync hooks")
else:
log.info("[INIT] Post-initial sync hooks skipped")
current_work_mem = cls.update_work_mem('2GB') current_work_mem = cls.update_work_mem('2GB')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment