Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2179f0c
change to topicIdPartition
jolshan Sep 8, 2021
28acda9
Handle unknown topic IDs for full/sessionless cases.
jolshan Sep 9, 2021
8be7a96
Handling some incremental session things. Still need to handle partit…
jolshan Sep 9, 2021
79319f3
fix inconsistent topic ID handling for sessionless fetch contexts
jolshan Sep 9, 2021
9dcfa3f
finish up first draft of handling incremental partitions
jolshan Sep 10, 2021
643d7ff
Remove unnecessary error handling
jolshan Sep 16, 2021
eb8a6ed
cleanups
jolshan Sep 20, 2021
11deaa8
Merge branch 'trunk' of github.com:apache/kafka into KAFKA-13111
jolshan Sep 20, 2021
938d35e
Change equality checks based on which version we are using
jolshan Sep 21, 2021
8ea8653
Merge branch 'trunk' of github.com:apache/kafka into KAFKA-13111
jolshan Sep 28, 2021
815e8c0
try to transform fetch session handler
jolshan Sep 27, 2021
4caa2dd
Change FetchSessionHandler again to handle creating a new session rig…
jolshan Sep 28, 2021
5e7b628
Move topic ID error to partition level, remove extra topic ID map par…
jolshan Oct 6, 2021
32c6297
check version using nodeApiVersions
jolshan Oct 6, 2021
a1de391
KAFKA-13111; FetchSessionHandler WIP
dajac Oct 12, 2021
2708655
more refactor
dajac Oct 13, 2021
4cdc41c
Merge remote-tracking branch 'dajac/KAFKA-13111' into KAFKA-13111-test
jolshan Oct 22, 2021
83a91e6
Merge branch 'trunk' of github.com:apache/kafka into KAFKA-13111
jolshan Oct 22, 2021
50c9db6
Merge branch 'KAFKA-13111' of github.com:jolshan/kafka into KAFKA-13111
jolshan Oct 22, 2021
9f349f2
remove inconsistent topic ID from top level, put toForget after fetch…
jolshan Oct 26, 2021
c0a278f
Add some testing for edge cases
jolshan Oct 28, 2021
fbbf522
Respond to review comments
jolshan Nov 4, 2021
ea75200
Respond to comments on tests
jolshan Nov 5, 2021
9174fdb
FetchRequestTests, CachedPartition, FetchSessionHandler, and other cl…
jolshan Nov 8, 2021
43d69a1
PartitionData should take into account topicId in both equals and has…
dajac Nov 8, 2021
594b549
Add more tests to FetcherTest; Update logic in FetchSessionHandler; F…
dajac Nov 8, 2021
321ea1d
Fix tests, remove outdated error comments from FetchRequest/Response
jolshan Nov 8, 2021
f84b6f9
Add tests for AbstractFetcherThread and ReplicaFetcherThread
jolshan Nov 9, 2021
63bc476
Add testResolveUnknownPartitions test
dajac Nov 9, 2021
1a5fa71
More cleanups and test fixes
jolshan Nov 10, 2021
165a106
Merge branch 'trunk' of github.com:apache/kafka into KAFKA-13111
jolshan Nov 10, 2021
f8b1d14
Small fix in testResolveUnknownPartitions
dajac Nov 10, 2021
09fad0a
Further test fixes
jolshan Nov 10, 2021
eab5380
prepare for topicIdPartition refactor
jolshan Nov 11, 2021
5048d03
Merge branch 'trunk' of github.com:apache/kafka into KAFKA-13111
jolshan Nov 11, 2021
ae81d04
fix build
jolshan Nov 11, 2021
d458fd1
fix build
dajac Nov 11, 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
2 changes: 1 addition & 1 deletion checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
files="(Utils|Topic|KafkaLZ4BlockOutputStream|AclData|JoinGroupRequest).java"/>

<suppress checks="CyclomaticComplexity"
files="(ConsumerCoordinator|Fetcher|KafkaProducer|ConfigDef|KerberosLogin|AbstractRequest|AbstractResponse|Selector|SslFactory|SslTransportLayer|SaslClientAuthenticator|SaslClientCallbackHandler|SaslServerAuthenticator|AbstractCoordinator|TransactionManager|AbstractStickyAssignor|DefaultSslEngineFactory|Authorizer|RecordAccumulator|MemoryRecords).java"/>
files="(ConsumerCoordinator|Fetcher|KafkaProducer|ConfigDef|KerberosLogin|AbstractRequest|AbstractResponse|Selector|SslFactory|SslTransportLayer|SaslClientAuthenticator|SaslClientCallbackHandler|SaslServerAuthenticator|AbstractCoordinator|TransactionManager|AbstractStickyAssignor|DefaultSslEngineFactory|Authorizer|RecordAccumulator|MemoryRecords|FetchSessionHandler).java"/>

<suppress checks="JavaNCSS"
files="(AbstractRequest|AbstractResponse|KerberosLogin|WorkerSinkTaskTest|TransactionManagerTest|SenderTest|KafkaAdminClient|ConsumerCoordinatorTest|KafkaAdminClientTest|KafkaRaftClientTest).java"/>
Expand Down
280 changes: 119 additions & 161 deletions clients/src/main/java/org/apache/kafka/clients/FetchSessionHandler.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.kafka.common.Node;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.TopicIdPartition;
import org.apache.kafka.common.Uuid;
import org.apache.kafka.common.errors.CorruptRecordException;
import org.apache.kafka.common.errors.InvalidTopicException;
Expand Down Expand Up @@ -110,6 +111,7 @@
import java.util.stream.Collectors;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;

/**
* This class manages the fetching process with the brokers.
Expand Down Expand Up @@ -262,7 +264,7 @@ public synchronized int sendFetches() {
maxVersion = ApiKeys.FETCH.latestVersion();
}
final FetchRequest.Builder request = FetchRequest.Builder
.forConsumer(maxVersion, this.maxWaitMs, this.minBytes, data.toSend(), data.topicIds())
.forConsumer(maxVersion, this.maxWaitMs, this.minBytes, data.toSend())
.isolationLevel(isolationLevel)
.setMaxBytes(this.maxBytes)
.metadata(data.metadata())
Expand Down Expand Up @@ -292,19 +294,18 @@ public void onSuccess(ClientResponse resp) {
}
if (!handler.handleResponse(response, resp.requestHeader().apiVersion())) {
if (response.error() == Errors.FETCH_SESSION_TOPIC_ID_ERROR
|| response.error() == Errors.UNKNOWN_TOPIC_ID
|| response.error() == Errors.INCONSISTENT_TOPIC_ID) {
metadata.requestUpdate();
}
return;
}

Map<TopicPartition, FetchResponseData.PartitionData> responseData = response.responseData(data.topicNames(), resp.requestHeader().apiVersion());
Set<TopicPartition> partitions = new HashSet<>(responseData.keySet());
Map<TopicIdPartition, FetchResponseData.PartitionData> responseData = response.responseData(handler.sessionTopicNames(), resp.requestHeader().apiVersion());
Set<TopicPartition> partitions = new HashSet<>(responseData.keySet().stream().map(TopicIdPartition::topicPartition).collect(Collectors.toSet()));
FetchResponseMetricAggregator metricAggregator = new FetchResponseMetricAggregator(sensors, partitions);

for (Map.Entry<TopicPartition, FetchResponseData.PartitionData> entry : responseData.entrySet()) {
TopicPartition partition = entry.getKey();
for (Map.Entry<TopicIdPartition, FetchResponseData.PartitionData> entry : responseData.entrySet()) {
TopicIdPartition partition = entry.getKey();
FetchRequest.PartitionData requestData = data.sessionPartitions().get(partition);
if (requestData == null) {
String message;
Expand All @@ -330,7 +331,7 @@ public void onSuccess(ClientResponse resp) {
Iterator<? extends RecordBatch> batches = FetchResponse.recordsOrFail(partitionData).batches().iterator();
short responseVersion = resp.requestHeader().apiVersion();

completedFetches.add(new CompletedFetch(partition, partitionData,
completedFetches.add(new CompletedFetch(partition.topicPartition(), partitionData,
metricAggregator, batches, fetchOffset, responseVersion));
}
}
Expand Down Expand Up @@ -824,6 +825,14 @@ static boolean hasUsableOffsetForLeaderEpochVersion(NodeApiVersions nodeApiVersi
return OffsetsForLeaderEpochRequest.supportsTopicPermission(apiVersion.maxVersion());
}

static boolean hasUsableTopicIdFetchRequestVersion(NodeApiVersions nodeApiVersions) {
Comment thread
jolshan marked this conversation as resolved.
Outdated
ApiVersion apiVersion = nodeApiVersions.apiVersion(ApiKeys.FETCH);
if (apiVersion == null)
return false;

return apiVersion.maxVersion() >= 13;
}

/**
* For each partition which needs validation, make an asynchronous request to get the end-offsets for the partition
* with the epoch less than or equal to the epoch the partition last saw.
Expand Down Expand Up @@ -1239,7 +1248,15 @@ private Map<Node, FetchSessionHandler.FetchRequestData> prepareFetchRequests() {
fetchable.put(node, builder);
}

builder.add(partition, topicIds.getOrDefault(partition.topic(), Uuid.ZERO_UUID), new FetchRequest.PartitionData(position.offset,
// One option is to store this in the builder and only check on the creation of the builder
NodeApiVersions nodeApiVersions = apiVersions.get(node.idString());
if (nodeApiVersions == null) {
client.tryConnect(node);
return emptyMap();
}
Uuid topicId = hasUsableTopicIdFetchRequestVersion(nodeApiVersions) ? topicIds.getOrDefault(partition.topic(), Uuid.ZERO_UUID) : Uuid.ZERO_UUID;

builder.add(new TopicIdPartition(topicId, partition), new FetchRequest.PartitionData(position.offset,
FetchRequest.INVALID_LOG_START_OFFSET, this.fetchSize,
position.currentLeader.epoch, Optional.empty()));

Expand Down Expand Up @@ -1353,6 +1370,9 @@ private CompletedFetch initializeCompletedFetch(CompletedFetch nextCompletedFetc
} else if (error == Errors.UNKNOWN_TOPIC_OR_PARTITION) {
log.warn("Received unknown topic or partition error in fetch for partition {}", tp);
this.metadata.requestUpdate();
} else if (error == Errors.UNKNOWN_TOPIC_ID) {
log.warn("Received unknown topic ID error in fetch for partition {}", tp);
this.metadata.requestUpdate();
} else if (error == Errors.OFFSET_OUT_OF_RANGE) {
Optional<Integer> clearedReplicaId = subscriptions.clearPreferredReadReplica(tp);
if (!clearedReplicaId.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ public FetchMetadata nextCloseExisting() {
return new FetchMetadata(sessionId, INITIAL_EPOCH);
}

/**
* Return the metadata for the next closed session response.
*/
public FetchMetadata closeExisting() {
Comment thread
jolshan marked this conversation as resolved.
Outdated
return new FetchMetadata(sessionId, FINAL_EPOCH);
}

/**
* Return the metadata for the next full fetch request.
*/
Expand Down
Loading