Skip to content
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

*: serve member list API with linearizable guarantee #11639

Merged
merged 1 commit into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG-3.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.4.0...v3.5.0) and

### Breaking Changes

- Changed behavior of clienv3 API [MemberList](https://github.com/etcd-io/etcd/pull/11639).
- Previously, it is directly served with server's local data, which could be stale.
- Now, it is served with linearizable guarantee. If the server is disconnected from quorum, `MemberList` call will fail.
- [gRPC gateway](https://github.com/grpc-ecosystem/grpc-gateway) only supports [`/v3`](TODO) endpoint.
- Deprecated [`/v3beta`](https://github.com/etcd-io/etcd/pull/9298).
- `curl -L http://localhost:2379/v3beta/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'` does work in v3.5. Use `curl -L http://localhost:2379/v3/kv/put -X POST -d '{"key": "Zm9v", "value": "YmFy"}'` instead.
Expand Down Expand Up @@ -135,6 +138,7 @@ Note that any `etcd_debugging_*` metrics are experimental and subject to change.
### API

- Add [`/v3/auth/status`](https://github.com/etcd-io/etcd/pull/11536) endpoint to check if authentication is enabled
- [Add `Linearizable` field to `etcdserverpb.MemberListRequest`](https://github.com/etcd-io/etcd/pull/11639).


### Dependency
Expand Down
4 changes: 3 additions & 1 deletion Documentation/dev-guide/api_reference_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ Empty field.

##### message `MemberListRequest` (etcdserver/etcdserverpb/rpc.proto)

Empty field.
| Field | Description | Type |
| ----- | ----------- | ---- |
| linearizable | | bool |



Expand Down
8 changes: 7 additions & 1 deletion Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2365,7 +2365,13 @@
}
},
"etcdserverpbMemberListRequest": {
"type": "object"
"type": "object",
"properties": {
"linearizable": {
"type": "boolean",
"format": "boolean"
}
}
},
"etcdserverpbMemberListResponse": {
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion clientv3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *cluster) MemberUpdate(ctx context.Context, id uint64, peerAddrs []strin

func (c *cluster) MemberList(ctx context.Context) (*MemberListResponse, error) {
// it is safe to retry on list.
resp, err := c.remote.MemberList(ctx, &pb.MemberListRequest{}, c.callOpts...)
resp, err := c.remote.MemberList(ctx, &pb.MemberListRequest{Linearizable: true}, c.callOpts...)
if err == nil {
return (*MemberListResponse)(resp), nil
}
Expand Down
9 changes: 7 additions & 2 deletions etcdserver/api/v3rpc/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (

type ClusterServer struct {
cluster api.Cluster
server etcdserver.ServerV3
server *etcdserver.EtcdServer
}

func NewClusterServer(s etcdserver.ServerV3) *ClusterServer {
func NewClusterServer(s *etcdserver.EtcdServer) *ClusterServer {
return &ClusterServer{
cluster: s.Cluster(),
server: s,
Expand Down Expand Up @@ -88,6 +88,11 @@ func (cs *ClusterServer) MemberUpdate(ctx context.Context, r *pb.MemberUpdateReq
}

func (cs *ClusterServer) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) {
if r.Linearizable {
if err := cs.server.LinearizableReadNotify(ctx); err != nil {
return nil, togRPCError(err)
}
}
membs := membersToProtoMembers(cs.cluster.Members())
return &pb.MemberListResponse{Header: cs.header(), Members: membs}, nil
}
Expand Down
550 changes: 296 additions & 254 deletions etcdserver/etcdserverpb/rpc.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions etcdserver/etcdserverpb/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ message MemberUpdateResponse{
}

message MemberListRequest {
bool linearizable = 1;
}

message MemberListResponse {
Expand Down
4 changes: 4 additions & 0 deletions etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ func (s *EtcdServer) linearizableReadLoop() {
}
}

func (s *EtcdServer) LinearizableReadNotify(ctx context.Context) error {
return s.linearizableReadNotify(ctx)
}

func (s *EtcdServer) linearizableReadNotify(ctx context.Context) error {
s.readMu.RLock()
nc := s.readNotifier
Expand Down