Skip to content

Commit

Permalink
Merge pull request #8263 from fanminshi/hash_by_rev
Browse files Browse the repository at this point in the history
api: hash by rev
  • Loading branch information
xiang90 committed Jul 26, 2017
2 parents ee1c340 + 8609521 commit 2a348fb
Show file tree
Hide file tree
Showing 12 changed files with 1,068 additions and 382 deletions.
38 changes: 33 additions & 5 deletions Documentation/dev-guide/apispec/swagger/rpc.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,23 +858,23 @@
"tags": [
"Maintenance"
],
"summary": "Hash returns the hash of the local KV state for consistency checking purpose.\nThis is designed for testing; do not use this in production when there\nare ongoing transactions.",
"operationId": "Hash",
"summary": "HashKV computes the hash of all MVCC keys up to a given revision.",
"operationId": "HashKV",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/etcdserverpbHashRequest"
"$ref": "#/definitions/etcdserverpbHashKVRequest"
}
}
],
"responses": {
"200": {
"description": "(empty)",
"schema": {
"$ref": "#/definitions/etcdserverpbHashResponse"
"$ref": "#/definitions/etcdserverpbHashKVResponse"
}
}
}
Expand Down Expand Up @@ -1552,14 +1552,42 @@
}
}
},
"etcdserverpbHashKVRequest": {
"type": "object",
"properties": {
"revision": {
"description": "revision is the key-value store revision for the hash operation.",
"type": "string",
"format": "int64"
}
}
},
"etcdserverpbHashKVResponse": {
"type": "object",
"properties": {
"compact_revision": {
"description": "compact_revision is the compacted revision of key-value store when hash begins.",
"type": "string",
"format": "int64"
},
"hash": {
"description": "hash is the hash value computed from the responding member's MVCC keys up to a given revision.",
"type": "integer",
"format": "int64"
},
"header": {
"$ref": "#/definitions/etcdserverpbResponseHeader"
}
}
},
"etcdserverpbHashRequest": {
"type": "object"
},
"etcdserverpbHashResponse": {
"type": "object",
"properties": {
"hash": {
"description": "hash is the hash value computed from the responding member's key-value store.",
"description": "hash is the hash value computed from the responding member's KV's backend.",
"type": "integer",
"format": "int64"
},
Expand Down
18 changes: 18 additions & 0 deletions etcdserver/api/v3rpc/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ func (ms *maintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.H
return resp, nil
}

func (ms *maintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) {
h, rev, compactRev, err := ms.kg.KV().HashByRev(r.Revision)
if err != nil {
return nil, togRPCError(err)
}

resp := &pb.HashKVResponse{Header: &pb.ResponseHeader{Revision: rev}, Hash: h, CompactRevision: compactRev}
ms.hdr.fill(resp.Header)
return resp, nil
}

func (ms *maintenanceServer) Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) {
return ms.a.Alarm(ctx, ar)
}
Expand Down Expand Up @@ -203,6 +214,13 @@ func (ams *authMaintenanceServer) Hash(ctx context.Context, r *pb.HashRequest) (
return ams.maintenanceServer.Hash(ctx, r)
}

func (ams *authMaintenanceServer) HashKV(ctx context.Context, r *pb.HashKVRequest) (*pb.HashKVResponse, error) {
if err := ams.isAuthenticated(ctx); err != nil {
return nil, err
}
return ams.maintenanceServer.HashKV(ctx, r)
}

func (ams *authMaintenanceServer) Status(ctx context.Context, ar *pb.StatusRequest) (*pb.StatusResponse, error) {
return ams.maintenanceServer.Status(ctx, ar)
}
Expand Down
2 changes: 2 additions & 0 deletions etcdserver/etcdserverpb/etcdserver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions etcdserver/etcdserverpb/gw/rpc.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2a348fb

Please sign in to comment.