Skip to content

config: add backend cluster schema and multi-port listener config#1103

Merged
ti-chi-bot[bot] merged 2 commits intopingcap:mainfrom
YangKeao:pr/02-multi-cluster-config
Mar 24, 2026
Merged

config: add backend cluster schema and multi-port listener config#1103
ti-chi-bot[bot] merged 2 commits intopingcap:mainfrom
YangKeao:pr/02-multi-cluster-config

Conversation

@YangKeao
Copy link
Member

@YangKeao YangKeao commented Mar 19, 2026

What problem does this PR solve?

Issue Number: close #1097

What is changed and how it works:

Add the configuration surface needed for multi-cluster routing:

  • [[proxy.backend-clusters]]
  • balance.routing-rule = "port"
  • proxy.port-range = [...]

This keeps existing single-cluster configuration working while introducing the new schema for:

  • multiple backend PD clusters
  • port-based routing
  • per-cluster DNS server configuration

Check List

Tests

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

Notable changes

  • Has configuration change
  • Has HTTP API interfaces change
  • Has tiproxyctl change
  • Other user behavior changes

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot requested review from djshow832 and xhebox March 19, 2026 16:43
@ti-chi-bot ti-chi-bot bot added the size/XXL label Mar 19, 2026
@YangKeao
Copy link
Member Author

/retest

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 82.44275% with 23 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@4ef8435). Learn more about missing BASE report.

Files with missing lines Patch % Lines
lib/config/proxy.go 84.00% 14 Missing and 6 partials ⚠️
pkg/proxy/proxy.go 40.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1103   +/-   ##
=======================================
  Coverage        ?   67.08%           
=======================================
  Files           ?      141           
  Lines           ?    14814           
  Branches        ?        0           
=======================================
  Hits            ?     9938           
  Misses          ?     4198           
  Partials        ?      678           
Flag Coverage Δ
unit 67.08% <82.44%> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +79 to +83
type BackendCluster struct {
Name string `yaml:"name,omitempty" toml:"name,omitempty" json:"name,omitempty" reloadable:"true"`
PDAddrs string `yaml:"pd-addrs,omitempty" toml:"pd-addrs,omitempty" json:"pd-addrs,omitempty" reloadable:"true"`
NSServers []string `yaml:"ns-servers,omitempty" toml:"ns-servers,omitempty" json:"ns-servers,omitempty" reloadable:"true"`
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

reloadable means it can be updated online. Why not put it in ProxyServerOnline?
Besides, I don't see how it's hot-reloaded.

Copy link
Member Author

@YangKeao YangKeao Mar 24, 2026

Choose a reason for hiding this comment

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

Why not put it in ProxyServerOnline?

Done. I've moved it to ProxyServerOnline. Sorry I didn't get the meaning of ProxyServerOnline previously 😢

Besides, I don't see how it's hot-reloaded.

Also through API and watchConfig channel, you can find it in later PR https://github.com/pingcap/tiproxy/pull/1104/changes#diff-3e09c0d7ae18b71320d7c24a83a3be7bc8437ca68f7aaa9de953ef7fbc0a6810R80 .

if err != nil || portNum < 1 || portNum > 65535 {
return "", errors.New("port is invalid")
}
return net.JoinHostPort(host, strconv.Itoa(portNum)), nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just return server?

Copy link
Member Author

@YangKeao YangKeao Mar 24, 2026

Choose a reason for hiding this comment

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

It's also fine to just return server. Re-joining the host and port can avoid some strange cases and return a "normalized value". For example, the 127.0.0.1:0053 will be converted to 127.0.0.1:53 (though 127.0.0.1:0053 is also OK for most of the function calls).

return nil, errors.New("proxy.port-range must contain exactly two ports")
}
start, end := ps.PortRange[0], ps.PortRange[1]
if start < 1 || start > 65535 || end < 1 || end > 65535 || start > end {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if a port is assigned by BackendIO before it's assigned as a listening port?

Copy link
Member Author

@YangKeao YangKeao Mar 24, 2026

Choose a reason for hiding this comment

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

Listeners are not hot-configurable, so it will listen to all ports at the beginning, and no port will be assigned before it listens the port.

The GetSQLAddrs will return a huge list: [127.0.0.1:6000, 127.0.0.1:6001, 127.0.0.1:6002, .... 127.0.0.1:9000] and all of them will be listened at the beginning of the program.

Introduce backend cluster config, compatibility helpers, validation, and SQL listener support for proxy.port-range.
@YangKeao YangKeao force-pushed the pr/02-multi-cluster-config branch from a09d6c3 to 8f52821 Compare March 24, 2026 09:01
@ti-chi-bot ti-chi-bot bot removed the lgtm label Mar 24, 2026
@ti-chi-bot ti-chi-bot bot added the lgtm label Mar 24, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Mar 24, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: djshow832

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

The pull request process is described here

Details Needs approval from an approver in each of these files:

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
Copy link

ti-chi-bot bot commented Mar 24, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-03-24 11:26:28.339462868 +0000 UTC m=+267584.375533118: ☑️ agreed by djshow832.
  • 2026-03-24 11:26:39.272733904 +0000 UTC m=+267595.308804164: ✖️🔁 reset by djshow832.
  • 2026-03-24 11:26:53.042427088 +0000 UTC m=+267609.078497348: ☑️ agreed by djshow832.

@ti-chi-bot ti-chi-bot bot merged commit 29264bd into pingcap:main Mar 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configs related to multi-cluster support, and listen to multiple ports.

3 participants