Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Status

Current state: Under discussion.

...

Instantiating a new client may result in a fatal failure if the bootstrap server cannot be resolved due to misconfiguration or transient network issues such as slow DNS. This is suboptimal because of , including the fact that it might take a long time for the address to become available at the DNS server and users will need to continue to retry.  Also, the ConfigException exception type does not accurately reflect the root cause of the problem, and it doesn't allow users to retry to resolve transient issues.  It would be more effective to provide a grace period for retry attempts before ultimately failingwhich makes it hard to handle this failure case.  We think it is reasonable to allow users to have a grace period to retry if the address cannot be resolved immediately. Also, poisoning the clients during the construction can be obstructive; I think it is better to fail the client on its first attempt to connect to the network.

Proposed Changes

This KIP proposes moving bootstrapping logic from the constructor to the NetworkClient poll for two purposes,

1. not failing the client upon instantiation. In many cases, this behavior also kills the app, which might not be desirable.

2. piggybacking onto the client poll is a more natural way to retry.

We propose to add . This change ensures that the client doesn't fail at startup due to issues like misconfiguration or network disruptions and allows for retries upon subsequent poll() invocations. The proposed updates include introducing a new configuration option for timing out the bootstrapping process, a new exception type for handling bootstrap-related issues, and additional logging to aid in diagnosing bootstrapping failures.

Public Facing Changes

  • Timeout Configuration: bootstrap.connection.timeout.ms
  • Exception: BootstrapConnectionException extends KafkaException
  • Logging: log.WARN("Unable to bootstrap after {} ms.", elapsedMs)

Internal Changes

  • Client Constructor: The constructor will only parse the bootstrap configuration.

  • NetworkClient:

    • Bootstrapping will now occur in the poll method before attempting to update the metadata. This includes resolving the addresses and bootstrapping the metadata.
    • An error message will be logged in the event of a failed bootstrap process.
    • If the timeout exceeds, a non-retriable BootstrapConnectionException will be thrown.
  • Consumer, Producer, and Admin Clients: The bootstrap code will be changed.

...

Compatibility, Deprecation, and Migration Plan

  • Client Behaviors Changes

    • Bootstrap upon first NetworkClient.poll() instead of in the constructor.

    • Bootstrapping is retriable.

    • KafkaConsumer: Users can retry bootstrapping via poll() if it fails. Each retry will be bounded by either the poll timer or the bootstrap timer, whichever expires first.

    • KafkaAdminClient: Bootstrap exception is thrown when user tries to materialize the result future. The retry is bounded by the API timeout.

    • KafkaProducer: Bootstrap will be done in the background thread. If the client has not been bootstrapped when the user attempts to send a message, it can wait up to the maximum block timer or until the bootstrap is complete, whichever expires first.

    Exception Handling

      • Throws BootstrapConnectionException

Case Study

Compatibility

  • There shouldn't be a compatibility problem as the bootstrap logic changes only affect the failure scenario.
  • The user can use a timeout (bootstrap.connection.timeout.ms) of 0 to mimic the current behavior, i.e. fatal upon the first failure.

Deprecation

  • There's no deprecation plan

Migration

  • There's no migration plan

Case Study

Every time the network client attempts to bootstrap and fails, a warning message will be logged.  In this section, I outlined how clients can react to bootstrap failures. In particular, I want to cover two common cases:

...

Case 1: Unable to connect to the bootstrap(For example: misconfiguration)

When the bootstrap timeout expires, the client will throw a BootstrapConnectionException on poll().

Case 2: Transient Network Issue (For example: transient DNS failure)Issue

consumer poll won't return any record until the client has been bootstrappedIf there is a transient network issue, such as slow DNS resolution, poll() will continue to return an empty record until the issue is resolved. If the issue cannot be resolved within the bootstrap timeout, a BootstrapConnectionException will be thrown on poll().

KafkaProducer

Case 1: Unable to connect to the bootstrap(For example: misconfiguration)

The BootstrapConnectionException will be thrown in send() and partitionsFor() when the bootstrap timeout expires. If the max.block.ms elapsed before the timeout expires, a TimeoutException will be thrown instead.

Case 2: Transient Network Issue (For example: transient DNS failure)Issue

The send() and partitionsFor() methods will be blocked on bootstrap until either the max.block.ms or the bootstrap timeout elapses.

...

Case 1: Unable to connect to the bootstrap(For example: misconfiguration)

The API call results will either timeout if the request times out first or be completed exceptionally with a BootstrapConnectionException

Case 2: Transient Network Issue (For example: transient DNS failure)Issue

If there is a transient network issue, such as a transient DNS failure, the user won't be able to get the results back until the bootstrap issue is resolved.  Meanwhile, the API calls will expire.

...