Пример #1
0
async def test_on_timeout(extra_context, loop):
    logger = Mock()
    assert isinstance(on_timeout, _FlightRecorderProxy)

    # Test no errors when there's no active flight recorder
    _assert_log_severities(on_timeout)

    with patch('mode.utils.logging.asctime') as asctime:
        asctime.return_value = 'TIME'
        # Test logging to active flight recorder (with nesting)
        with flight_recorder(logger, timeout=300) as fl1:
            fl1.extra_context.update(extra_context)
            assert current_flight_recorder() is fl1
            _assert_recorder_exercised(on_timeout, fl1)

            with flight_recorder(logger, timeout=30)as fl2:
                for k, v in fl1.extra_context.items():
                    assert fl2.extra_context[k] == v
                assert current_flight_recorder() is fl2
                _assert_recorder_exercised(on_timeout, fl2)
                _assert_recorder_flush_logs(logger, fl2)

            assert current_flight_recorder() is fl1
            _assert_recorder_flush_logs(logger, fl1)
            _assert_recorder_exercised(on_timeout, fl1)
            _assert_recorder_flush_logs(logger, fl1)
Пример #2
0
    async def _on_partitions_revoked(self, revoked: Set[TP]) -> None:
        """Handle revocation of topic partitions.

        This is called during a rebalance and is followed by
        :meth:`on_partitions_assigned`.

        Revoked means the partitions no longer exist, or they
        have been reassigned to a different node.
        """
        if self.should_stop:
            return self._on_rebalance_when_stopped()
        session_timeout = self.conf.broker_session_timeout
        with flight_recorder(self.log, timeout=session_timeout) as on_timeout:
            self._on_revoked_timeout = on_timeout
            try:
                self.log.dev('ON PARTITIONS REVOKED')
                on_timeout.info('fetcher.stop()')
                await self._stop_fetcher()
                on_timeout.info('tables.stop_standbys()')
                await self.tables._stop_standbys()
                assignment = self.consumer.assignment()
                if assignment:
                    on_timeout.info('flow_control.suspend()')
                    self.flow_control.suspend()
                    on_timeout.info('consumer.pause_partitions')
                    await self.consumer.pause_partitions(assignment)
                    # Every agent instance has an incoming buffer of messages
                    # (a asyncio.Queue) -- we clear those to make sure
                    # agents will not start processing them.
                    #
                    # This allows for large buffer sizes
                    # (stream_buffer_maxsize).
                    on_timeout.info('flow_control.clear()')
                    self.flow_control.clear()

                    # even if we clear, some of the agent instances may have
                    # already started working on an event.
                    #
                    # we need to wait for them.
                    if self.conf.stream_wait_empty:
                        on_timeout.info('consumer.wait_empty()')
                        await self.consumer.wait_empty()
                    on_timeout.info('agents.on_partitions_revoked')
                    await self.agents.on_partitions_revoked(revoked)
                else:
                    self.log.dev('ON P. REVOKED NOT COMMITTING: NO ASSIGNMENT')
                on_timeout.info('topics.on_partitions_revoked()')
                await self.topics.on_partitions_revoked(revoked)
                on_timeout.info('tables.on_partitions_revoked()')
                await self.tables.on_partitions_revoked(revoked)
                on_timeout.info('+send signal: on_partitions_revoked')
                await self.on_partitions_revoked.send(revoked)
                on_timeout.info('-send signal: on_partitions_revoked')
            except Exception as exc:
                on_timeout.info('on partitions assigned crashed: %r', exc)
                await self.crash(exc)
            finally:
                self._on_revoked_timeout = None
Пример #3
0
    async def _on_partitions_assigned(self, assigned: Set[TP]) -> None:
        """Handle new topic partition assignment.

        This is called during a rebalance after :meth:`on_partitions_revoked`.

        The new assignment overrides the previous
        assignment, so any tp no longer in the assigned' list will have
        been revoked.
        """
        if self.should_stop:
            return self._on_rebalance_when_stopped()
        session_timeout = self.conf.broker_session_timeout
        self.unassigned = not assigned
        with flight_recorder(self.log, timeout=session_timeout) as on_timeout:
            try:
                on_timeout.info('fetcher.stop()')
                await self._stop_fetcher()
                on_timeout.info('agents.on_partitions_assigned()')
                await self.agents.on_partitions_assigned(assigned)
                # Wait for transport.Conductor to finish
                # calling Consumer.subscribe
                on_timeout.info('topics.wait_for_subscriptions()')
                await self.topics.wait_for_subscriptions()
                on_timeout.info('consumer.pause_partitions()')
                await self.consumer.pause_partitions(assigned)
                on_timeout.info('topics.on_partitions_assigned()')
                await self.topics.on_partitions_assigned(assigned)
                on_timeout.info('tables.on_partitions_assigned()')
                await self.tables.on_partitions_assigned(assigned)
                on_timeout.info('+send signal: on_partitions_assigned')
                await self.on_partitions_assigned.send(assigned)
                on_timeout.info('-send signal: on_partitions_assigned')
                on_timeout.info('flow_control.resume()')
                self.flow_control.resume()
            except Exception as exc:
                on_timeout.info('on partitions assigned crashed: %r', exc)
                await self.crash(exc)
Пример #4
0
 def bb(self, *, logger):
     return flight_recorder(logger, timeout=30.0)