Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rest:offsets): prevent not_leader_for_partition error #692

Merged
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
13 changes: 12 additions & 1 deletion karapace/kafka_rest_apis/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,20 @@ def make_offsets_request(self, topic: str, partition_id: int, timestamp: int) ->
topics = [(topic, partitions)]
request = OffsetRequest[2](replica_id, isolation_level, topics)

future = self._send_request_to_least_loaded_node(request)
future = self.send_request_to_leader_node(request, topic, partition_id)
return future

def send_request_to_leader_node(self, request: OffsetRequest, topic_name: str, partition_id: int) -> Future:
cluster_meta_resp = self.cluster_metadata(topics=[topic_name])
partition = [p for p in cluster_meta_resp["topics"][topic_name]["partitions"] if p["partition"] == partition_id]

# handle case where partition_id is not part metadata
if partition == []:
return self._send_request_to_least_loaded_node(request)

leader_id = partition[0]["leader"]
return self._send_request_to_node(leader_id, request)

def get_offsets(self, topic: str, partition_id: int) -> dict:
beginning_f = self.make_offsets_request(topic, partition_id, OffsetResetStrategy.EARLIEST)
end_f = self.make_offsets_request(topic, partition_id, OffsetResetStrategy.LATEST)
Expand Down