client: add Quorum option in getOption
This commit is contained in:
@ -194,6 +194,11 @@ type GetOptions struct {
|
|||||||
// not be sorted and the ordering used should not be considered
|
// not be sorted and the ordering used should not be considered
|
||||||
// predictable.
|
// predictable.
|
||||||
Sort bool
|
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 {
|
type DeleteOptions struct {
|
||||||
@ -378,6 +383,7 @@ func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*R
|
|||||||
if opts != nil {
|
if opts != nil {
|
||||||
act.Recursive = opts.Recursive
|
act.Recursive = opts.Recursive
|
||||||
act.Sorted = opts.Sort
|
act.Sorted = opts.Sort
|
||||||
|
act.Quorum = opts.Quorum
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, body, err := k.client.Do(ctx, act)
|
resp, body, err := k.client.Do(ctx, act)
|
||||||
@ -442,6 +448,7 @@ type getAction struct {
|
|||||||
Key string
|
Key string
|
||||||
Recursive bool
|
Recursive bool
|
||||||
Sorted bool
|
Sorted bool
|
||||||
|
Quorum bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *getAction) HTTPRequest(ep url.URL) *http.Request {
|
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 := u.Query()
|
||||||
params.Set("recursive", strconv.FormatBool(g.Recursive))
|
params.Set("recursive", strconv.FormatBool(g.Recursive))
|
||||||
params.Set("sorted", strconv.FormatBool(g.Sorted))
|
params.Set("sorted", strconv.FormatBool(g.Sorted))
|
||||||
|
params.Set("quorum", strconv.FormatBool(g.Quorum))
|
||||||
u.RawQuery = params.Encode()
|
u.RawQuery = params.Encode()
|
||||||
|
|
||||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||||
|
@ -102,27 +102,38 @@ func TestGetAction(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
recursive bool
|
recursive bool
|
||||||
sorted bool
|
sorted bool
|
||||||
|
quorum bool
|
||||||
wantQuery string
|
wantQuery string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
recursive: false,
|
recursive: false,
|
||||||
sorted: false,
|
sorted: false,
|
||||||
wantQuery: "recursive=false&sorted=false",
|
quorum: false,
|
||||||
|
wantQuery: "quorum=false&recursive=false&sorted=false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
recursive: true,
|
recursive: true,
|
||||||
sorted: false,
|
sorted: false,
|
||||||
wantQuery: "recursive=true&sorted=false",
|
quorum: false,
|
||||||
|
wantQuery: "quorum=false&recursive=true&sorted=false",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
recursive: false,
|
recursive: false,
|
||||||
sorted: true,
|
sorted: true,
|
||||||
wantQuery: "recursive=false&sorted=true",
|
quorum: false,
|
||||||
|
wantQuery: "quorum=false&recursive=false&sorted=true",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
recursive: true,
|
recursive: true,
|
||||||
sorted: 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",
|
Key: "/foo/bar",
|
||||||
Recursive: tt.recursive,
|
Recursive: tt.recursive,
|
||||||
Sorted: tt.sorted,
|
Sorted: tt.sorted,
|
||||||
|
Quorum: tt.quorum,
|
||||||
}
|
}
|
||||||
got := *f.HTTPRequest(ep)
|
got := *f.HTTPRequest(ep)
|
||||||
|
|
||||||
@ -1120,11 +1132,13 @@ func TestHTTPKeysAPIGetAction(t *testing.T) {
|
|||||||
opts: &GetOptions{
|
opts: &GetOptions{
|
||||||
Sort: true,
|
Sort: true,
|
||||||
Recursive: true,
|
Recursive: true,
|
||||||
|
Quorum: true,
|
||||||
},
|
},
|
||||||
wantAction: &getAction{
|
wantAction: &getAction{
|
||||||
Key: "/foo",
|
Key: "/foo",
|
||||||
Sorted: true,
|
Sorted: true,
|
||||||
Recursive: true,
|
Recursive: true,
|
||||||
|
Quorum: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user