tell state engine to restore

This commit is contained in:
Jude Nelson
2018-01-22 17:13:13 -05:00
parent bdda580e04
commit c02ddd9cfc
2 changed files with 13 additions and 4 deletions

View File

@@ -626,8 +626,7 @@ def blockstack_backup_restore(working_dir, block_number):
Return True on success
Return False on failure
"""
db = BlockstackDB.get_readwrite_instance(working_dir)
res = db.db_restore(block_number=block_number)
db = BlockstackDB.get_readwrite_instance(working_dir, restore=True, restore_block_height=block_number)
db.close()
return res

View File

@@ -143,10 +143,11 @@ class BlockstackDB( virtualchain.StateEngine ):
@classmethod
def get_readwrite_instance(cls, working_dir):
def get_readwrite_instance(cls, working_dir, restore=False, restore_block_height=None):
"""
Get a read/write instance to the db, without the singleton check.
Only available in test mode
Used for low-level operations like db restore.
Not used in the steady state behavior of the system.
"""
log.warning("!!! Getting raw read/write DB instance !!!")
@@ -155,6 +156,15 @@ class BlockstackDB( virtualchain.StateEngine ):
db = BlockstackDB(db_path, DISPOSITION_RW, working_dir)
rc = db.db_setup()
if not rc:
if restore:
# restore from backup instead of bailing out
log.debug("Restoring from unclean shutdown")
rc = db.db_restore(block_number=restore_block_height)
if rc:
return db
else:
log.error("Failed to restore from unclean shutdown")
db.close()
raise Exception("Failed to set up db")