Skip to content

pdctl: support to specify multiple pd addrs seperated by commas#1629

Merged
nolouch merged 9 commits into
tikv:masterfrom
shafreeck:pdctl/urls
Jul 12, 2019
Merged

pdctl: support to specify multiple pd addrs seperated by commas#1629
nolouch merged 9 commits into
tikv:masterfrom
shafreeck:pdctl/urls

Conversation

@shafreeck
Copy link
Copy Markdown
Contributor

@shafreeck shafreeck commented Jul 10, 2019

Signed-off-by: Shafreeck Sea shafreeck@gmail.com

Closes #1611

Example:
$ pd-ctl -u 'http://192.168.10.1:2379,http://192.168.10.2:2379'

pd-ctl prefers to stick on a health endpoint until getting some error,
then it chooses the next endpoint in a round-robin manner and keeps using
it until next error.

It should be noticed that if the current endpoint cannot fail fast, it
maybe slow to get the result while the next endpoint is healthy, because
we were waiting for the current endpoint to return until it was timed out.

About the refactoring

I didn't find a way to refactor the code in an OOP manner, because the original code is procedure-oriented and the HTTP client to issue a request is tightly coupled with cobra.Command. I used a functional-style instead, the function to issue a request(which is doRequest) builds the
http.Request inside and uses a closure to maintain the pointer to the current endpoint,
if the endpoint becomes unavailable, the closure advances the pointer to the next.

The feature of doRequest and dial a request returned by getRequest is redundant, so I removed the getReqeust function and combines all the features into doRequest. doRequest is extended to accept an optional body so it wraps the feature of dial + getRequest and at the same time is compatible with the original code.

What problem does this PR solve?

Closes #1611

What is changed and how it works?

pd-ctl -u can use a comma separated string with urls

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>

Closes tikv#1611

Example:
 $ pd-ctl -u 'http://192.168.10.1:2379,http://192.168.10.2:2379'

pd-ctl prefers to stick on a health endpoint until getting some error,
then it chooses a next endpoint in a round-robin manner and keeps using
it until next error.

It should be noticed that if current endpoint can not fail fast, it
maybe slow to get the result while the next endpoint is healthy, because
we were waiting for the current endpoint to return until it was timeout.
@shafreeck shafreeck self-assigned this Jul 10, 2019
@shafreeck shafreeck added area/pdctl type/enhancement The issue or PR belongs to an enhancement. labels Jul 10, 2019
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Comment thread tools/pd-ctl/pdctl/command/global.go Outdated
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Comment thread tools/pd-ctl/pdctl/command/global.go Outdated
Comment thread tools/pd-ctl/pdctl/command/global.go
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
@nolouch nolouch merged commit 75a1f9f into tikv:master Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement The issue or PR belongs to an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: pd-ctl support multiple server addresses

4 participants