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

ticdc: support detecting the Kafka cluster version automatically #10854

Merged
merged 9 commits into from
May 7, 2024

Conversation

wk989898
Copy link
Collaborator

@wk989898 wk989898 commented Mar 27, 2024

What problem does this PR solve?

Issue Number: close #10852

What is changed and how it works?

Add Kafka version detect. Connect a broker and use ApiVersionsRequest to get ApiKeys and MaxVersion, according to MaxVersion infer the Kafka version.

Test:

ticdc instance: v8.0.0-master-dirty
pd instance:v7.6.0
tikv instance:v7.6.0
tidb instance:v7.6.0

kafka version status
3.7.0 success
3.0.1 success
2.8.0 success
2.7.0 success
2.5.0 success
2.4.0 success
2.3.1 success
2.1.1 success
2.1.0 success
2.0.1 success
2.0.0 success
1.0.1 success
0.11.0.2 success
0.10.1 API is not supported
0.10.0 API is not supported
0.8.2 not support ApiVersionsRequest

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?

not sure.

Do you need to update user documentation, design documentation or monitoring documentation?

no.

Release note

`None`

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels Mar 27, 2024
Copy link
Contributor

ti-chi-bot bot commented Mar 27, 2024

Hi @wk989898. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 27, 2024
@@ -122,6 +117,28 @@ func NewSaramaConfig(ctx context.Context, o *Options) (*sarama.Config, error) {
return nil, cerror.WrapError(cerror.ErrKafkaInvalidConfig, err)
}

kafkaVersion, err := GetKafkaVersion(ctx, config, o)
Copy link
Member

@sdojjy sdojjy Mar 28, 2024

Choose a reason for hiding this comment

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

only detect the kafka cluster version when there is no version specified by the user

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

detect the kafka version is necessary if the user specified an error version

}
if o.IsAssignedVersion {
config.Version = version
if version.String() != kafkaVersion.String() {
Copy link
Member

Choose a reason for hiding this comment

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

according to the api version mapping, if the kafka cluster version is greater than 2.8.0, version.String() != kafkaVersion.String() is always true.

log.Warn("Kafka fail to open broker", zap.String("addr", addrs[i]))
continue
}
defer func() {
Copy link
Member

Choose a reason for hiding this comment

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

do not use defer in for loop

return sarama.V2_0_0_0, err
}

func requiredVersion(version int16) sarama.KafkaVersion {
Copy link
Member

Choose a reason for hiding this comment

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

requiredVersion is not a good name here, this function is just a version mapping.

}
if o.IsAssignedVersion {
config.Version = version
if !version.IsAtLeast(sarama.V2_8_0_0) && version.String() != kafkaVersion.String() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to use constants rather than literals.

return version, err
}
}
return sarama.V2_0_0_0, err
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to use constants rather than literals.

if err != nil {
return nil, cerror.WrapError(cerror.ErrKafkaInvalidVersion, err)
}
if o.IsAssignedVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

config.Version = kafkaVersion can be set at the very first, else is redundant.

var err error
addrs := o.BrokerEndpoints
if len(addrs) > 1 {
// Shuffle the list of addresses to randomize the order in which
Copy link
Contributor

Choose a reason for hiding this comment

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

Why shuffle here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Prevent latency from increasing when the first address is inaccessible.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Apr 1, 2024
@ti-chi-bot ti-chi-bot bot added the lgtm label Apr 8, 2024
Copy link
Contributor

ti-chi-bot bot commented Apr 8, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand, CharlesCheung96

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [3AceShowHand,CharlesCheung96]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 8, 2024
Copy link
Contributor

ti-chi-bot bot commented Apr 8, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-04-01 05:27:51.601357024 +0000 UTC m=+248933.128897563: ☑️ agreed by CharlesCheung96.
  • 2024-04-08 10:24:09.791888507 +0000 UTC m=+871511.319429053: ☑️ agreed by 3AceShowHand.

Copy link

codecov bot commented Apr 22, 2024

Codecov Report

Attention: Patch coverage is 51.94805% with 37 lines in your changes are missing coverage. Please review.

Project coverage is 57.4052%. Comparing base (894b36f) to head (4c10b56).

Additional details and impacted files
Components Coverage Δ
cdc 61.6809% <51.9480%> (+0.0162%) ⬆️
dm 51.2315% <ø> (-0.0061%) ⬇️
engine 63.3950% <ø> (+0.0070%) ⬆️
Flag Coverage Δ
unit 57.4052% <51.9480%> (+0.0086%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@@               Coverage Diff                @@
##             master     #10854        +/-   ##
================================================
+ Coverage   57.3966%   57.4052%   +0.0086%     
================================================
  Files           851        851                
  Lines        125469     125539        +70     
================================================
+ Hits          72015      72066        +51     
- Misses        48034      48056        +22     
+ Partials       5420       5417         -3     

@wk989898
Copy link
Collaborator Author

/retest

Copy link
Contributor

ti-chi-bot bot commented Apr 28, 2024

@wk989898: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@CharlesCheung96
Copy link
Contributor

/retest

@ti-chi-bot ti-chi-bot bot merged commit 99d3755 into pingcap:master May 7, 2024
28 checks passed
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. label May 16, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #11120.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #11123.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved contribution This PR is from a community contributor. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TiCDC: kafka client has run out of available brokers to talk to: EOF
5 participants