Versions Compared

Key

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

KIP-367 Introduce close(Duration) to Producer and AdminClient instead of close(long, TimeUnit)

Table of Contents

This page is meant as a template for writing a KIP. To create a KIP choose Tools->Copy on this page and modify with your content and replace the heading with the next KIP number and a description of your issue. Replace anything in italics with your own description.

Status

Current state: TBD Accepted

Discussion thread: TBD thread

JIRA: TBD KAFKA-7391

Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Motivation

KIP-266 have replaced the (long, TimeUnit) by Duration for KafkaConsumer. For consistency, we should do the same APIs migration for KafkaProducer and KafkaAdminClient. 

Public Interfaces

KafkaProducer

Code Block
languagejava
titleKafkaProducer
+     *
+     * @deprecated Since 2.1. Use {@link #close(Duration)} or {@link #close()}.
      */
+    @Deprecated
     @Override
     public void close(long timeout, TimeUnit timeUnit) {
         close(timeout, timeUnit, false);
     }
 
+    /**
+     * This method waits up to <code>timeout</code> for the producer to complete the sending of all incomplete requests.
+     * <p>
+     * If the producer is unable to complete all requests before the timeout expires, this method will fail
+     * any unsent and unacknowledged records immediately.
+     * <p>
+     * If invoked from within a {@link Callback} this method will not block and will be equivalent to
+     * <code>close(Duration.ofMillis(0))</code>. This is done since no further sending will happen while
+     * blocking the I/O thread of the producer.
+     *
+     * @param timeout The maximum time to wait for producer to complete any pending requests. The value should be
+     *                non-negative. Specifying a timeout of zero means do not wait for pending send requests to complete.
+     * @throws InterruptException If the thread is interrupted while blocked
+     * @throws IllegalArgumentException If the <code>timeout</code> is negative.
+     */
+    @Override
+    public void close(Duration timeout) {
+        close(timeout.toMillis(), TimeUnit.MILLISECONDS, false);
+    }

...




@Override
public void close(Duration timeout)


Producer

Code Block
languagejava
titleProducer
@Deprecated
void close(long timeout, TimeUnit unit);


void close(Duration timeout);


KafkaAdminClient

Code Block
languagejava
titleKafkaAdminClient
@Override
public void close(Duration timeout)


@Deprecated
public void close(long duration, TimeUnit unit)

Noted: the implementation of close(long, TimeUnit) will be placed at AdminClient.

AdminClient

Code Block
languagejava
titleProducerAdminClient
+    @Deprecated
public   abstract  void close(long timeoutduration, TimeUnit unit);
 
+    /**
+     * @see KafkaProducer#close(Duration)
+     */
+    
public abstract void close(Duration timeout);

Noted: there is a default implementation of close(long, TimeUnit).


Proposed Changes

New Public methods are proposed. see Public Interfaces

In short, this KIP is going to deprecate close(long, TimeUnit) of KafkaProducer and KafkaAdminClient and add a replacement method - close(Duration)

Compatibility, Deprecation, and Migration Plan

No compatibility issues foreseen.

Rejected Alternatives

If there are alternative ways of accomplishing the same thing, what were they? The purpose of this section is to motivate why the design is the way it is and not some other way.

...