Example #1
0
 def periodic_backup(self):
     time.sleep(60)
     if not self.own_start is None:
         backup = {}
         self.write_lock.acquire()
         records = shelve.open(self.db)
         for k in records.keys():
             k_key = hash_util.Key(k)
             if hash_util.hash_between_right_inclusive(k_key,self.own_start, self.own_end):
                 backup[k] = records[k]
         size = len(backup.keys())
         if size > 0:
             newmsg = Database_Backup_Message(self.owner, backup)
             self.send_message(newmsg,node.predecessor)
         records.close()
         self.write_lock.release()
Example #2
0
 def change_in_responsibility(self,new_pred_key, my_key):
     self.own_start = new_pred_key
     self.own_end = my_key
     backup = {}
     self.write_lock.acquire()
     records = shelve.open(self.db)
     for k in records.keys():
         k_key = hash_util.Key(k)
         if not hash_util.hash_between_right_inclusive(k_key,self.own_start, self.own_end):
             backup[k] = records[k]
     size = len(backup.keys())
     if size > 0:
         newmsg = Database_Backup_Message(self.owner, backup)
         self.send_message(newmsg,node.predecessor)
     records.close()
     self.write_lock.release()