From ae89ccc9dfc6b8a88535e1e6a86529c0032a2632 Mon Sep 17 00:00:00 2001 From: Sam Nguyen <118077+dtjm@users.noreply.github.com> Date: Fri, 1 Nov 2019 11:59:53 -0700 Subject: [PATCH] Update `Error` consts and `Error.Temporary()` (#372) --- error.go | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/error.go b/error.go index dc91e6e2c..744535dcd 100644 --- a/error.go +++ b/error.go @@ -6,6 +6,7 @@ import ( ) // Error represents the different error codes that may be returned by kafka. +// https://kafka.apache.org/protocol#protocol_error_codes type Error int const ( @@ -22,6 +23,7 @@ const ( MessageSizeTooLarge Error = 10 StaleControllerEpoch Error = 11 OffsetMetadataTooLarge Error = 12 + NetworkException Error = 13 GroupLoadInProgress Error = 14 GroupCoordinatorNotAvailable Error = 15 NotCoordinatorForGroup Error = 16 @@ -85,6 +87,12 @@ const ( FencedLeaderEpoch Error = 74 UnknownLeaderEpoch Error = 75 UnsupportedCompressionType Error = 76 + StaleBrokerEpoch Error = 77 + OffsetNotAvailable Error = 78 + MemberIDRequired Error = 79 + PreferredLeaderNotAvailable Error = 80 + GroupMaxSizeReached Error = 81 + FencedInstanceID Error = 82 ) // Error satisfies the error interface. @@ -99,14 +107,35 @@ func (e Error) Timeout() bool { // Temporary returns true if the operation that generated the error may succeed // if retried at a later time. +// Kafka error documentation specifies these as "retriable" +// https://kafka.apache.org/protocol#protocol_error_codes func (e Error) Temporary() bool { - return e == LeaderNotAvailable || - e == BrokerNotAvailable || - e == ReplicaNotAvailable || - e == GroupLoadInProgress || - e == GroupCoordinatorNotAvailable || - e == RebalanceInProgress || - e.Timeout() + switch e { + case InvalidMessage, + UnknownTopicOrPartition, + LeaderNotAvailable, + NotLeaderForPartition, + RequestTimedOut, + NetworkException, + GroupLoadInProgress, + GroupCoordinatorNotAvailable, + NotCoordinatorForGroup, + NotEnoughReplicas, + NotEnoughReplicasAfterAppend, + NotController, + KafkaStorageError, + FetchSessionIDNotFound, + InvalidFetchSessionEpoch, + ListenerNotFound, + FencedLeaderEpoch, + UnknownLeaderEpoch, + OffsetNotAvailable, + PreferredLeaderNotAvailable: + return true + + default: + return false + } } // Title returns a human readable title for the error.