207 Commits

Author SHA1 Message Date
Jonathan Boulle
5490db7cca client: fix typo in docstring (than -> then) 2016-01-28 18:07:39 +01:00
Gyu-Ho Lee
bbb7fb5a46 client: do not timeout when wait is true
Current V2 watch waits by encoding URL with wait=true.
When a client sets 'no-sync', it requests directly to
proxy and the proxy redirects it by cloning the request
object, which leads to cancel the original request when
it times out and the cloned request gets closed prematurely.

This fixes coreos#3894 by querying
the original client request in order to not use context timeout
when 'wait=true'.
2016-01-21 18:45:15 -08:00
Gyu-Ho Lee
2a3bd01f58 *: move EndpointSelection doc to godoc
This merges two redundant documentation into one.
2016-01-21 09:48:05 -08:00
Xiang Li
d2d70513a1 Merge pull request #4185 from xiang90/client-srv
*: support client srv target
2016-01-13 11:26:35 -08:00
Xiang Li
bfa21001a1 *: support client srv target 2016-01-13 11:12:15 -08:00
Gyu-Ho Lee
3ac8ff3a84 client: keys.go minor typo 2016-01-13 11:02:37 -08:00
Gyu-Ho Lee
f67f6d7c7c client: add IsKeyNotFound function
This can be used to check if an error is client.ErrorCodeKeyNotFound.
Related to https://github.com/coreos/etcd/issues/4080.
2016-01-12 20:04:08 -08:00
Jonathan Boulle
dac56faf61 Merge pull request #4030 from mitake/endpoint-selection
client: add a mechanism for various endpoint selection mode
2015-12-24 12:55:16 +01:00
Hitoshi Mitake
a46ffc60e5 client: add a mechanism for various endpoint selection mode
Current etcd client library chooses a default destination node from
every member of a cluster in a random manner. However, requests of
write and read (for consistent results) need to be forwarded to the
leader node as the nature of Raft algorithm. If the chosen node is a
follower, additional network traffic will be caused by the forwarding
from follower to leader.

Mainly for reducing the forward traffic, this commit adds a new
mechanism for various endpoint selection mode to the client library
which can be configured with client.Config.SelectionMode.

Currently, two modes are provided:
 - EndpointSelectionRandom: default, same to existing behavior (pick
   a node in a random manner)
 - EndpointSelectionPrioritizeLeader: prioritize leader, for the above
   purpose

I evaluated the effectiveness of the EndpointSelectionPrioritizeLeader
with 4 t1.micro instances of AWS (3 nodes for etcd cluster and 1 node
for etcd client). Client executes this simple benchmark
(https://github.com/mitake/etcd-things/tree/master/prioritize-leader-bench),
just writes 10000 keys. When SelectionMode == EndpointSelectionRandom
(default), the benchmark needed 1 min and 32.102 sec to finish. When
SelectionMode == EndpointSelectionPrioritizeLeader, the benchmark
needed 1 min 4.760 sec.
2015-12-24 11:02:40 +09:00
Hitoshi Mitake
53be8405f3 client: a new API for obtaining a leader node information 2015-12-23 22:54:04 +09:00
Xiang Li
5587c4aa9a client: support reset Endpoints.
ResetEndpoints is useful when the there is a scheduled cluster
changes or when manually manage the cluster without auto-sync
enabled.
2015-12-21 11:59:13 -08:00
Gyu-Ho Lee
88aec09ddf client: fixes for govet -shadow
This fixes for shadowed error variables found by go tip go tool vet.
Fixes for https://github.com/coreos/etcd/issues/3954.
2015-12-12 09:13:07 -08:00
masterlvng
938333a9fe client/README: correct Endpoints param 2015-12-09 20:49:52 -08:00
Andrei Korzhevskii
cb9a3e04b1 client: fix goroutine leak in unreleased context
If headerTimeout is not zero then two context are created but only one is released.
cancelCtx in this case is never released which leads to goroutine leak inside it.
2015-11-27 19:44:38 +03:00
Wojciech Tyczynski
65ae8784fb client: regenerate code to unmarshal key response
Regenerate code for unmarshaling key response with a new version of
ugorji/go/codec.
2015-11-02 12:06:32 +01:00
kayrus
afb35e366d client: added example on how to get node's value 2015-10-19 10:31:05 +02:00
Wojciech Tyczynski
4eb598be06 client: regenerate code to unmarshal key response
Regenerate code for unmarshaling key response with a new version of
ugorji/go/codec
2015-10-09 10:59:42 +02:00
Marin Atanasov Nikolov
d6459b8b84 client: Fix API example 2015-09-21 19:51:29 +03:00
Jonathan Boulle
7848ac3979 *: add missing license headers 2015-09-15 14:09:01 -07:00
Dmitry Smirnov
b2f4a5f587 *: fix spelling issues (codespell).
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2015-09-11 10:22:29 +10:00
Yicheng Qin
2f558e56d2 client: add Nodes to codecgen and regenerate 2015-09-10 11:51:59 -07:00
Yicheng Qin
eb51901830 client: add Nodes type to faciliate sorting
This helps users to sort easily.
2015-09-10 11:03:12 -07:00
Yicheng Qin
d412eaa3a2 Merge pull request #3308 from yichengq/go-codec
Use ugorji codec for unmarshalling key responses in client
2015-09-01 14:04:38 -07:00
Yicheng Qin
27b9963959 client: always cancel in-flight request when do request
This fits the way for go1.5 to cancel request.
2015-08-25 09:04:58 -07:00
Xiang Li
6b23a8131f *: test gofmt with -s and fix reported issues 2015-08-21 18:52:16 -07:00
Xiang Li
1dcc145aef client: fix test 2015-08-21 14:36:29 -07:00
Steve Phillips
952827157a client: fixed typo in WatcherOptions docs
specifices -> specifies
2015-08-18 16:43:09 -07:00
Steve Phillips
69fc796926 client: spelling error in docs (occured -> occurred) 2015-08-18 16:26:52 -07:00
Yicheng Qin
087061e434 Merge pull request #3303 from yichengq/auth-path
use canonical path for auth
2015-08-18 12:06:48 -07:00
Yicheng Qin
b5ec7f543a client: use canonical url path in request
The main change is that it keeps the trailing slash. This helps
auth feature to judge path permission accurately.
2015-08-18 08:59:48 -07:00
Xiang Li
87f061bab2 *: key handler should write auth error as etcd error 2015-08-17 14:45:45 -07:00
Yicheng Qin
7083828ae3 Godeps: import github.com/ugorji/go/codec 2015-08-16 18:13:44 -07:00
Yicheng Qin
a364af72af client: use ugorij/go/codec to unmarshal key response
This change speeds up response unmarshal ~2x:

```
BenchmarkSmallResponseUnmarshal	   20000	     75243 ns/op
BenchmarkManySmallResponseUnmarshal	     200	   6629661 ns/op
BenchmarkMediumResponseUnmarshal	    1000	   1359041 ns/op
BenchmarkLargeResponseUnmarshal	      20	  61600978 ns/op
```
2015-08-16 18:08:54 -07:00
Yicheng Qin
95d100e957 client: add response unmarshal benchmark
The benchmark result:

```
BenchmarkSmallResponseUnmarshal	  10000	   164524 ns/op
BenchmarkManySmallResponseUnmarshal	    100	 13916636 ns/op
BenchmarkMediumResponseUnmarshal	   1000	  1974295 ns/op
BenchmarkLargeResponseUnmarshal	     20	 80462001 ns/op
ok		github.com/coreos/etcd/client	7.777s
```
2015-08-16 16:44:50 -07:00
Yicheng Qin
5eed141d54 client: fix clusterError typo in README
It helps users to use client better.
2015-08-13 16:38:41 -07:00
Xiang Li
5d06d4ec44 client: print url as string 2015-08-12 10:09:40 -07:00
Yicheng Qin
7d618c46ad client: clean up README
Address rob's comments about sentences in README.
2015-08-11 15:33:56 -07:00
Yicheng Qin
dceacacd49 Merge pull request #3194 from yichengq/client-readme
client: add README
2015-08-11 13:35:54 -07:00
Yicheng Qin
8a7cf56e13 client: add README
It describes some basic usage and caveat of etcd/client package.

Write it together with Xiang.
2015-08-11 12:07:24 -07:00
Yicheng Qin
a1ef699aeb client: return context.DeadlineExceeded instead of ClusterError
This is done to match user expectation to see context.DeadlineExceeded
when it reaches deadline.
2015-08-11 10:18:38 -07:00
Yicheng Qin
f4c29a5f55 client: support to set timeout for each request
Add HeaderTimeout field in Config, so users could set timeout for each request.
Before this, one hanged request may block the call for long time. After
this, if the network is good, the user could set short timeout and expect
that API call can attempt next available endpoint quickly.
2015-08-11 10:01:05 -07:00
Yicheng Qin
0ab16db728 client: Sync() pin the endpoint when member list doesn't change
This helps client to pin the same endpoint as long as cluster doesn't change.
2015-08-07 10:08:28 -07:00
Xiang Li
b9c6b64d61 Merge pull request #3216 from yichengq/cancel-err
client: return context canceled error correctly
2015-08-06 15:04:49 -07:00
Yicheng Qin
78af793338 client: return context canceled error correctly
If the body is closed to stop watching, it will ignore the error from
reading body and return context error.

Before this PR, the cancel when watching always returns error `read tcp
127.0.0.1:57824: use of closed network connection`. After this PR, it
will return expected context canceled error.
2015-08-06 14:52:04 -07:00
Xiang Li
b04bb3e0ea Merge pull request #3229 from xiang90/f_cerr
client: return context.Canceled error when user cancels the request
2015-08-06 14:41:19 -07:00
Yicheng Qin
25ad71fbac Merge pull request #3225 from yichengq/client-record-err
client: return correct error for 50x response
2015-08-06 14:40:38 -07:00
Yicheng Qin
cfeaf3d172 client: return correct error for 50x response
etcd always returns 500/503 response when it may have no leader.
So we should log the other 50x response in a normal way.

This helps to log correctly when discovery meets 504 error. Before this
PR, it logs like this:

```
18:31:58 etcd2 | 2015/08/4 18:31:58 discovery: error #0: client: etcd
member https://discovery.etcd.io has no leader
18:31:58 etcd2 | 2015/08/4 18:31:58 discovery: waiting for other nodes:
error connecting to https://discovery.etcd.io, retrying in 4s
```

After this PR:

```
22:20:25 etcd2 | 2015/08/4 22:20:25 discovery: error #0: client: etcd
member https://discovery.etcd.io returns server error [Gateway Timeout]
22:20:25 etcd2 | 2015/08/4 22:20:25 discovery: waiting for other nodes:
error connecting to https://discovery.etcd.io, retrying in 4s
```
2015-08-06 14:25:03 -07:00
Xiang Li
9a8607fce1 Merge pull request #3187 from yichengq/client-keep-sync
client: add KeepSync function
2015-08-06 00:16:28 -07:00
Yicheng Qin
c53b3016ae client: add AutoSync function
AutoSync provides the way for client to syncing member list from
etcd cluster automatically.
2015-08-05 13:22:56 -07:00
Xiang Li
f38187bbdb client: return context.Canceled error when user cancels the request 2015-08-05 09:52:30 -07:00