From 65f3d520559708d04f8e2835340d3ec0da0e4755 Mon Sep 17 00:00:00 2001 From: Tommi Vainikainen Date: Wed, 10 Apr 2024 16:51:34 +0300 Subject: [PATCH] Retry on temporary errors from schema reader If leader for partition is not available, it is a temporary error that is resolved after re-fetching metadata. Log, but ignore those errors. --- karapace/schema_reader.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/karapace/schema_reader.py b/karapace/schema_reader.py index 750992686..0fdcd2f16 100644 --- a/karapace/schema_reader.py +++ b/karapace/schema_reader.py @@ -16,8 +16,10 @@ InvalidReplicationFactorError, KafkaConfigurationError, KafkaTimeoutError, + LeaderNotAvailableError, NoBrokersAvailable, NodeNotReadyError, + NotLeaderForPartitionError, TopicAlreadyExistsError, TopicAuthorizationFailedError, UnknownTopicOrPartitionError, @@ -246,6 +248,8 @@ def _get_beginning_offset(self) -> int: LOG.warning("Reading begin offsets timed out.") except UnknownTopicOrPartitionError: LOG.warning("Topic does not yet exist.") + except (LeaderNotAvailableError, NotLeaderForPartitionError): + LOG.warning("Retrying to find leader for schema topic partition.") except Exception as e: # pylint: disable=broad-except self.stats.unexpected_exception(ex=e, where="_get_beginning_offset") LOG.exception("Unexpected exception when reading begin offsets.") @@ -265,6 +269,9 @@ def _is_ready(self) -> bool: except UnknownTopicOrPartitionError: LOG.warning("Topic does not yet exist.") return False + except (LeaderNotAvailableError, NotLeaderForPartitionError): + LOG.warning("Retrying to find leader for schema topic partition.") + return False except Exception as e: # pylint: disable=broad-except self.stats.unexpected_exception(ex=e, where="_is_ready") LOG.exception("Unexpected exception when reading end offsets.")