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

Elect leader api(KIP-460) implemented #1311

Merged
merged 12 commits into from
Oct 10, 2024
Merged

Elect leader api(KIP-460) implemented #1311

merged 12 commits into from
Oct 10, 2024

Conversation

PratRanj07
Copy link
Contributor

Implemented the ElectLeaders API and wrote unit tests for it

@PratRanj07 PratRanj07 requested review from a team as code owners October 3, 2024 18:10
@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

milindl
milindl previously requested changes Oct 8, 2024
Copy link
Contributor

@milindl milindl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good

Please add an integration test

@@ -43,3 +43,4 @@ protobuf_consumer_example/protobuf_consumer_example
protobuf_producer_example/protobuf_producer_example
stats_example/stats_example
transactions_example/transactions_example
admin_elect_leaders/admin_elect_leaders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add with all the other admin stuff (in alphabetical order)

@@ -86,6 +86,8 @@ Examples

[transactions_example](transactions_example) - Showcasing a transactional consume-process-produce application

[admin_elect_leaders](admin_elect_leaders) - Perform Preferred/ Unclean elections for the specified Topic Partitions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[admin_elect_leaders](admin_elect_leaders) - Perform Preferred/ Unclean elections for the specified Topic Partitions
[admin_elect_leaders](admin_elect_leaders) - Perform Preferred/Unclean elections for the specified Topic Partitions

And also keep it in alphabetical order

return result, newErrorFromString(ErrInvalidArg, "expected non-empty partitions")
}

result = ElectLeadersResult{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not needed

partitions = make([]TopicPartition, partCnt)

for i := 0; i < partCnt; i++ {
setupTopicPartitionFromCtopicPartitionResult(&partitions[i],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this method so that you can just pass the C.rd_kafka_topic_partition_result_t directly into it and let it call the other on its own.

I also feel like both newTopicPartitionsFromCTopicPartitionResult and setupTopicPartitionFromCtopicPartitionResult should be in kafka.go, but that can wait for when we need it from another place.

// err returns any top level level that occured during the operation.
func (a *AdminClient) ElectLeaders(ctx context.Context, electLeaderRequest ElectLeadersRequest, options ...ElectLeadersAdminOption) (result ElectLeadersResult, err error) {

if len(electLeaderRequest.partitions) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed in the call with the team:

0-length should give an error

nil corresponds to null and should set for all partitions

But len(nil) == len([]) == 0

partitions []TopicPartition
}

func NewElectLeadersRequest(electionType ElectionType, partitions []TopicPartition) ElectLeadersRequest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment above function

Comment on lines 1097 to 1098
// TopicPartitions for which election has been performed and specific error if any
// that occured while election in the specific TopicPartition.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TopicPartitions for which election has been performed and specific error if any
// that occured while election in the specific TopicPartition.
// TopicPartitions for which election has been performed and the per-partition error, if any
// that occurred while running the election for the specific TopicPartition.

Comment on lines 3607 to 3608
// User has to check all the elements of the result to check any error occured per partition.
// err returns any top level level that occured during the operation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// User has to check all the elements of the result to check any error occured per partition.
// err returns any top level level that occured during the operation.
// Individual TopicPartitions inside the ElectLeadersResult should be checked for errors.
// Additionally, an error that is not nil for client-level errors is returned.

{},
{SetAdminRequestTimeout(time.Second)},
} {
// empty list should fail
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this after the librdkafka change, so the empty list fails, but a nil list times out instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually after the librdkafka change, both empty list and nil partitions is valid.
If there is an empty list in input, we are getting an empty list in the output and for nil, all partitions.


res, err := ac.ElectLeaders(ctx, kafka.NewElectLeadersRequest(electionType, topicPartitionList))
if err != nil {
kafkaErr, ok := err.(kafka.Error) // Type assertion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kafkaErr, ok := err.(kafka.Error) // Type assertion
kafkaErr, ok := err.(kafka.Error)

Copy link
Contributor

@emasab emasab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR Pratyush! A few comments:

examples/README.md Outdated Show resolved Hide resolved
examples/README.md Outdated Show resolved Hide resolved
examples/admin_elect_leaders/admin_elect_leaders.go Outdated Show resolved Hide resolved
kafka/adminapi.go Outdated Show resolved Hide resolved
kafka/adminapi.go Outdated Show resolved Hide resolved
kafka/adminapi.go Show resolved Hide resolved
kafka/adminapi.go Outdated Show resolved Hide resolved
@PratRanj07 PratRanj07 requested a review from emasab October 9, 2024 20:00
Copy link
Contributor

@emasab emasab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Well done Pratyush!

@emasab emasab dismissed milindl’s stale review October 10, 2024 14:53

Milind is OOO

@PratRanj07 PratRanj07 merged commit be6f062 into master Oct 10, 2024
3 checks passed
@PratRanj07 PratRanj07 deleted the dev_electLeaders branch October 10, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants