Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -959,6 +959,7 @@ public void handle(OffsetFetchResponse response, RequestFuture<Map<TopicPartitio
return;
}

Set<String> unauthorizedTopics = null;
Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>(response.responseData().size());
for (Map.Entry<TopicPartition, OffsetFetchResponse.PartitionData> entry : response.responseData().entrySet()) {
TopicPartition tp = entry.getKey();
Expand All @@ -969,11 +970,17 @@ public void handle(OffsetFetchResponse response, RequestFuture<Map<TopicPartitio

if (error == Errors.UNKNOWN_TOPIC_OR_PARTITION) {
future.raise(new KafkaException("Topic or Partition " + tp + " does not exist"));
return;
} else if (error == Errors.TOPIC_AUTHORIZATION_FAILED) {
if (unauthorizedTopics == null) {
unauthorizedTopics = new HashSet<>();
}
unauthorizedTopics.add(tp.topic());
} else {
future.raise(new KafkaException("Unexpected error in fetch offset response for partition " +
tp + ": " + error.message()));
return;
}
return;
} else if (data.offset >= 0) {
// record the position with the offset (-1 indicates no committed offset to fetch)
offsets.put(tp, new OffsetAndMetadata(data.offset, data.leaderEpoch, data.metadata));
Expand All @@ -982,7 +989,11 @@ public void handle(OffsetFetchResponse response, RequestFuture<Map<TopicPartitio
}
}

future.complete(offsets);
if (unauthorizedTopics != null) {
future.raise(new TopicAuthorizationException(unauthorizedTopics));
} else {
future.complete(offsets);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
* Possible error codes:
*
* - Partition errors:
* - UNKNOWN_TOPIC_OR_PARTITION (3)
* - {@link Errors#UNKNOWN_TOPIC_OR_PARTITION}
* - {@link Errors#TOPIC_AUTHORIZATION_FAILED}
*
* - Group or coordinator errors:
* - COORDINATOR_LOAD_IN_PROGRESS (14)
* - COORDINATOR_NOT_AVAILABLE (15)
* - NOT_COORDINATOR (16)
* - GROUP_AUTHORIZATION_FAILED (30)
* - {@link Errors#COORDINATOR_LOAD_IN_PROGRESS}
* - {@link Errors#COORDINATOR_NOT_AVAILABLE}
* - {@link Errors#NOT_COORDINATOR}
* - {@link Errors#GROUP_AUTHORIZATION_FAILED}
*/
public class OffsetFetchResponse extends AbstractResponse {
private static final Field.ComplexArray TOPICS = new Field.ComplexArray("responses",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.kafka.common.errors.FencedInstanceIdException;
import org.apache.kafka.common.errors.GroupAuthorizationException;
import org.apache.kafka.common.errors.OffsetMetadataTooLarge;
import org.apache.kafka.common.errors.TopicAuthorizationException;
import org.apache.kafka.common.errors.WakeupException;
import org.apache.kafka.common.internals.ClusterResourceListeners;
import org.apache.kafka.common.internals.Topic;
Expand Down Expand Up @@ -1791,6 +1792,21 @@ public void testFetchCommittedOffsets() {
assertEquals(new OffsetAndMetadata(offset, leaderEpoch, metadata), fetchedOffsets.get(t1p));
}

@Test
public void testTopicAuthorizationFailedInOffsetFetch() {
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady(time.timer(Long.MAX_VALUE));

OffsetFetchResponse.PartitionData data = new OffsetFetchResponse.PartitionData(-1, Optional.empty(),
"", Errors.TOPIC_AUTHORIZATION_FAILED);

client.prepareResponse(new OffsetFetchResponse(Errors.NONE, singletonMap(t1p, data)));
TopicAuthorizationException exception = assertThrows(TopicAuthorizationException.class, () ->
coordinator.fetchCommittedOffsets(singleton(t1p), time.timer(Long.MAX_VALUE)));

assertEquals(singleton(topic1), exception.unauthorizedTopics());
}

@Test
public void testRefreshOffsetLoadInProgress() {
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
Expand Down