Ejemplo n.º 1
0
 def _on_my_identity_rotated(self, evt):
     from logs import lg
     from lib import packetid
     from storage import backup_matrix
     backup_matrix.ReadLocalFiles()
     remote_files_ids = list(backup_matrix.remote_files().keys())
     for currentID in remote_files_ids:
         latestID = packetid.LatestBackupID(currentID)
         if latestID != currentID:
             backup_matrix.remote_files(
             )[latestID] = backup_matrix.remote_files().pop(currentID)
             lg.info(
                 'detected backup ID change in remote_files() after identity rotate : %r -> %r'
                 % (
                     currentID,
                     latestID,
                 ))
     remote_max_block_numbers_ids = list(
         backup_matrix.remote_max_block_numbers().keys())
     for currentID in remote_max_block_numbers_ids:
         latestID = packetid.LatestBackupID(currentID)
         if latestID != currentID:
             backup_matrix.remote_max_block_numbers(
             )[latestID] = backup_matrix.remote_max_block_numbers().pop(
                 currentID)
             lg.info(
                 'detected backup ID change in remote_max_block_numbers() after identity rotate : %r -> %r'
                 % (
                     currentID,
                     latestID,
                 ))
Ejemplo n.º 2
0
 def doScanBrokenBlocks(self, *args, **kwargs):
     """
     Action method.
     """
     # if remote data structure is not exist for this backup - create it
     # this mean this is only local backup!
     from storage import backup_matrix
     if self.currentBackupID not in backup_matrix.remote_files():
         backup_matrix.remote_files()[self.currentBackupID] = {}
         # we create empty remote info for every local block
         # range(0) should return []
         for blockNum in range(backup_matrix.local_max_block_numbers().get(
                 self.currentBackupID, -1) + 1):
             backup_matrix.remote_files()[
                 self.currentBackupID][blockNum] = {
                     'D': [0] * contactsdb.num_suppliers(),
                     'P': [0] * contactsdb.num_suppliers()
                 }
     # detect missing blocks from remote info
     self.workingBlocksQueue = backup_matrix.ScanMissingBlocks(
         self.currentBackupID)
     # find the correct max block number for this backup
     # we can have remote and local files
     # will take biggest block number from both
     backupMaxBlock = max(
         backup_matrix.remote_max_block_numbers().get(
             self.currentBackupID, -1),
         backup_matrix.local_max_block_numbers().get(
             self.currentBackupID, -1))
     # now need to remember this biggest block number
     # remote info may have less blocks - need to create empty info for
     # missing blocks
     for blockNum in range(backupMaxBlock + 1):
         if blockNum in backup_matrix.remote_files()[self.currentBackupID]:
             continue
         backup_matrix.remote_files()[self.currentBackupID][blockNum] = {
             'D': [0] * contactsdb.num_suppliers(),
             'P': [0] * contactsdb.num_suppliers()
         }
     # clear requesting queue, remove old packets for this backup, we will
     # send them again
     from stream import io_throttle
     io_throttle.DeleteBackupRequests(self.currentBackupID)
     if _Debug:
         lg.out(
             _DebugLevel,
             'backup_rebuilder.doScanBrokenBlocks for %s : %s' %
             (self.currentBackupID, str(self.workingBlocksQueue)))
     self.automat('backup-ready')