v3_server.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package etcdserver
  15. import (
  16. "strconv"
  17. "strings"
  18. "time"
  19. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  20. "github.com/coreos/etcd/etcdserver/membership"
  21. "github.com/coreos/etcd/lease"
  22. "github.com/coreos/etcd/lease/leasehttp"
  23. "github.com/coreos/etcd/mvcc"
  24. "golang.org/x/net/context"
  25. "google.golang.org/grpc/metadata"
  26. )
  27. const (
  28. // the max request size that raft accepts.
  29. // TODO: make this a flag? But we probably do not want to
  30. // accept large request which might block raft stream. User
  31. // specify a large value might end up with shooting in the foot.
  32. maxRequestBytes = 1.5 * 1024 * 1024
  33. // max timeout for waiting a v3 request to go through raft.
  34. maxV3RequestTimeout = 5 * time.Second
  35. )
  36. type RaftKV interface {
  37. Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error)
  38. Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error)
  39. DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error)
  40. Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error)
  41. Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error)
  42. }
  43. type Lessor interface {
  44. // LeaseGrant sends LeaseGrant request to raft and apply it after committed.
  45. LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error)
  46. // LeaseRevoke sends LeaseRevoke request to raft and apply it after committed.
  47. LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error)
  48. // LeaseRenew renews the lease with given ID. The renewed TTL is returned. Or an error
  49. // is returned.
  50. LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error)
  51. }
  52. type Authenticator interface {
  53. AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error)
  54. AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error)
  55. Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error)
  56. UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error)
  57. UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error)
  58. UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error)
  59. UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error)
  60. UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error)
  61. UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error)
  62. RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error)
  63. RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error)
  64. RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error)
  65. RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error)
  66. RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error)
  67. UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error)
  68. RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error)
  69. }
  70. func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeResponse, error) {
  71. var result *applyResult
  72. var err error
  73. if r.Serializable {
  74. var user string
  75. user, err = s.usernameFromCtx(ctx)
  76. if err != nil {
  77. return nil, err
  78. }
  79. result = s.applyV3.Apply(
  80. &pb.InternalRaftRequest{
  81. Header: &pb.RequestHeader{Username: user},
  82. Range: r})
  83. } else {
  84. result, err = s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Range: r})
  85. }
  86. if err != nil {
  87. return nil, err
  88. }
  89. if result.err != nil {
  90. return nil, result.err
  91. }
  92. return result.resp.(*pb.RangeResponse), nil
  93. }
  94. func (s *EtcdServer) Put(ctx context.Context, r *pb.PutRequest) (*pb.PutResponse, error) {
  95. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Put: r})
  96. if err != nil {
  97. return nil, err
  98. }
  99. if result.err != nil {
  100. return nil, result.err
  101. }
  102. return result.resp.(*pb.PutResponse), nil
  103. }
  104. func (s *EtcdServer) DeleteRange(ctx context.Context, r *pb.DeleteRangeRequest) (*pb.DeleteRangeResponse, error) {
  105. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{DeleteRange: r})
  106. if err != nil {
  107. return nil, err
  108. }
  109. if result.err != nil {
  110. return nil, result.err
  111. }
  112. return result.resp.(*pb.DeleteRangeResponse), nil
  113. }
  114. func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse, error) {
  115. var result *applyResult
  116. var err error
  117. if isTxnSerializable(r) {
  118. user, err := s.usernameFromCtx(ctx)
  119. if err != nil {
  120. return nil, err
  121. }
  122. result = s.applyV3.Apply(
  123. &pb.InternalRaftRequest{
  124. Header: &pb.RequestHeader{Username: user},
  125. Txn: r})
  126. } else {
  127. result, err = s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Txn: r})
  128. }
  129. if err != nil {
  130. return nil, err
  131. }
  132. if result.err != nil {
  133. return nil, result.err
  134. }
  135. return result.resp.(*pb.TxnResponse), nil
  136. }
  137. func isTxnSerializable(r *pb.TxnRequest) bool {
  138. for _, u := range r.Success {
  139. if r := u.GetRequestRange(); r == nil || !r.Serializable {
  140. return false
  141. }
  142. }
  143. for _, u := range r.Failure {
  144. if r := u.GetRequestRange(); r == nil || !r.Serializable {
  145. return false
  146. }
  147. }
  148. return true
  149. }
  150. func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.CompactionResponse, error) {
  151. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Compaction: r})
  152. if r.Physical && result != nil && result.physc != nil {
  153. <-result.physc
  154. // The compaction is done deleting keys; the hash is now settled
  155. // but the data is not necessarily committed. If there's a crash,
  156. // the hash may revert to a hash prior to compaction completing
  157. // if the compaction resumes. Force the finished compaction to
  158. // commit so it won't resume following a crash.
  159. s.be.ForceCommit()
  160. }
  161. if err != nil {
  162. return nil, err
  163. }
  164. if result.err != nil {
  165. return nil, result.err
  166. }
  167. resp := result.resp.(*pb.CompactionResponse)
  168. if resp == nil {
  169. resp = &pb.CompactionResponse{}
  170. }
  171. if resp.Header == nil {
  172. resp.Header = &pb.ResponseHeader{}
  173. }
  174. resp.Header.Revision = s.kv.Rev()
  175. return resp, nil
  176. }
  177. func (s *EtcdServer) LeaseGrant(ctx context.Context, r *pb.LeaseGrantRequest) (*pb.LeaseGrantResponse, error) {
  178. // no id given? choose one
  179. for r.ID == int64(lease.NoLease) {
  180. // only use positive int64 id's
  181. r.ID = int64(s.reqIDGen.Next() & ((1 << 63) - 1))
  182. }
  183. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{LeaseGrant: r})
  184. if err != nil {
  185. return nil, err
  186. }
  187. if result.err != nil {
  188. return nil, result.err
  189. }
  190. return result.resp.(*pb.LeaseGrantResponse), nil
  191. }
  192. func (s *EtcdServer) LeaseRevoke(ctx context.Context, r *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) {
  193. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{LeaseRevoke: r})
  194. if err != nil {
  195. return nil, err
  196. }
  197. if result.err != nil {
  198. return nil, result.err
  199. }
  200. return result.resp.(*pb.LeaseRevokeResponse), nil
  201. }
  202. func (s *EtcdServer) LeaseRenew(ctx context.Context, id lease.LeaseID) (int64, error) {
  203. ttl, err := s.lessor.Renew(id)
  204. if err == nil {
  205. return ttl, nil
  206. }
  207. if err != lease.ErrNotPrimary {
  208. return -1, err
  209. }
  210. // renewals don't go through raft; forward to leader manually
  211. cctx, cancel := context.WithTimeout(ctx, s.Cfg.ReqTimeout())
  212. defer cancel()
  213. // renewals don't go through raft; forward to leader manually
  214. for cctx.Err() == nil && err != nil {
  215. leader, lerr := s.waitLeader(cctx)
  216. if lerr != nil {
  217. return -1, lerr
  218. }
  219. for _, url := range leader.PeerURLs {
  220. lurl := url + "/leases"
  221. ttl, err = leasehttp.RenewHTTP(cctx, id, lurl, s.peerRt)
  222. if err == nil || err == lease.ErrLeaseNotFound {
  223. return ttl, err
  224. }
  225. }
  226. }
  227. return -1, ErrTimeout
  228. }
  229. func (s *EtcdServer) waitLeader(ctx context.Context) (*membership.Member, error) {
  230. leader := s.cluster.Member(s.Leader())
  231. for leader == nil {
  232. // wait an election
  233. dur := time.Duration(s.Cfg.ElectionTicks) * time.Duration(s.Cfg.TickMs) * time.Millisecond
  234. select {
  235. case <-time.After(dur):
  236. leader = s.cluster.Member(s.Leader())
  237. case <-s.done:
  238. return nil, ErrStopped
  239. case <-ctx.Done():
  240. return nil, ErrNoLeader
  241. }
  242. }
  243. if leader == nil || len(leader.PeerURLs) == 0 {
  244. return nil, ErrNoLeader
  245. }
  246. return leader, nil
  247. }
  248. func (s *EtcdServer) Alarm(ctx context.Context, r *pb.AlarmRequest) (*pb.AlarmResponse, error) {
  249. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Alarm: r})
  250. if err != nil {
  251. return nil, err
  252. }
  253. if result.err != nil {
  254. return nil, result.err
  255. }
  256. return result.resp.(*pb.AlarmResponse), nil
  257. }
  258. func (s *EtcdServer) AuthEnable(ctx context.Context, r *pb.AuthEnableRequest) (*pb.AuthEnableResponse, error) {
  259. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthEnable: r})
  260. if err != nil {
  261. return nil, err
  262. }
  263. if result.err != nil {
  264. return nil, result.err
  265. }
  266. return result.resp.(*pb.AuthEnableResponse), nil
  267. }
  268. func (s *EtcdServer) AuthDisable(ctx context.Context, r *pb.AuthDisableRequest) (*pb.AuthDisableResponse, error) {
  269. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthDisable: r})
  270. if err != nil {
  271. return nil, err
  272. }
  273. if result.err != nil {
  274. return nil, result.err
  275. }
  276. return result.resp.(*pb.AuthDisableResponse), nil
  277. }
  278. func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest) (*pb.AuthenticateResponse, error) {
  279. st, err := s.AuthStore().GenSimpleToken()
  280. if err != nil {
  281. return nil, err
  282. }
  283. internalReq := &pb.InternalAuthenticateRequest{
  284. Name: r.Name,
  285. Password: r.Password,
  286. SimpleToken: st,
  287. }
  288. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{Authenticate: internalReq})
  289. if err != nil {
  290. return nil, err
  291. }
  292. if result.err != nil {
  293. return nil, result.err
  294. }
  295. return result.resp.(*pb.AuthenticateResponse), nil
  296. }
  297. func (s *EtcdServer) UserAdd(ctx context.Context, r *pb.AuthUserAddRequest) (*pb.AuthUserAddResponse, error) {
  298. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserAdd: r})
  299. if err != nil {
  300. return nil, err
  301. }
  302. if result.err != nil {
  303. return nil, result.err
  304. }
  305. return result.resp.(*pb.AuthUserAddResponse), nil
  306. }
  307. func (s *EtcdServer) UserDelete(ctx context.Context, r *pb.AuthUserDeleteRequest) (*pb.AuthUserDeleteResponse, error) {
  308. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserDelete: r})
  309. if err != nil {
  310. return nil, err
  311. }
  312. if result.err != nil {
  313. return nil, result.err
  314. }
  315. return result.resp.(*pb.AuthUserDeleteResponse), nil
  316. }
  317. func (s *EtcdServer) UserChangePassword(ctx context.Context, r *pb.AuthUserChangePasswordRequest) (*pb.AuthUserChangePasswordResponse, error) {
  318. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserChangePassword: r})
  319. if err != nil {
  320. return nil, err
  321. }
  322. if result.err != nil {
  323. return nil, result.err
  324. }
  325. return result.resp.(*pb.AuthUserChangePasswordResponse), nil
  326. }
  327. func (s *EtcdServer) UserGrantRole(ctx context.Context, r *pb.AuthUserGrantRoleRequest) (*pb.AuthUserGrantRoleResponse, error) {
  328. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserGrantRole: r})
  329. if err != nil {
  330. return nil, err
  331. }
  332. if result.err != nil {
  333. return nil, result.err
  334. }
  335. return result.resp.(*pb.AuthUserGrantRoleResponse), nil
  336. }
  337. func (s *EtcdServer) UserGet(ctx context.Context, r *pb.AuthUserGetRequest) (*pb.AuthUserGetResponse, error) {
  338. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserGet: r})
  339. if err != nil {
  340. return nil, err
  341. }
  342. if result.err != nil {
  343. return nil, result.err
  344. }
  345. return result.resp.(*pb.AuthUserGetResponse), nil
  346. }
  347. func (s *EtcdServer) UserList(ctx context.Context, r *pb.AuthUserListRequest) (*pb.AuthUserListResponse, error) {
  348. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserList: r})
  349. if err != nil {
  350. return nil, err
  351. }
  352. if result.err != nil {
  353. return nil, result.err
  354. }
  355. return result.resp.(*pb.AuthUserListResponse), nil
  356. }
  357. func (s *EtcdServer) UserRevokeRole(ctx context.Context, r *pb.AuthUserRevokeRoleRequest) (*pb.AuthUserRevokeRoleResponse, error) {
  358. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthUserRevokeRole: r})
  359. if err != nil {
  360. return nil, err
  361. }
  362. if result.err != nil {
  363. return nil, result.err
  364. }
  365. return result.resp.(*pb.AuthUserRevokeRoleResponse), nil
  366. }
  367. func (s *EtcdServer) RoleAdd(ctx context.Context, r *pb.AuthRoleAddRequest) (*pb.AuthRoleAddResponse, error) {
  368. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthRoleAdd: r})
  369. if err != nil {
  370. return nil, err
  371. }
  372. if result.err != nil {
  373. return nil, result.err
  374. }
  375. return result.resp.(*pb.AuthRoleAddResponse), nil
  376. }
  377. func (s *EtcdServer) RoleGrantPermission(ctx context.Context, r *pb.AuthRoleGrantPermissionRequest) (*pb.AuthRoleGrantPermissionResponse, error) {
  378. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthRoleGrantPermission: r})
  379. if err != nil {
  380. return nil, err
  381. }
  382. if result.err != nil {
  383. return nil, result.err
  384. }
  385. return result.resp.(*pb.AuthRoleGrantPermissionResponse), nil
  386. }
  387. func (s *EtcdServer) RoleGet(ctx context.Context, r *pb.AuthRoleGetRequest) (*pb.AuthRoleGetResponse, error) {
  388. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthRoleGet: r})
  389. if err != nil {
  390. return nil, err
  391. }
  392. if result.err != nil {
  393. return nil, result.err
  394. }
  395. return result.resp.(*pb.AuthRoleGetResponse), nil
  396. }
  397. func (s *EtcdServer) RoleList(ctx context.Context, r *pb.AuthRoleListRequest) (*pb.AuthRoleListResponse, error) {
  398. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthRoleList: r})
  399. if err != nil {
  400. return nil, err
  401. }
  402. if result.err != nil {
  403. return nil, result.err
  404. }
  405. return result.resp.(*pb.AuthRoleListResponse), nil
  406. }
  407. func (s *EtcdServer) RoleRevokePermission(ctx context.Context, r *pb.AuthRoleRevokePermissionRequest) (*pb.AuthRoleRevokePermissionResponse, error) {
  408. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthRoleRevokePermission: r})
  409. if err != nil {
  410. return nil, err
  411. }
  412. if result.err != nil {
  413. return nil, result.err
  414. }
  415. return result.resp.(*pb.AuthRoleRevokePermissionResponse), nil
  416. }
  417. func (s *EtcdServer) RoleDelete(ctx context.Context, r *pb.AuthRoleDeleteRequest) (*pb.AuthRoleDeleteResponse, error) {
  418. result, err := s.processInternalRaftRequest(ctx, pb.InternalRaftRequest{AuthRoleDelete: r})
  419. if err != nil {
  420. return nil, err
  421. }
  422. if result.err != nil {
  423. return nil, result.err
  424. }
  425. return result.resp.(*pb.AuthRoleDeleteResponse), nil
  426. }
  427. func (s *EtcdServer) isValidSimpleToken(token string) bool {
  428. splitted := strings.Split(token, ".")
  429. if len(splitted) != 2 {
  430. return false
  431. }
  432. index, err := strconv.Atoi(splitted[1])
  433. if err != nil {
  434. return false
  435. }
  436. // CAUTION: below index synchronization is required because this node
  437. // might not receive and apply the log entry of Authenticate() RPC.
  438. authApplied := false
  439. for i := 0; i < 10; i++ {
  440. if uint64(index) <= s.getAppliedIndex() {
  441. authApplied = true
  442. break
  443. }
  444. time.Sleep(100 * time.Millisecond)
  445. }
  446. if !authApplied {
  447. plog.Errorf("timeout of waiting Authenticate() RPC")
  448. return false
  449. }
  450. return true
  451. }
  452. func (s *EtcdServer) usernameFromCtx(ctx context.Context) (string, error) {
  453. md, ok := metadata.FromContext(ctx)
  454. if !ok {
  455. return "", nil
  456. }
  457. ts, tok := md["token"]
  458. if !tok {
  459. return "", nil
  460. }
  461. token := ts[0]
  462. if !s.isValidSimpleToken(token) {
  463. return "", ErrInvalidAuthToken
  464. }
  465. username, uok := s.AuthStore().UsernameFromToken(token)
  466. if !uok {
  467. plog.Warningf("invalid auth token: %s", token)
  468. return "", ErrInvalidAuthToken
  469. }
  470. return username, nil
  471. }
  472. func (s *EtcdServer) processInternalRaftRequest(ctx context.Context, r pb.InternalRaftRequest) (*applyResult, error) {
  473. r.Header = &pb.RequestHeader{
  474. ID: s.reqIDGen.Next(),
  475. }
  476. username, err := s.usernameFromCtx(ctx)
  477. if err != nil {
  478. return nil, err
  479. }
  480. r.Header.Username = username
  481. data, err := r.Marshal()
  482. if err != nil {
  483. return nil, err
  484. }
  485. if len(data) > maxRequestBytes {
  486. return nil, ErrRequestTooLarge
  487. }
  488. id := r.ID
  489. if id == 0 {
  490. id = r.Header.ID
  491. }
  492. ch := s.w.Register(id)
  493. cctx, cancel := context.WithTimeout(ctx, maxV3RequestTimeout)
  494. defer cancel()
  495. start := time.Now()
  496. s.r.Propose(cctx, data)
  497. proposalsPending.Inc()
  498. defer proposalsPending.Dec()
  499. select {
  500. case x := <-ch:
  501. return x.(*applyResult), nil
  502. case <-cctx.Done():
  503. proposalsFailed.Inc()
  504. s.w.Trigger(id, nil) // GC wait
  505. return nil, s.parseProposeCtxErr(cctx.Err(), start)
  506. case <-s.done:
  507. return nil, ErrStopped
  508. }
  509. }
  510. // Watchable returns a watchable interface attached to the etcdserver.
  511. func (s *EtcdServer) Watchable() mvcc.WatchableKV { return s.KV() }