mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3165 from yichengq/client-quorum
client: add Quorum option in getOption
This commit is contained in:
commit
93002caca5
@ -194,6 +194,11 @@ type GetOptions struct {
|
||||
// not be sorted and the ordering used should not be considered
|
||||
// predictable.
|
||||
Sort bool
|
||||
|
||||
// Quorum specifies whether it gets the latest committed value that
|
||||
// has been applied in quorum of members, which ensures external
|
||||
// consistency (or linearizability).
|
||||
Quorum bool
|
||||
}
|
||||
|
||||
type DeleteOptions struct {
|
||||
@ -378,6 +383,7 @@ func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*R
|
||||
if opts != nil {
|
||||
act.Recursive = opts.Recursive
|
||||
act.Sorted = opts.Sort
|
||||
act.Quorum = opts.Quorum
|
||||
}
|
||||
|
||||
resp, body, err := k.client.Do(ctx, act)
|
||||
@ -442,6 +448,7 @@ type getAction struct {
|
||||
Key string
|
||||
Recursive bool
|
||||
Sorted bool
|
||||
Quorum bool
|
||||
}
|
||||
|
||||
func (g *getAction) HTTPRequest(ep url.URL) *http.Request {
|
||||
@ -450,6 +457,7 @@ func (g *getAction) HTTPRequest(ep url.URL) *http.Request {
|
||||
params := u.Query()
|
||||
params.Set("recursive", strconv.FormatBool(g.Recursive))
|
||||
params.Set("sorted", strconv.FormatBool(g.Sorted))
|
||||
params.Set("quorum", strconv.FormatBool(g.Quorum))
|
||||
u.RawQuery = params.Encode()
|
||||
|
||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||
|
@ -102,27 +102,38 @@ func TestGetAction(t *testing.T) {
|
||||
tests := []struct {
|
||||
recursive bool
|
||||
sorted bool
|
||||
quorum bool
|
||||
wantQuery string
|
||||
}{
|
||||
{
|
||||
recursive: false,
|
||||
sorted: false,
|
||||
wantQuery: "recursive=false&sorted=false",
|
||||
quorum: false,
|
||||
wantQuery: "quorum=false&recursive=false&sorted=false",
|
||||
},
|
||||
{
|
||||
recursive: true,
|
||||
sorted: false,
|
||||
wantQuery: "recursive=true&sorted=false",
|
||||
quorum: false,
|
||||
wantQuery: "quorum=false&recursive=true&sorted=false",
|
||||
},
|
||||
{
|
||||
recursive: false,
|
||||
sorted: true,
|
||||
wantQuery: "recursive=false&sorted=true",
|
||||
quorum: false,
|
||||
wantQuery: "quorum=false&recursive=false&sorted=true",
|
||||
},
|
||||
{
|
||||
recursive: true,
|
||||
sorted: true,
|
||||
wantQuery: "recursive=true&sorted=true",
|
||||
quorum: false,
|
||||
wantQuery: "quorum=false&recursive=true&sorted=true",
|
||||
},
|
||||
{
|
||||
recursive: false,
|
||||
sorted: false,
|
||||
quorum: true,
|
||||
wantQuery: "quorum=true&recursive=false&sorted=false",
|
||||
},
|
||||
}
|
||||
|
||||
@ -131,6 +142,7 @@ func TestGetAction(t *testing.T) {
|
||||
Key: "/foo/bar",
|
||||
Recursive: tt.recursive,
|
||||
Sorted: tt.sorted,
|
||||
Quorum: tt.quorum,
|
||||
}
|
||||
got := *f.HTTPRequest(ep)
|
||||
|
||||
@ -1120,11 +1132,13 @@ func TestHTTPKeysAPIGetAction(t *testing.T) {
|
||||
opts: &GetOptions{
|
||||
Sort: true,
|
||||
Recursive: true,
|
||||
Quorum: true,
|
||||
},
|
||||
wantAction: &getAction{
|
||||
Key: "/foo",
|
||||
Sorted: true,
|
||||
Recursive: true,
|
||||
Quorum: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user