-
Notifications
You must be signed in to change notification settings - Fork 901
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
Added a delete records api #1710
Changes from 46 commits
863a1e8
93fc6c3
7336986
4417733
f7952b6
6293a56
b4a1f08
900540e
49ced95
5e67ea3
684efd8
f0626ff
60b8feb
654e069
86ae277
5afe007
d7f37db
5e4cd7d
50443bc
bd64ea6
fddaa6a
58ac04c
9ba4168
8f7f2a6
9f3152d
e176626
fb202c8
766aa16
e240e2f
cd5cfac
e46e3d6
1366b2d
8ed70cb
dc1e05c
8483b12
293a050
fba0f7b
cdd3ae4
e3b5b96
9f5dcde
227cb0f
e359c0f
d93162a
d965435
8172ca8
60a4258
65b3417
3f1a7f3
e1f484d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
emasab marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -54,6 +54,8 @@ | |||||
from ._listoffsets import (OffsetSpec, # noqa: F401 | ||||||
ListOffsetsResultInfo) | ||||||
|
||||||
from ._records import DeletedRecords # noqa: F401 | ||||||
|
||||||
from .._model import TopicCollection as _TopicCollection | ||||||
|
||||||
from ..cimpl import (KafkaException, # noqa: F401 | ||||||
|
@@ -535,6 +537,17 @@ def _check_list_offsets_request(topic_partition_offsets, kwargs): | |||||
if not isinstance(kwargs['isolation_level'], _IsolationLevel): | ||||||
raise TypeError("isolation_level argument should be an IsolationLevel") | ||||||
|
||||||
@staticmethod | ||||||
def _check_delete_records(request): | ||||||
if not isinstance(request, list): | ||||||
raise TypeError(f"Expected Request to be a list, got '{type(request).__name__}' ") | ||||||
for req in request: | ||||||
if not isinstance(req, _TopicPartition): | ||||||
raise TypeError("Element of the request list must be of type 'TopicPartition'" + | ||||||
f" got '{type(req).__name__}' ") | ||||||
if req.partition < 0: | ||||||
raise ValueError("'partition' cannot be negative") | ||||||
|
||||||
pranavrth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
def create_topics(self, new_topics, **kwargs): | ||||||
""" | ||||||
Create one or more new topics. | ||||||
|
@@ -544,7 +557,8 @@ def create_topics(self, new_topics, **kwargs): | |||||
:param float operation_timeout: The operation timeout in seconds, | ||||||
controlling how long the CreateTopics request will block | ||||||
on the broker waiting for the topic creation to propagate | ||||||
in the cluster. A value of 0 returns immediately. Default: 0 | ||||||
in the cluster. A value of 0 returns immediately. | ||||||
Default: `socket.timeout.ms/1000.0` | ||||||
:param float request_timeout: The overall request timeout in seconds, | ||||||
including broker lookup, request transmission, operation time | ||||||
on broker, and response. Default: `socket.timeout.ms*1000.0` | ||||||
pranavrth marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
@@ -577,7 +591,8 @@ def delete_topics(self, topics, **kwargs): | |||||
:param float operation_timeout: The operation timeout in seconds, | ||||||
controlling how long the DeleteTopics request will block | ||||||
on the broker waiting for the topic deletion to propagate | ||||||
in the cluster. A value of 0 returns immediately. Default: 0 | ||||||
in the cluster. A value of 0 returns immediately. | ||||||
Default: `socket.timeout.ms/1000.0` | ||||||
:param float request_timeout: The overall request timeout in seconds, | ||||||
including broker lookup, request transmission, operation time | ||||||
on broker, and response. Default: `socket.timeout.ms*1000.0` | ||||||
|
@@ -615,7 +630,8 @@ def create_partitions(self, new_partitions, **kwargs): | |||||
:param float operation_timeout: The operation timeout in seconds, | ||||||
controlling how long the CreatePartitions request will block | ||||||
on the broker waiting for the partition creation to propagate | ||||||
in the cluster. A value of 0 returns immediately. Default: 0 | ||||||
in the cluster. A value of 0 returns immediately. | ||||||
Default: `socket.timeout.ms/1000.0` | ||||||
:param float request_timeout: The overall request timeout in seconds, | ||||||
including broker lookup, request transmission, operation time | ||||||
on broker, and response. Default: `socket.timeout.ms*1000.0` | ||||||
|
@@ -1205,3 +1221,40 @@ def list_offsets(self, topic_partition_offsets, **kwargs): | |||||
|
||||||
super(AdminClient, self).list_offsets(topic_partition_offsets_list, f, **kwargs) | ||||||
return futmap | ||||||
|
||||||
def delete_records(self, topic_partition_offsets, **kwargs): | ||||||
""" | ||||||
Deletes all the records before the specified offsets (not including), | ||||||
in the specified Topic and Partitions. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Written this way they seem like classes
Suggested change
|
||||||
|
||||||
:param list(TopicPartitions) topic_partition_offsets: A list of | ||||||
TopicPartition objects having `offset` field set to the offset | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
before which all the records should be deleted. | ||||||
`offset` can be set to :py:const:`OFFSET_END` (-1) to delete all records | ||||||
in the partition. | ||||||
:param float request_timeout: The overall request timeout in seconds, | ||||||
including broker lookup, request transmission, operation time | ||||||
on broker, and response. Default: `socket.timeout.ms*1000.0` | ||||||
:param float operation_timeout: The operation timeout in seconds, | ||||||
PratRanj07 marked this conversation as resolved.
Show resolved
Hide resolved
emasab marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
controlling how long the delete_records request will block | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
on the broker waiting for the record deletion to propagate | ||||||
in the cluster. A value of 0 returns immediately. | ||||||
Default: `socket.timeout.ms/1000.0` | ||||||
|
||||||
:returns: A dict of futures keyed by the TopicPartition. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
The future result() method returns DeletedRecords | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
or raises KafkaException | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
:rtype: dict[TopicPartition, future] | ||||||
|
||||||
:raises KafkaException: Operation failed locally or on broker. | ||||||
:raises TypeError: Invalid input type. | ||||||
:raises ValueError: Invalid input value. | ||||||
""" | ||||||
AdminClient._check_delete_records(topic_partition_offsets) | ||||||
|
||||||
f, futmap = AdminClient._make_futures_v2( | ||||||
topic_partition_offsets, _TopicPartition, AdminClient._make_futmap_result) | ||||||
|
||||||
super(AdminClient, self).delete_records(topic_partition_offsets, f, **kwargs) | ||||||
return futmap |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2024 Confluent Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
class DeletedRecords: | ||
""" | ||
DeletedRecords | ||
Represents information about deleted records. | ||
|
||
Parameters | ||
---------- | ||
low_watermark: int | ||
The "low watermark" for the topic partition on which the deletion was executed. | ||
""" | ||
def __init__(self, low_watermark): | ||
self.low_watermark = low_watermark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
DeletedRecords
toindex.rst
afterConsumerGroupDescription
and