def get_total_replica_vbucket_moves(self): moves = self.get_replica_vbucket_moves() if self.is_colored_vbmap_problem(): result = 0 for x in moves: result += util.sum_off_diagonal(x) else: result = util.sum_off_diagonal(moves) return result
def calculate_cost(begin_bucket_config, end_bucket_config): # Note that this function only works for straight adds with 1 replica start = do_bucket_config(begin_bucket_config) end = do_bucket_config(end_bucket_config) node_count = max(len(start['serverList']), len(end['serverList'])) active_moves = [[0 for _ in xrange(node_count)] for _ in xrange(node_count)] replica_moves = [[0 for _ in xrange(node_count)] for _ in xrange(node_count)] end_vb_map = end['vBucketMap'] begin_vb_map = start['vBucketMap'] i = 0 for end_chain in end_vb_map: begin_chain = begin_vb_map[i] active_moves[begin_chain[0]][end_chain[0]] += 1 replica_moves[begin_chain[1]][end_chain[1]] += 1 i += 1 print "active moves:" print twod_array_to_string(active_moves, with_indices=True, delimiter='\t', total=True) print "replica moves:" print twod_array_to_string(replica_moves, with_indices=True, delimiter='\t', total=True) print "active move cost: ", util.sum_off_diagonal(active_moves) print "replica move cost: ", util.sum_off_diagonal(replica_moves) print "total cost: ", util.sum_off_diagonal(active_moves) + util.sum_off_diagonal(replica_moves)