-
Notifications
You must be signed in to change notification settings - Fork 500
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
fix pd control bugs #245
Merged
Merged
fix pd control bugs #245
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0873cff
fix pd control bugs
xiaojingchen 01dc579
fix bugs
xiaojingchen 2f2df9a
address comment
xiaojingchen 4d440fb
Merge branch 'master' into pd-controll-bugs
tennix 2e42390
Merge branch 'master' into pd-controll-bugs
xiaojingchen e05e575
Merge branch 'master' into pd-controll-bugs
xiaojingchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,20 @@ func (pc *pdClient) GetStore(storeID uint64) (*StoreInfo, error) { | |
} | ||
|
||
func (pc *pdClient) DeleteStore(storeID uint64) error { | ||
var exist bool | ||
stores, err := pc.GetStores() | ||
if err != nil { | ||
return err | ||
} | ||
for _, store := range stores.Stores { | ||
if store.Store.GetId() == storeID { | ||
exist = true | ||
break | ||
} | ||
} | ||
if !exist { | ||
return nil | ||
} | ||
apiURL := fmt.Sprintf("%s/%s/%d", pc.url, storePrefix, storeID) | ||
req, err := http.NewRequest("DELETE", apiURL, nil) | ||
if err != nil { | ||
|
@@ -316,7 +330,7 @@ func (pc *pdClient) DeleteStore(storeID uint64) error { | |
defer DeferClose(res.Body, &err) | ||
|
||
// Remove an offline store should returns http.StatusOK | ||
if res.StatusCode == http.StatusOK { | ||
if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusNotFound { | ||
return nil | ||
} | ||
body, err := ioutil.ReadAll(res.Body) | ||
|
@@ -328,6 +342,20 @@ func (pc *pdClient) DeleteStore(storeID uint64) error { | |
} | ||
|
||
func (pc *pdClient) DeleteMemberByID(memberID uint64) error { | ||
var exist bool | ||
members, err := pc.GetMembers() | ||
if err != nil { | ||
return err | ||
} | ||
for _, member := range members.Members { | ||
if member.MemberId == memberID { | ||
exist = true | ||
break | ||
} | ||
} | ||
if !exist { | ||
return nil | ||
} | ||
apiURL := fmt.Sprintf("%s/%s/id/%d", pc.url, membersPrefix, memberID) | ||
req, err := http.NewRequest("DELETE", apiURL, nil) | ||
if err != nil { | ||
|
@@ -338,14 +366,28 @@ func (pc *pdClient) DeleteMemberByID(memberID uint64) error { | |
return err | ||
} | ||
defer DeferClose(res.Body, &err) | ||
if res.StatusCode == http.StatusOK { | ||
if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusNotFound { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
return nil | ||
} | ||
err2 := readErrorBody(res.Body) | ||
return fmt.Errorf("failed %v to delete member %d: %v", res.StatusCode, memberID, err2) | ||
} | ||
|
||
func (pc *pdClient) DeleteMember(name string) error { | ||
var exist bool | ||
members, err := pc.GetMembers() | ||
if err != nil { | ||
return err | ||
} | ||
for _, member := range members.Members { | ||
if member.Name == name { | ||
exist = true | ||
break | ||
} | ||
} | ||
if !exist { | ||
return nil | ||
} | ||
apiURL := fmt.Sprintf("%s/%s/name/%s", pc.url, membersPrefix, name) | ||
req, err := http.NewRequest("DELETE", apiURL, nil) | ||
if err != nil { | ||
|
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
DeleteStore
request's response will returnhttp.StatusNotFound
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the response return 500 code too, this is no use now. It's just a standard way.