mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-21 09:55:29 +08:00
tell state engine to restore
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user