pdctl: support to specify multiple pd addrs seperated by commas#1629
Merged
Conversation
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.
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
disksing
reviewed
Jul 11, 2019
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
rleungx
reviewed
Jul 11, 2019
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
Signed-off-by: Shafreeck Sea <shafreeck@gmail.com>
disksing
approved these changes
Jul 11, 2019
rleungx
approved these changes
Jul 11, 2019
nolouch
approved these changes
Jul 12, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 isdoRequest) builds thehttp.Requestinside 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
doRequestanddiala request returned bygetRequestis redundant, so I removed thegetReqeustfunction and combines all the features intodoRequest.doRequestis extended to accept an optional body so it wraps the feature ofdial+getRequestand 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
-ucan use a comma separated string with urlsCheck List
Tests