def test_swap_partitions_change_not_performed(self):
        swap_change = SwapPartitionsChange(self.zk, lambda x: load_swap_data(x, -1, 10001))
        result = swap_change.run([])

        # change should not trigger partitions swap as there is no possible
        # partitions swap that will decrease the gap between brokers
        assert not result
        self.zk.reallocate_partitions.assert_not_called()
Example #2
0
    def test_swap_partitions_change_postponed_when_rebalancing(self):
        self.zk.is_rebalancing.return_value = True

        swap_change = SwapPartitionsChange(self.zk, None)
        result = swap_change.run([])

        # if there was a rebalance node in ZK - the change should be postponed
        assert result
        assert not swap_change.to_move
Example #3
0
    def test_swap_partitions_change_not_performed(self):
        swap_change = SwapPartitionsChange(
            self.zk, lambda x: load_swap_data(x, -1, 10001))
        result = swap_change.run([])

        # change should not trigger partitions swap as there is no possible
        # partitions swap that will decrease the gap between brokers
        assert not result
        self.zk.reallocate_partitions.assert_not_called()
    def test_swap_partitions_change_postponed_when_rebalancing(self):
        self.zk.is_rebalancing.return_value = True

        swap_change = SwapPartitionsChange(self.zk, None)
        result = swap_change.run([])

        # if there was a rebalance node in ZK - the change should be postponed
        assert result
        assert not swap_change.to_move
    def test_swap_partitions_change_performed(self):
        def _swap_data_provider(zk):
            return load_swap_data(zk, -1, 10000)

        swap_change = SwapPartitionsChange(self.zk, _swap_data_provider)
        result = swap_change.run([])

        assert not result
        self.zk.reallocate_partitions.assert_called_with([('t2', 2, [222, 111]), ('t2', 1, [222, 333])])
    def test_swap_partitions_change_postponed(self):
        self.zk.reallocate_partitions.return_value = False

        swap_change = SwapPartitionsChange(self.zk, lambda x: load_swap_data(x, -1, 10000))
        result = swap_change.run([])

        # if the write to ZK wasn't possible for some reason, the change should
        # return True and repeat write to ZK during next trigger by controller
        assert result
        assert swap_change.to_move == [('t2', 2, [222, 111]), ('t2', 1, [222, 333])]
Example #7
0
    def test_swap_partitions_change_performed_existing(self):
        swap_change = SwapPartitionsChange(self.zk, None)
        dummy_move_list = ["dummy"]
        swap_change.to_move = ["dummy"]
        result = swap_change.run([])

        # if there already was a pair of partitions to swap in to_move
        # property - SwapPartitionsChange should just execute this swap
        assert not result
        self.zk.reallocate_partitions.assert_called_with(dummy_move_list)
        self.zk.load_partition_assignment.assert_not_called()
    def test_swap_partitions_change_performed_existing(self):
        swap_change = SwapPartitionsChange(self.zk, None)
        dummy_move_list = ["dummy"]
        swap_change.to_move = ["dummy"]
        result = swap_change.run([])

        # if there already was a pair of partitions to swap in to_move
        # property - SwapPartitionsChange should just execute this swap
        assert not result
        self.zk.reallocate_partitions.assert_called_with(dummy_move_list)
        self.zk.load_partition_assignment.assert_not_called()
Example #9
0
    def test_swap_partitions_change_postponed(self):
        self.zk.reallocate_partitions.return_value = False

        swap_change = SwapPartitionsChange(
            self.zk, lambda x: load_swap_data(x, -1, 10000))
        result = swap_change.run([])

        # if the write to ZK wasn't possible for some reason, the change should
        # return True and repeat write to ZK during next trigger by controller
        assert result
        assert swap_change.to_move == [('t2', 2, [222, 111]),
                                       ('t2', 1, [222, 333])]
Example #10
0
    def test_swap_partitions_change_performed(self):
        def _swap_data_provider(zk):
            return load_swap_data(zk, -1, 10000)

        swap_change = SwapPartitionsChange(self.zk, _swap_data_provider)
        result = swap_change.run([])

        assert not result
        self.zk.reallocate_partitions.assert_called_with([('t2', 2, [222,
                                                                     111]),
                                                          ('t2', 1, [222,
                                                                     333])])
Example #11
0
 def check(self) -> Change:
     with self.zk.lock():
         data = self.zk.take_action(
             self.broker_manager.id_manager.detect_broker_id())
     if not data:
         return None
     if 'name' not in data:
         _LOG.error(
             'Action name can not be restored from {}, skipping'.format(
                 data))
         return None
     try:
         if data['name'] == 'restart':
             return RestartBrokerChange(self.zk, self.broker_manager,
                                        lambda: False)
         elif data['name'] == 'rebalance':
             return OptimizedRebalanceChange(self.zk,
                                             self.zk.get_broker_ids())
         elif data['name'] == 'migrate':
             return MigrationChange(self.zk, data['from'], data['to'],
                                    data['shrink'])
         elif data['name'] == 'fatboyslim':
             return SwapPartitionsChange(
                 self.zk, lambda x: load_swap_data(
                     x, self.api_port, int(data['threshold_kb'])))
         else:
             _LOG.error('Action {} not supported'.format(data))
     except Exception as e:
         _LOG.error('Failed to create action from {}'.format(data),
                    exc_info=e)
     return None