Skip to content
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b3e592f
MINOR: remove FetchResponse.AbortedTransaction and duplicate construc…
chia7712 Dec 29, 2020
f217bb5
remove unnecessary changes and remove partitionData
chia7712 Jan 4, 2021
3f219e5
remove PartitionData
chia7712 Jan 5, 2021
83a26f0
add isDivergingEpoch and isPreferredReplica
chia7712 Jan 6, 2021
7c386a0
remove unused import
chia7712 Jan 13, 2021
c010e4e
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 14, 2021
30695f8
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 15, 2021
9122aee
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 16, 2021
4106d2f
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 18, 2021
d97de8a
fix checkstyle
chia7712 Jan 18, 2021
13f7710
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 18, 2021
52ab156
tweak style
chia7712 Jan 18, 2021
cb157fe
rename dataByTopicPartition to responseData
chia7712 Jan 18, 2021
9627cd9
rename recordSet to records
chia7712 Jan 18, 2021
e15ee0c
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 19, 2021
868ff0c
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 19, 2021
ef45f01
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 21, 2021
bc5c494
Merge branch 'trunk' into MINOR-9758
chia7712 Jan 27, 2021
ce991c3
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 1, 2021
4a83601
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 2, 2021
3b55cd7
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 12, 2021
cd1c981
fix build
chia7712 Feb 12, 2021
fbca049
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 17, 2021
4077553
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 18, 2021
d513d85
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 20, 2021
9e17a7e
fix build error
chia7712 Feb 20, 2021
568d8f5
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 23, 2021
eddfffd
rename FetchablePartitionResponse to PartitionData; add helper method…
chia7712 Feb 23, 2021
9b76376
rename index to partitionIndex
chia7712 Feb 23, 2021
7d5a5a3
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 25, 2021
a4edde3
fix broken build
chia7712 Feb 25, 2021
b929215
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 26, 2021
e6e1478
Merge branch 'trunk' into MINOR-9758
chia7712 Feb 27, 2021
ff57d4e
make FetchResponse thread-safe
chia7712 Feb 27, 2021
0e9e847
remove duplicate assignments; batch data; add more comments
chia7712 Feb 28, 2021
033b933
Merge branch 'trunk' into MINOR-9758
chia7712 Mar 1, 2021
8263bda
Merge branch 'trunk' into MINOR-9758
chia7712 Mar 2, 2021
529d81d
remove redundant code; add more comment for casting; use helper metho…
chia7712 Mar 2, 2021
9f8e97b
Merge branch 'trunk' into MINOR-9758
chia7712 Mar 2, 2021
4fa69c5
fix build error
chia7712 Mar 2, 2021
55b35ab
set partition index; add recordsSize;
chia7712 Mar 2, 2021
821c307
Merge branch 'trunk' into MINOR-9758
chia7712 Mar 4, 2021
ae25551
revert sizeOf
chia7712 Mar 4, 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 @@ -318,7 +318,7 @@ static Set<TopicPartition> findMissing(Set<TopicPartition> toFind, Set<TopicPart
* @param response The response.
* @return True if the full fetch response partitions are valid.
*/
String verifyFullFetchResponsePartitions(FetchResponse<?> response) {
String verifyFullFetchResponsePartitions(FetchResponse response) {
StringBuilder bld = new StringBuilder();
Set<TopicPartition> extra =
findMissing(response.responseData().keySet(), sessionPartitions.keySet());
Expand All @@ -343,7 +343,7 @@ String verifyFullFetchResponsePartitions(FetchResponse<?> response) {
* @param response The response.
* @return True if the incremental fetch response partitions are valid.
*/
String verifyIncrementalFetchResponsePartitions(FetchResponse<?> response) {
String verifyIncrementalFetchResponsePartitions(FetchResponse response) {
Set<TopicPartition> extra =
findMissing(response.responseData().keySet(), sessionPartitions.keySet());
if (!extra.isEmpty()) {
Expand All @@ -362,7 +362,7 @@ String verifyIncrementalFetchResponsePartitions(FetchResponse<?> response) {
* @param response The FetchResponse.
* @return The string to log.
*/
private String responseDataToLogString(FetchResponse<?> response) {
private String responseDataToLogString(FetchResponse response) {
if (!log.isTraceEnabled()) {
int implied = sessionPartitions.size() - response.responseData().size();
if (implied > 0) {
Expand Down Expand Up @@ -398,7 +398,7 @@ private String responseDataToLogString(FetchResponse<?> response) {
* @return True if the response is well-formed; false if it can't be processed
* because of missing or unexpected partitions.
*/
public boolean handleResponse(FetchResponse<?> response) {
public boolean handleResponse(FetchResponse response) {
if (response.error() != Errors.NONE) {
log.info("Node {} was unable to process the fetch request with {}: {}.",
node, nextMetadata, response.error());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.kafka.common.errors.TopicAuthorizationException;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeaders;
import org.apache.kafka.common.message.FetchResponseData;
import org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion;
import org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition;
import org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse;
Expand All @@ -66,7 +67,6 @@
import org.apache.kafka.common.record.ControlRecordType;
import org.apache.kafka.common.record.Record;
import org.apache.kafka.common.record.RecordBatch;
import org.apache.kafka.common.record.Records;
import org.apache.kafka.common.record.TimestampType;
import org.apache.kafka.common.requests.FetchRequest;
import org.apache.kafka.common.requests.FetchResponse;
Expand Down Expand Up @@ -276,7 +276,7 @@ public void onSuccess(ClientResponse resp) {
synchronized (Fetcher.this) {
try {
@SuppressWarnings("unchecked")
FetchResponse<Records> response = (FetchResponse<Records>) resp.responseBody();
FetchResponse response = (FetchResponse) resp.responseBody();
FetchSessionHandler handler = sessionHandler(fetchTarget.id());
if (handler == null) {
log.error("Unable to find FetchSessionHandler for node {}. Ignoring fetch response.",
Expand All @@ -290,7 +290,7 @@ public void onSuccess(ClientResponse resp) {
Set<TopicPartition> partitions = new HashSet<>(response.responseData().keySet());
FetchResponseMetricAggregator metricAggregator = new FetchResponseMetricAggregator(sensors, partitions);

for (Map.Entry<TopicPartition, FetchResponse.PartitionData<Records>> entry : response.responseData().entrySet()) {
for (Map.Entry<TopicPartition, FetchResponseData.PartitionData> entry : response.responseData().entrySet()) {
TopicPartition partition = entry.getKey();
FetchRequest.PartitionData requestData = data.sessionPartitions().get(partition);
if (requestData == null) {
Expand All @@ -309,12 +309,12 @@ public void onSuccess(ClientResponse resp) {
throw new IllegalStateException(message);
} else {
long fetchOffset = requestData.fetchOffset;
FetchResponse.PartitionData<Records> partitionData = entry.getValue();
FetchResponseData.PartitionData partitionData = entry.getValue();

log.debug("Fetch {} at offset {} for partition {} returned fetch data {}",
isolationLevel, fetchOffset, partition, partitionData);

Iterator<? extends RecordBatch> batches = partitionData.records().batches().iterator();
Iterator<? extends RecordBatch> batches = FetchResponse.records(partitionData).batches().iterator();
short responseVersion = resp.requestHeader().apiVersion();

completedFetches.add(new CompletedFetch(partition, partitionData,
Expand Down Expand Up @@ -617,7 +617,7 @@ public FetchedRecords<K, V> fetchedRecords() {
// The first condition ensures that the completedFetches is not stuck with the same completedFetch
// in cases such as the TopicAuthorizationException, and the second condition ensures that no
// potential data loss due to an exception in a following record.
FetchResponse.PartitionData<Records> partition = records.partitionData;
FetchResponseData.PartitionData partition = records.partitionData;
if (fetched.isEmpty() && (partition.records() == null || partition.records().sizeInBytes() == 0)) {
completedFetches.poll();
}
Expand Down Expand Up @@ -1236,10 +1236,10 @@ private <T> Map<Node, Map<TopicPartition, T>> regroupPartitionMapByNode(Map<Topi
*/
private CompletedFetch initializeCompletedFetch(CompletedFetch nextCompletedFetch) {
TopicPartition tp = nextCompletedFetch.partition;
FetchResponse.PartitionData<Records> partition = nextCompletedFetch.partitionData;
FetchResponseData.PartitionData partition = nextCompletedFetch.partitionData;
long fetchOffset = nextCompletedFetch.nextFetchOffset;
CompletedFetch completedFetch = null;
Errors error = partition.error();
Errors error = Errors.forCode(partition.errorCode());

try {
if (!subscriptions.hasValidPosition(tp)) {
Expand All @@ -1257,7 +1257,7 @@ private CompletedFetch initializeCompletedFetch(CompletedFetch nextCompletedFetc

log.trace("Preparing to read {} bytes of data for partition {} with offset {}",
partition.records().sizeInBytes(), tp, position);
Iterator<? extends RecordBatch> batches = partition.records().batches().iterator();
Iterator<? extends RecordBatch> batches = FetchResponse.records(partition).batches().iterator();
completedFetch = nextCompletedFetch;

if (!batches.hasNext() && partition.records().sizeInBytes() > 0) {
Expand Down Expand Up @@ -1293,11 +1293,11 @@ private CompletedFetch initializeCompletedFetch(CompletedFetch nextCompletedFetc
subscriptions.updateLastStableOffset(tp, partition.lastStableOffset());
}

if (partition.preferredReadReplica().isPresent()) {
subscriptions.updatePreferredReadReplica(completedFetch.partition, partition.preferredReadReplica().get(), () -> {
if (FetchResponse.isPreferredReplica(partition)) {
subscriptions.updatePreferredReadReplica(completedFetch.partition, partition.preferredReadReplica(), () -> {
long expireTimeMs = time.milliseconds() + metadata.metadataExpireMs();
log.debug("Updating preferred read replica for partition {} to {}, set to expire at {}",
tp, partition.preferredReadReplica().get(), expireTimeMs);
tp, partition.preferredReadReplica(), expireTimeMs);
return expireTimeMs;
});
}
Expand Down Expand Up @@ -1462,8 +1462,8 @@ private class CompletedFetch {
private final TopicPartition partition;
private final Iterator<? extends RecordBatch> batches;
private final Set<Long> abortedProducerIds;
private final PriorityQueue<FetchResponse.AbortedTransaction> abortedTransactions;
private final FetchResponse.PartitionData<Records> partitionData;
private final PriorityQueue<FetchResponseData.AbortedTransaction> abortedTransactions;
private final FetchResponseData.PartitionData partitionData;
private final FetchResponseMetricAggregator metricAggregator;
private final short responseVersion;
private final long receivedTimestamp;
Expand All @@ -1481,7 +1481,7 @@ private class CompletedFetch {
private boolean initialized = false;

private CompletedFetch(TopicPartition partition,
FetchResponse.PartitionData<Records> partitionData,
FetchResponseData.PartitionData partitionData,
FetchResponseMetricAggregator metricAggregator,
Iterator<? extends RecordBatch> batches,
Long fetchOffset,
Expand Down Expand Up @@ -1651,22 +1651,22 @@ private void consumeAbortedTransactionsUpTo(long offset) {
if (abortedTransactions == null)
return;

while (!abortedTransactions.isEmpty() && abortedTransactions.peek().firstOffset <= offset) {
FetchResponse.AbortedTransaction abortedTransaction = abortedTransactions.poll();
abortedProducerIds.add(abortedTransaction.producerId);
while (!abortedTransactions.isEmpty() && abortedTransactions.peek().firstOffset() <= offset) {
FetchResponseData.AbortedTransaction abortedTransaction = abortedTransactions.poll();
abortedProducerIds.add(abortedTransaction.producerId());
}
}

private boolean isBatchAborted(RecordBatch batch) {
return batch.isTransactional() && abortedProducerIds.contains(batch.producerId());
}

private PriorityQueue<FetchResponse.AbortedTransaction> abortedTransactions(FetchResponse.PartitionData<?> partition) {
private PriorityQueue<FetchResponseData.AbortedTransaction> abortedTransactions(FetchResponseData.PartitionData partition) {
if (partition.abortedTransactions() == null || partition.abortedTransactions().isEmpty())
return null;

PriorityQueue<FetchResponse.AbortedTransaction> abortedTransactions = new PriorityQueue<>(
partition.abortedTransactions().size(), Comparator.comparingLong(o -> o.firstOffset)
PriorityQueue<FetchResponseData.AbortedTransaction> abortedTransactions = new PriorityQueue<>(
partition.abortedTransactions().size(), Comparator.comparingLong(FetchResponseData.AbortedTransaction::firstOffset)
);
abortedTransactions.addAll(partition.abortedTransactions());
return abortedTransactions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import org.apache.kafka.common.IsolationLevel;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.message.FetchRequestData;
import org.apache.kafka.common.message.FetchResponseData;
import org.apache.kafka.common.protocol.ApiKeys;
import org.apache.kafka.common.protocol.ByteBufferAccessor;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.record.MemoryRecords;
import org.apache.kafka.common.record.RecordBatch;
import org.apache.kafka.common.utils.Utils;

Expand Down Expand Up @@ -296,14 +296,11 @@ public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
// may not be any partitions at all in the response. For this reason, the top-level error code
// is essential for them.
Errors error = Errors.forException(e);
LinkedHashMap<TopicPartition, FetchResponse.PartitionData<MemoryRecords>> responseData = new LinkedHashMap<>();
LinkedHashMap<TopicPartition, FetchResponseData.PartitionData> responseData = new LinkedHashMap<>();
for (Map.Entry<TopicPartition, PartitionData> entry : fetchData.entrySet()) {
FetchResponse.PartitionData<MemoryRecords> partitionResponse = new FetchResponse.PartitionData<>(error,
FetchResponse.INVALID_HIGHWATERMARK, FetchResponse.INVALID_LAST_STABLE_OFFSET,
FetchResponse.INVALID_LOG_START_OFFSET, Optional.empty(), null, MemoryRecords.EMPTY);
responseData.put(entry.getKey(), partitionResponse);
responseData.put(entry.getKey(), FetchResponse.partitionResponse(entry.getKey().partition(), error));
}
return new FetchResponse<>(error, responseData, throttleTimeMs, data.sessionId());
return FetchResponse.of(error, throttleTimeMs, data.sessionId(), responseData);
}

public int replicaId() {
Expand Down
Loading