mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #4507 from gyuho/better_hash
etcdserver: populate ResponseHeader in Hash method
This commit is contained in:
commit
93f2a4487a
@ -139,6 +139,7 @@ func (s *kvServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashRespons
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, togRPCError(err)
|
return nil, togRPCError(err)
|
||||||
}
|
}
|
||||||
|
s.fillInHeader(resp.Header)
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,13 +749,21 @@ func (m *HashRequest) String() string { return proto.CompactTextString(m) }
|
|||||||
func (*HashRequest) ProtoMessage() {}
|
func (*HashRequest) ProtoMessage() {}
|
||||||
|
|
||||||
type HashResponse struct {
|
type HashResponse struct {
|
||||||
Hash uint32 `protobuf:"varint,1,opt,name=hash,proto3" json:"hash,omitempty"`
|
Header *ResponseHeader `protobuf:"bytes,1,opt,name=header" json:"header,omitempty"`
|
||||||
|
Hash uint32 `protobuf:"varint,2,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *HashResponse) Reset() { *m = HashResponse{} }
|
func (m *HashResponse) Reset() { *m = HashResponse{} }
|
||||||
func (m *HashResponse) String() string { return proto.CompactTextString(m) }
|
func (m *HashResponse) String() string { return proto.CompactTextString(m) }
|
||||||
func (*HashResponse) ProtoMessage() {}
|
func (*HashResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (m *HashResponse) GetHeader() *ResponseHeader {
|
||||||
|
if m != nil {
|
||||||
|
return m.Header
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type WatchRequest struct {
|
type WatchRequest struct {
|
||||||
// Types that are valid to be assigned to RequestUnion:
|
// Types that are valid to be assigned to RequestUnion:
|
||||||
// *WatchRequest_CreateRequest
|
// *WatchRequest_CreateRequest
|
||||||
@ -2479,8 +2487,18 @@ func (m *HashResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
_ = i
|
_ = i
|
||||||
var l int
|
var l int
|
||||||
_ = l
|
_ = l
|
||||||
|
if m.Header != nil {
|
||||||
|
data[i] = 0xa
|
||||||
|
i++
|
||||||
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
|
n15, err := m.Header.MarshalTo(data[i:])
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i += n15
|
||||||
|
}
|
||||||
if m.Hash != 0 {
|
if m.Hash != 0 {
|
||||||
data[i] = 0x8
|
data[i] = 0x10
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Hash))
|
i = encodeVarintRpc(data, i, uint64(m.Hash))
|
||||||
}
|
}
|
||||||
@ -2503,11 +2521,11 @@ func (m *WatchRequest) MarshalTo(data []byte) (int, error) {
|
|||||||
var l int
|
var l int
|
||||||
_ = l
|
_ = l
|
||||||
if m.RequestUnion != nil {
|
if m.RequestUnion != nil {
|
||||||
nn15, err := m.RequestUnion.MarshalTo(data[i:])
|
nn16, err := m.RequestUnion.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += nn15
|
i += nn16
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -2518,11 +2536,11 @@ func (m *WatchRequest_CreateRequest) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.CreateRequest.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.CreateRequest.Size()))
|
||||||
n16, err := m.CreateRequest.MarshalTo(data[i:])
|
n17, err := m.CreateRequest.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n16
|
i += n17
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -2532,11 +2550,11 @@ func (m *WatchRequest_CancelRequest) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0x12
|
data[i] = 0x12
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.CancelRequest.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.CancelRequest.Size()))
|
||||||
n17, err := m.CancelRequest.MarshalTo(data[i:])
|
n18, err := m.CancelRequest.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n17
|
i += n18
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -2621,11 +2639,11 @@ func (m *WatchResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n18, err := m.Header.MarshalTo(data[i:])
|
n19, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n18
|
i += n19
|
||||||
}
|
}
|
||||||
if m.WatchId != 0 {
|
if m.WatchId != 0 {
|
||||||
data[i] = 0x10
|
data[i] = 0x10
|
||||||
@ -2719,11 +2737,11 @@ func (m *LeaseCreateResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n19, err := m.Header.MarshalTo(data[i:])
|
n20, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n19
|
i += n20
|
||||||
}
|
}
|
||||||
if m.ID != 0 {
|
if m.ID != 0 {
|
||||||
data[i] = 0x10
|
data[i] = 0x10
|
||||||
@ -2786,11 +2804,11 @@ func (m *LeaseRevokeResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n20, err := m.Header.MarshalTo(data[i:])
|
n21, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n20
|
i += n21
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -2837,11 +2855,11 @@ func (m *LeaseKeepAliveResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n21, err := m.Header.MarshalTo(data[i:])
|
n22, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n21
|
i += n22
|
||||||
}
|
}
|
||||||
if m.ID != 0 {
|
if m.ID != 0 {
|
||||||
data[i] = 0x10
|
data[i] = 0x10
|
||||||
@ -2977,21 +2995,21 @@ func (m *MemberAddResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n22, err := m.Header.MarshalTo(data[i:])
|
n23, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n22
|
i += n23
|
||||||
}
|
}
|
||||||
if m.Member != nil {
|
if m.Member != nil {
|
||||||
data[i] = 0x12
|
data[i] = 0x12
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Member.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Member.Size()))
|
||||||
n23, err := m.Member.MarshalTo(data[i:])
|
n24, err := m.Member.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n23
|
i += n24
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -3038,11 +3056,11 @@ func (m *MemberRemoveResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n24, err := m.Header.MarshalTo(data[i:])
|
n25, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n24
|
i += n25
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -3104,11 +3122,11 @@ func (m *MemberUpdateResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n25, err := m.Header.MarshalTo(data[i:])
|
n26, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n25
|
i += n26
|
||||||
}
|
}
|
||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
@ -3150,11 +3168,11 @@ func (m *MemberListResponse) MarshalTo(data []byte) (int, error) {
|
|||||||
data[i] = 0xa
|
data[i] = 0xa
|
||||||
i++
|
i++
|
||||||
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
i = encodeVarintRpc(data, i, uint64(m.Header.Size()))
|
||||||
n26, err := m.Header.MarshalTo(data[i:])
|
n27, err := m.Header.MarshalTo(data[i:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
i += n26
|
i += n27
|
||||||
}
|
}
|
||||||
if len(m.Members) > 0 {
|
if len(m.Members) > 0 {
|
||||||
for _, msg := range m.Members {
|
for _, msg := range m.Members {
|
||||||
@ -3518,6 +3536,10 @@ func (m *HashRequest) Size() (n int) {
|
|||||||
func (m *HashResponse) Size() (n int) {
|
func (m *HashResponse) Size() (n int) {
|
||||||
var l int
|
var l int
|
||||||
_ = l
|
_ = l
|
||||||
|
if m.Header != nil {
|
||||||
|
l = m.Header.Size()
|
||||||
|
n += 1 + l + sovRpc(uint64(l))
|
||||||
|
}
|
||||||
if m.Hash != 0 {
|
if m.Hash != 0 {
|
||||||
n += 1 + sovRpc(uint64(m.Hash))
|
n += 1 + sovRpc(uint64(m.Hash))
|
||||||
}
|
}
|
||||||
@ -5705,6 +5727,39 @@ func (m *HashResponse) Unmarshal(data []byte) error {
|
|||||||
}
|
}
|
||||||
switch fieldNum {
|
switch fieldNum {
|
||||||
case 1:
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Header", wireType)
|
||||||
|
}
|
||||||
|
var msglen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowRpc
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := data[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
msglen |= (int(b) & 0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msglen < 0 {
|
||||||
|
return ErrInvalidLengthRpc
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + msglen
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
if m.Header == nil {
|
||||||
|
m.Header = &ResponseHeader{}
|
||||||
|
}
|
||||||
|
if err := m.Header.Unmarshal(data[iNdEx:postIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
case 2:
|
||||||
if wireType != 0 {
|
if wireType != 0 {
|
||||||
return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType)
|
return fmt.Errorf("proto: wrong wireType = %d for field Hash", wireType)
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,8 @@ message HashRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message HashResponse {
|
message HashResponse {
|
||||||
uint32 hash = 1;
|
ResponseHeader header = 1;
|
||||||
|
uint32 hash = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message WatchRequest {
|
message WatchRequest {
|
||||||
|
@ -98,7 +98,15 @@ func (s *EtcdServer) Compact(ctx context.Context, r *pb.CompactionRequest) (*pb.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return result.resp.(*pb.CompactionResponse), result.err
|
resp := result.resp.(*pb.CompactionResponse)
|
||||||
|
if resp == nil {
|
||||||
|
resp = &pb.CompactionResponse{}
|
||||||
|
}
|
||||||
|
if resp.Header == nil {
|
||||||
|
resp.Header = &pb.ResponseHeader{}
|
||||||
|
}
|
||||||
|
resp.Header.Revision = s.kv.Rev()
|
||||||
|
return resp, result.err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EtcdServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) {
|
func (s *EtcdServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashResponse, error) {
|
||||||
@ -106,7 +114,7 @@ func (s *EtcdServer) Hash(ctx context.Context, r *pb.HashRequest) (*pb.HashRespo
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &pb.HashResponse{Hash: h}, nil
|
return &pb.HashResponse{Header: &pb.ResponseHeader{Revision: s.kv.Rev()}, Hash: h}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EtcdServer) LeaseCreate(ctx context.Context, r *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error) {
|
func (s *EtcdServer) LeaseCreate(ctx context.Context, r *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user