Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d9bab79
MINOR: remove unneccessary public keyword from ProducerInterceptor in…
May 23, 2021
efb7cda
MINOR: update java doc for deprecated methods (#10722)
showuon May 24, 2021
c92e62a
MINOR: Add log identifier/prefix printing in Log layer static functio…
kowshik May 24, 2021
33df5c6
MINOR: clarify message ordering with max in-flight requests and idemp…
ableegoldman May 24, 2021
39f4e0c
MINOR: remove unneccessary public keyword from ConsumerInterceptor in…
May 25, 2021
63b6db3
KAFKA-12800: Configure generator to fail on trailing JSON tokens (#10…
cursedquail May 25, 2021
77573d8
MINOR: add window verification to sliding-window co-group test (#10745)
mjsax May 26, 2021
e4f2f6f
KAFKA-12260: Avoid hitting NPE for partitionsFor (#10017)
May 26, 2021
38e8391
MINOR: Log more information when producer snapshot is written (#10757)
dajac May 26, 2021
bbe170a
MINOR: deprecate TaskMetadata constructor and add KIP-740 notes to up…
ableegoldman May 26, 2021
47094ef
MINOR: Log constructor: Flip logical NOT for readability (#10756)
kowshik May 26, 2021
db288e4
Update implementation.html (#10771)
prince-mahajan May 27, 2021
56d9482
KAFKA-12819: Add assert messages to MirrorMaker tests plus other qual…
mdedetrich May 27, 2021
a02b19c
KAFKA-12796: Removal of deprecated classes under streams-scala (#10710)
jlprat May 27, 2021
e4b3a3c
MINOR: Adjust parameter ordering of `waitForCondition` and `retryOnEx…
ijuma May 27, 2021
3fb836f
MINOR: Improve Log layer segment iteration logic and few other areas …
kowshik May 27, 2021
2313026
KAFKA-12856: Upgrade Jackson to 2.12.3 (#10778)
ijuma May 27, 2021
6659777
MINOR: Don't ignore deletion of partition metadata file and log topic…
ijuma May 27, 2021
5cbe6a7
KAFKA-12791: ConcurrentModificationException in AbstractConfig use by…
lbradstreet May 27, 2021
a6f3094
MINOR: make sure all fiedls of o.p.k.s.a.Action are NOT null (#10764)
chia7712 May 28, 2021
588ea44
KAFKA-12782: Fix Javadocs generation by upgrading JDK (#10780)
jlprat May 28, 2021
f207bac
KAFKA-8410: KTableProcessor migration groundwork (#10744)
vvcephei May 28, 2021
0bf4b47
MINOR: upgrade pip from 20.2.2 to 21.1.1 (#10661)
chia7712 May 29, 2021
99a0312
KAFKA-12865 : Fix doc error in Admin.describeAcls API (#10790)
rohit-sachan May 29, 2021
6b005b2
MINOR: Reduce allocations in requests via buffer caching (#9229)
ijuma May 30, 2021
6c9e27c
HOTFIX: fix build error (#10796)
chia7712 May 31, 2021
ee88bf6
MINOR: remove unneccessary public keyword from ProducerInterceptor in…
May 23, 2021
dcc83c2
MINOR: remove unneccessary public keyword from ConsumerInterceptor in…
May 25, 2021
5e6f627
Merge remote-tracking branch 'origin/trunk' into trunk
May 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ default DescribeClusterResult describeCluster() {
* This operation is supported by brokers with version 0.11.0.0 or higher.
*
* @param filter The filter to use.
* @return The DeleteAclsResult.
* @return The DescribeAclsResult.
*/
default DescribeAclsResult describeAcls(AclBindingFilter filter) {
return describeAcls(filter, new DescribeAclsOptions());
Expand All @@ -354,7 +354,7 @@ default DescribeAclsResult describeAcls(AclBindingFilter filter) {
*
* @param filter The filter to use.
* @param options The options to use when listing the ACLs.
* @return The DeleteAclsResult.
* @return The DescribeAclsResult.
*/
DescribeAclsResult describeAcls(AclBindingFilter filter, DescribeAclsOptions options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface ConsumerInterceptor<K, V> extends Configurable, AutoCloseable {
* @param records records to be consumed by the client or records returned by the previous interceptors in the list.
* @return records that are either modified by the interceptor or same as records passed to this method.
*/
public ConsumerRecords<K, V> onConsume(ConsumerRecords<K, V> records);
ConsumerRecords<K, V> onConsume(ConsumerRecords<K, V> records);

/**
* This is called when offsets get committed.
Expand All @@ -74,10 +74,10 @@ public interface ConsumerInterceptor<K, V> extends Configurable, AutoCloseable {
*
* @param offsets A map of offsets by partition with associated metadata
*/
public void onCommit(Map<TopicPartition, OffsetAndMetadata> offsets);
void onCommit(Map<TopicPartition, OffsetAndMetadata> offsets);

/**
* This is called when interceptor is closed
*/
public void close();
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ public Map<TopicPartition, OffsetAndMetadata> committed(final Set<TopicPartition
*
* @param topic The topic to get partition metadata for
*
* @return The list of partitions
* @return The list of partitions, which will be empty when the given topic is not found
* @throws org.apache.kafka.common.errors.WakeupException if {@link #wakeup()} is called before or while this
* function is called
* @throws org.apache.kafka.common.errors.InterruptException if the calling thread is interrupted before or while
Expand All @@ -1924,7 +1924,7 @@ public List<PartitionInfo> partitionsFor(String topic) {
* @param topic The topic to get partition metadata for
* @param timeout The maximum of time to await topic metadata
*
* @return The list of partitions
* @return The list of partitions, which will be empty when the given topic is not found
* @throws org.apache.kafka.common.errors.WakeupException if {@link #wakeup()} is called before or while this
* function is called
* @throws org.apache.kafka.common.errors.InterruptException if the calling thread is interrupted before or while
Expand All @@ -1948,7 +1948,7 @@ public List<PartitionInfo> partitionsFor(String topic, Duration timeout) {
Timer timer = time.timer(timeout);
Map<String, List<PartitionInfo>> topicMetadata = fetcher.getTopicMetadata(
new MetadataRequest.Builder(Collections.singletonList(topic), metadata.allowAutoTopicCreation()), timer);
return topicMetadata.get(topic);
return topicMetadata.getOrDefault(topic, Collections.emptyList());
} finally {
release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public synchronized void updateEndOffsets(final Map<TopicPartition, Long> newOff
@Override
public synchronized List<PartitionInfo> partitionsFor(String topic) {
ensureNotClosed();
return this.partitions.get(topic);
return this.partitions.getOrDefault(topic, Collections.emptyList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ public class ProducerConfig extends AbstractConfig {
/** <code>max.in.flight.requests.per.connection</code> */
public static final String MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION = "max.in.flight.requests.per.connection";
private static final String MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION_DOC = "The maximum number of unacknowledged requests the client will send on a single connection before blocking."
+ " Note that if this setting is set to be greater than 1 and there are failed sends, there is a risk of"
+ " message re-ordering due to retries (i.e., if retries are enabled).";
+ " Note that if this config is set to be greater than 1 and <code>enable.idempotence</code> is set to false, there is a risk of"
+ " message re-ordering after a failed send due to retries (i.e., if retries are enabled).";

/** <code>retries</code> */
public static final String RETRIES_CONFIG = CommonClientConfigs.RETRIES_CONFIG;
Expand Down Expand Up @@ -246,10 +246,10 @@ public class ProducerConfig extends AbstractConfig {
public static final String ENABLE_IDEMPOTENCE_CONFIG = "enable.idempotence";
public static final String ENABLE_IDEMPOTENCE_DOC = "When set to 'true', the producer will ensure that exactly one copy of each message is written in the stream. If 'false', producer "
+ "retries due to broker failures, etc., may write duplicates of the retried message in the stream. "
+ "Note that enabling idempotence requires <code>" + MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION + "</code> to be less than or equal to 5, "
+ "<code>" + RETRIES_CONFIG + "</code> to be greater than 0 and <code>" + ACKS_CONFIG + "</code> must be 'all'. If these values "
+ "are not explicitly set by the user, suitable values will be chosen. If incompatible values are set, "
+ "a <code>ConfigException</code> will be thrown.";
+ "Note that enabling idempotence requires <code>" + MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION + "</code> to be less than or equal to 5 "
+ "(with message ordering preserved for any allowable value), <code>" + RETRIES_CONFIG + "</code> to be greater than 0, and <code>"
+ ACKS_CONFIG + "</code> must be 'all'. If these values are not explicitly set by the user, suitable values will be chosen. If incompatible "
+ "values are set, a <code>ConfigException</code> will be thrown.";

/** <code> transaction.timeout.ms </code> */
public static final String TRANSACTION_TIMEOUT_CONFIG = "transaction.timeout.ms";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface ProducerInterceptor<K, V> extends Configurable {
* @param record the record from client or the record returned by the previous interceptor in the chain of interceptors.
* @return producer record to send to topic/partition
*/
public ProducerRecord<K, V> onSend(ProducerRecord<K, V> record);
ProducerRecord<K, V> onSend(ProducerRecord<K, V> record);

/**
* This method is called when the record sent to the server has been acknowledged, or when sending the record fails before
Expand All @@ -86,10 +86,10 @@ public interface ProducerInterceptor<K, V> extends Configurable {
* {@link org.apache.kafka.clients.producer.KafkaProducer#send(ProducerRecord)}.
* @param exception The exception thrown during processing of this record. Null if no error occurred.
*/
public void onAcknowledgement(RecordMetadata metadata, Exception exception);
void onAcknowledgement(RecordMetadata metadata, Exception exception);

/**
* This is called when interceptor is closed
*/
public void close();
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.kafka.common.compress;

import com.github.luben.zstd.BufferPool;
import com.github.luben.zstd.RecyclingBufferPool;
import com.github.luben.zstd.ZstdInputStreamNoFinalizer;
import com.github.luben.zstd.ZstdOutputStreamNoFinalizer;
Expand Down Expand Up @@ -47,10 +48,24 @@ public static OutputStream wrapForOutput(ByteBufferOutputStream buffer) {

public static InputStream wrapForInput(ByteBuffer buffer, byte messageVersion, BufferSupplier decompressionBufferSupplier) {
try {
// We use our own BufferSupplier instead of com.github.luben.zstd.RecyclingBufferPool since our
// implementation doesn't require locking or soft references.
BufferPool bufferPool = new BufferPool() {
@Override
public ByteBuffer get(int capacity) {
return decompressionBufferSupplier.get(capacity);
}

@Override
public void release(ByteBuffer buffer) {
decompressionBufferSupplier.release(buffer);
}
};

// Set output buffer (uncompressed) to 16 KB (none by default) to ensure reasonable performance
// in cases where the caller reads a small number of bytes (potentially a single byte).
return new BufferedInputStream(new ZstdInputStreamNoFinalizer(new ByteBufferInputStream(buffer),
RecyclingBufferPool.INSTANCE), 16 * 1024);
bufferPool), 16 * 1024);
} catch (Throwable e) {
throw new KafkaException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;

/**
* A convenient base class for configurations to extend.
Expand All @@ -42,8 +43,12 @@ public class AbstractConfig {

private final Logger log = LoggerFactory.getLogger(getClass());

/* configs for which values have been requested, used to detect unused configs */
private final Set<String> used;
/**
* Configs for which values have been requested, used to detect unused configs.
* This set must be concurrent modifiable and iterable. It will be modified
* when directly accessed or as a result of RecordingMap access.
*/
private final Set<String> used = ConcurrentHashMap.newKeySet();

/* the original values passed in by the user */
private final Map<String, ?> originals;
Expand Down Expand Up @@ -106,7 +111,6 @@ public AbstractConfig(ConfigDef definition, Map<?, ?> originals, Map<String, ?>

this.originals = resolveConfigVariables(configProviderProps, (Map<String, Object>) originals);
this.values = definition.parse(this.originals);
this.used = Collections.synchronizedSet(new HashSet<>());
Map<String, Object> configUpdates = postProcessParsedConfig(Collections.unmodifiableMap(this.values));
for (Map.Entry<String, Object> update : configUpdates.entrySet()) {
this.values.put(update.getKey(), update.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,32 @@ public class Action {
private final boolean logIfAllowed;
private final boolean logIfDenied;

/**
* @param operation non-null operation being performed
* @param resourcePattern non-null resource pattern on which this action is being performed
*/
public Action(AclOperation operation,
ResourcePattern resourcePattern,
int resourceReferenceCount,
boolean logIfAllowed,
boolean logIfDenied) {
this.operation = operation;
this.resourcePattern = resourcePattern;
this.operation = Objects.requireNonNull(operation, "operation can't be null");
this.resourcePattern = Objects.requireNonNull(resourcePattern, "resourcePattern can't be null");
this.logIfAllowed = logIfAllowed;
this.logIfDenied = logIfDenied;
this.resourceReferenceCount = resourceReferenceCount;
}

/**
* Resource on which action is being performed.
* @return a non-null resource pattern on which this action is being performed
*/
public ResourcePattern resourcePattern() {
return resourcePattern;
}

/**
* Operation being performed.
*
* @return a non-null operation being performed
*/
public AclOperation operation() {
return operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5773,7 +5773,7 @@ public void testClientSideTimeoutAfterFailureToReceiveResponse() throws Exceptio
TestUtils.waitForCondition(() -> {
time.sleep(1);
return disconnectFuture.isDone();
}, 1, 5000, () -> "Timed out waiting for expected disconnect");
}, 5000, 1, () -> "Timed out waiting for expected disconnect");
assertFalse(disconnectFuture.isCompletedExceptionally());
assertFalse(result.future.isDone());
TestUtils.waitForCondition(env.kafkaClient()::hasInFlightRequests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,28 @@ private void consumerCloseTest(final long closeTimeoutMs,
}
}

@Test
public void testPartitionsForNonExistingTopic() {
Time time = new MockTime();
SubscriptionState subscription = new SubscriptionState(new LogContext(), OffsetResetStrategy.EARLIEST);
ConsumerMetadata metadata = createMetadata(subscription);
MockClient client = new MockClient(time, metadata);

initMetadata(client, Collections.singletonMap(topic, 1));
Cluster cluster = metadata.fetch();

MetadataResponse updateResponse = RequestTestUtils.metadataResponse(cluster.nodes(),
cluster.clusterResource().clusterId(),
cluster.controller().id(),
Collections.emptyList());
client.prepareResponse(updateResponse);

ConsumerPartitionAssignor assignor = new RoundRobinAssignor();

KafkaConsumer<String, String> consumer = newConsumer(time, client, subscription, metadata, assignor, true, groupInstanceId);
assertEquals(Collections.emptyList(), consumer.partitionsFor("non-exist-topic"));
}

@Test
public void testPartitionsForAuthenticationFailure() {
final KafkaConsumer<String, String> consumer = consumerWithPendingAuthenticationError();
Expand Down
16 changes: 8 additions & 8 deletions clients/src/test/java/org/apache/kafka/test/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public static void waitForCondition(final TestCondition testCondition, final lon
* avoid transient failures due to slow or overloaded machines.
*/
public static void waitForCondition(final TestCondition testCondition, final long maxWaitMs, Supplier<String> conditionDetailsSupplier) throws InterruptedException {
waitForCondition(testCondition, DEFAULT_POLL_INTERVAL_MS, maxWaitMs, conditionDetailsSupplier);
waitForCondition(testCondition, maxWaitMs, DEFAULT_POLL_INTERVAL_MS, conditionDetailsSupplier);
}

/**
Expand All @@ -310,11 +310,11 @@ public static void waitForCondition(final TestCondition testCondition, final lon
*/
public static void waitForCondition(
final TestCondition testCondition,
final long pollIntervalMs,
final long maxWaitMs,
final long pollIntervalMs,
Supplier<String> conditionDetailsSupplier
) throws InterruptedException {
retryOnExceptionWithTimeout(pollIntervalMs, maxWaitMs, () -> {
retryOnExceptionWithTimeout(maxWaitMs, pollIntervalMs, () -> {
String conditionDetailsSupplied = conditionDetailsSupplier != null ? conditionDetailsSupplier.get() : null;
String conditionDetails = conditionDetailsSupplied != null ? conditionDetailsSupplied : "";
assertTrue(testCondition.conditionMet(),
Expand All @@ -333,7 +333,7 @@ public static void waitForCondition(
*/
public static void retryOnExceptionWithTimeout(final long timeoutMs,
final ValuelessCallable runnable) throws InterruptedException {
retryOnExceptionWithTimeout(DEFAULT_POLL_INTERVAL_MS, timeoutMs, runnable);
retryOnExceptionWithTimeout(timeoutMs, DEFAULT_POLL_INTERVAL_MS, runnable);
}

/**
Expand All @@ -345,21 +345,21 @@ public static void retryOnExceptionWithTimeout(final long timeoutMs,
* @throws InterruptedException if the current thread is interrupted while waiting for {@code runnable} to complete successfully.
*/
public static void retryOnExceptionWithTimeout(final ValuelessCallable runnable) throws InterruptedException {
retryOnExceptionWithTimeout(DEFAULT_POLL_INTERVAL_MS, DEFAULT_MAX_WAIT_MS, runnable);
retryOnExceptionWithTimeout(DEFAULT_MAX_WAIT_MS, DEFAULT_POLL_INTERVAL_MS, runnable);
}

/**
* Wait for the given runnable to complete successfully, i.e. throw now {@link Exception}s or
* {@link AssertionError}s, or for the given timeout to expire. If the timeout expires then the
* last exception or assertion failure will be thrown thus providing context for the failure.
*
* @param pollIntervalMs the interval in milliseconds to wait between invoking {@code runnable}.
* @param timeoutMs the total time in milliseconds to wait for {@code runnable} to complete successfully.
* @param pollIntervalMs the interval in milliseconds to wait between invoking {@code runnable}.
* @param runnable the code to attempt to execute successfully.
* @throws InterruptedException if the current thread is interrupted while waiting for {@code runnable} to complete successfully.
*/
public static void retryOnExceptionWithTimeout(final long pollIntervalMs,
final long timeoutMs,
public static void retryOnExceptionWithTimeout(final long timeoutMs,
final long pollIntervalMs,
final ValuelessCallable runnable) throws InterruptedException {
final long expectedEnd = System.currentTimeMillis() + timeoutMs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ public void testSerde() {
byte[] value = checkpoint.recordValue();
ConsumerRecord<byte[], byte[]> record = new ConsumerRecord<>("any-topic", 7, 8, key, value);
Checkpoint deserialized = Checkpoint.deserializeRecord(record);
assertEquals(checkpoint.consumerGroupId(), deserialized.consumerGroupId());
assertEquals(checkpoint.topicPartition(), deserialized.topicPartition());
assertEquals(checkpoint.upstreamOffset(), deserialized.upstreamOffset());
assertEquals(checkpoint.downstreamOffset(), deserialized.downstreamOffset());
assertEquals(checkpoint.consumerGroupId(), deserialized.consumerGroupId(),
"Failure on checkpoint consumerGroupId serde");
assertEquals(checkpoint.topicPartition(), deserialized.topicPartition(),
"Failure on checkpoint topicPartition serde");
assertEquals(checkpoint.upstreamOffset(), deserialized.upstreamOffset(),
"Failure on checkpoint upstreamOffset serde");
assertEquals(checkpoint.downstreamOffset(), deserialized.downstreamOffset(),
"Failure on checkpoint downstreamOffset serde");
}
}
Loading