diff --git a/.github/workflows/PR.yaml b/.github/workflows/PR.yaml new file mode 100644 index 0000000..7a1f890 --- /dev/null +++ b/.github/workflows/PR.yaml @@ -0,0 +1,32 @@ +on: + pull_request: + branches: + - master + +jobs: + build: + name: build + runs-on: ubuntu-latest + container: + image: golang:1.14-buster + volumes: + - "/home/runner/work/$GITHUB_REPOSITORY:/go/src/github.com/$GITHUB_REPOSITORY" + steps: + - uses: actions/checkout@v1 + + - name: restore from cache + uses: actions/cache@v1 + with: + path: /go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + + - name: download dependencies if not cached + run: | + if [ ! -d "/go/pkg/mod" ]; then + go mod tidy + fi + + - name: test + run: go test -race -covermode=atomic -coverprofile coverage.out -v $(go list ./...) diff --git a/CHANGES.md b/CHANGES.md index 3108b8f..6fc2348 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- adds scan endpoint #35 @vniche - Fix bug in getting leader ID #34 @mosuka ## [v0.3.1] 2020-04-01 diff --git a/protobuf/kvs.pb.go b/protobuf/kvs.pb.go index 3bb6c8d..4a13f1e 100644 --- a/protobuf/kvs.pb.go +++ b/protobuf/kvs.pb.go @@ -59,7 +59,7 @@ func (x Event_Type) String() string { } func (Event_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{15, 0} + return fileDescriptor_431078ad7b21f851, []int{17, 0} } type LivenessCheckResponse struct { @@ -531,6 +531,84 @@ func (m *GetResponse) GetValue() []byte { return nil } +type ScanRequest struct { + Prefix string `protobuf:"bytes,1,opt,name=prefix,proto3" json:"prefix,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ScanRequest) Reset() { *m = ScanRequest{} } +func (m *ScanRequest) String() string { return proto.CompactTextString(m) } +func (*ScanRequest) ProtoMessage() {} +func (*ScanRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_431078ad7b21f851, []int{11} +} + +func (m *ScanRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ScanRequest.Unmarshal(m, b) +} +func (m *ScanRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ScanRequest.Marshal(b, m, deterministic) +} +func (m *ScanRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScanRequest.Merge(m, src) +} +func (m *ScanRequest) XXX_Size() int { + return xxx_messageInfo_ScanRequest.Size(m) +} +func (m *ScanRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ScanRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ScanRequest proto.InternalMessageInfo + +func (m *ScanRequest) GetPrefix() string { + if m != nil { + return m.Prefix + } + return "" +} + +type ScanResponse struct { + Values [][]byte `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ScanResponse) Reset() { *m = ScanResponse{} } +func (m *ScanResponse) String() string { return proto.CompactTextString(m) } +func (*ScanResponse) ProtoMessage() {} +func (*ScanResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_431078ad7b21f851, []int{12} +} + +func (m *ScanResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ScanResponse.Unmarshal(m, b) +} +func (m *ScanResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ScanResponse.Marshal(b, m, deterministic) +} +func (m *ScanResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScanResponse.Merge(m, src) +} +func (m *ScanResponse) XXX_Size() int { + return xxx_messageInfo_ScanResponse.Size(m) +} +func (m *ScanResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ScanResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ScanResponse proto.InternalMessageInfo + +func (m *ScanResponse) GetValues() [][]byte { + if m != nil { + return m.Values + } + return nil +} + type SetRequest struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` @@ -543,7 +621,7 @@ func (m *SetRequest) Reset() { *m = SetRequest{} } func (m *SetRequest) String() string { return proto.CompactTextString(m) } func (*SetRequest) ProtoMessage() {} func (*SetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{11} + return fileDescriptor_431078ad7b21f851, []int{13} } func (m *SetRequest) XXX_Unmarshal(b []byte) error { @@ -589,7 +667,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} } func (m *DeleteRequest) String() string { return proto.CompactTextString(m) } func (*DeleteRequest) ProtoMessage() {} func (*DeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{12} + return fileDescriptor_431078ad7b21f851, []int{14} } func (m *DeleteRequest) XXX_Unmarshal(b []byte) error { @@ -629,7 +707,7 @@ func (m *SetMetadataRequest) Reset() { *m = SetMetadataRequest{} } func (m *SetMetadataRequest) String() string { return proto.CompactTextString(m) } func (*SetMetadataRequest) ProtoMessage() {} func (*SetMetadataRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{13} + return fileDescriptor_431078ad7b21f851, []int{15} } func (m *SetMetadataRequest) XXX_Unmarshal(b []byte) error { @@ -675,7 +753,7 @@ func (m *DeleteMetadataRequest) Reset() { *m = DeleteMetadataRequest{} } func (m *DeleteMetadataRequest) String() string { return proto.CompactTextString(m) } func (*DeleteMetadataRequest) ProtoMessage() {} func (*DeleteMetadataRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{14} + return fileDescriptor_431078ad7b21f851, []int{16} } func (m *DeleteMetadataRequest) XXX_Unmarshal(b []byte) error { @@ -715,7 +793,7 @@ func (m *Event) Reset() { *m = Event{} } func (m *Event) String() string { return proto.CompactTextString(m) } func (*Event) ProtoMessage() {} func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{15} + return fileDescriptor_431078ad7b21f851, []int{17} } func (m *Event) XXX_Unmarshal(b []byte) error { @@ -761,7 +839,7 @@ func (m *WatchResponse) Reset() { *m = WatchResponse{} } func (m *WatchResponse) String() string { return proto.CompactTextString(m) } func (*WatchResponse) ProtoMessage() {} func (*WatchResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{16} + return fileDescriptor_431078ad7b21f851, []int{18} } func (m *WatchResponse) XXX_Unmarshal(b []byte) error { @@ -800,7 +878,7 @@ func (m *MetricsResponse) Reset() { *m = MetricsResponse{} } func (m *MetricsResponse) String() string { return proto.CompactTextString(m) } func (*MetricsResponse) ProtoMessage() {} func (*MetricsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{17} + return fileDescriptor_431078ad7b21f851, []int{19} } func (m *MetricsResponse) XXX_Unmarshal(b []byte) error { @@ -840,7 +918,7 @@ func (m *KeyValuePair) Reset() { *m = KeyValuePair{} } func (m *KeyValuePair) String() string { return proto.CompactTextString(m) } func (*KeyValuePair) ProtoMessage() {} func (*KeyValuePair) Descriptor() ([]byte, []int) { - return fileDescriptor_431078ad7b21f851, []int{18} + return fileDescriptor_431078ad7b21f851, []int{20} } func (m *KeyValuePair) XXX_Unmarshal(b []byte) error { @@ -889,6 +967,8 @@ func init() { proto.RegisterType((*ClusterResponse)(nil), "kvs.ClusterResponse") proto.RegisterType((*GetRequest)(nil), "kvs.GetRequest") proto.RegisterType((*GetResponse)(nil), "kvs.GetResponse") + proto.RegisterType((*ScanRequest)(nil), "kvs.ScanRequest") + proto.RegisterType((*ScanResponse)(nil), "kvs.ScanResponse") proto.RegisterType((*SetRequest)(nil), "kvs.SetRequest") proto.RegisterType((*DeleteRequest)(nil), "kvs.DeleteRequest") proto.RegisterType((*SetMetadataRequest)(nil), "kvs.SetMetadataRequest") @@ -899,79 +979,85 @@ func init() { proto.RegisterType((*KeyValuePair)(nil), "kvs.KeyValuePair") } -func init() { proto.RegisterFile("protobuf/kvs.proto", fileDescriptor_431078ad7b21f851) } +func init() { + proto.RegisterFile("protobuf/kvs.proto", fileDescriptor_431078ad7b21f851) +} var fileDescriptor_431078ad7b21f851 = []byte{ - // 955 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x56, 0xdd, 0x6e, 0x1b, 0x55, - 0x10, 0xae, 0xff, 0x62, 0x67, 0xec, 0x24, 0xdb, 0x89, 0x13, 0xdc, 0x4d, 0x49, 0x9b, 0x53, 0x09, - 0x82, 0xc1, 0x5e, 0x1a, 0x10, 0x3f, 0x11, 0xbd, 0x28, 0x26, 0xaa, 0x44, 0x5d, 0x1a, 0xad, 0xa1, - 0x48, 0xdc, 0x44, 0x27, 0xde, 0xa9, 0xbd, 0xd8, 0xde, 0x5d, 0x76, 0x8f, 0x5d, 0x59, 0x55, 0x6f, - 0x78, 0x05, 0xc4, 0xcb, 0xf0, 0x1a, 0xbc, 0x02, 0x0f, 0x82, 0xce, 0xd9, 0xb3, 0x5e, 0x3b, 0xf6, - 0xb6, 0xbd, 0x8a, 0xcf, 0xcc, 0x37, 0xdf, 0x7c, 0x3b, 0x7f, 0x0a, 0x60, 0x10, 0xfa, 0xc2, 0xbf, - 0x9e, 0xbe, 0xb4, 0x46, 0xb3, 0xa8, 0xad, 0x1e, 0x58, 0x18, 0xcd, 0x22, 0xf3, 0xce, 0xc0, 0xf7, - 0x07, 0x63, 0xb2, 0x16, 0x7e, 0xee, 0xcd, 0x63, 0xbf, 0x79, 0x74, 0xd3, 0x45, 0x93, 0x40, 0x24, - 0xce, 0xbb, 0xda, 0xc9, 0x03, 0xd7, 0xe2, 0x9e, 0xe7, 0x0b, 0x2e, 0x5c, 0xdf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 0x22, 0x9c, 0xdb, 0x31, 0x0a, 0x0f, 0x61, 0x6b, 0x4c, 0xdc, 0xa1, 0x50, - 0x7f, 0x83, 0x7e, 0x99, 0x1d, 0x80, 0x14, 0x8c, 0x06, 0x14, 0x46, 0x34, 0xd7, 0xda, 0xe5, 0x4f, - 0xbc, 0x07, 0xa5, 0x19, 0x1f, 0x4f, 0x49, 0x0b, 0xde, 0x56, 0x69, 0x64, 0x84, 0x1d, 0xdb, 0xcf, - 0xf3, 0xdf, 0xe4, 0xd8, 0x77, 0x50, 0xfd, 0xd1, 0x77, 0x3d, 0x9b, 0xfe, 0x98, 0x52, 0x24, 0x70, - 0x17, 0xf2, 0xae, 0xa3, 0x49, 0xf2, 0xae, 0x83, 0x1f, 0x42, 0x51, 0x8a, 0x58, 0xa7, 0x50, 0x66, - 0x76, 0x0c, 0xb5, 0x2e, 0xf1, 0x19, 0x65, 0x84, 0xb3, 0x16, 0xd4, 0x14, 0x3a, 0xe9, 0x6c, 0x42, - 0x97, 0xdb, 0x4c, 0xf7, 0x2d, 0xec, 0xe9, 0x32, 0x2c, 0x22, 0x3e, 0x82, 0x72, 0x3f, 0x36, 0xe9, - 0xa0, 0xda, 0x72, 0xb5, 0xec, 0xc4, 0xc9, 0x8e, 0x01, 0x9e, 0x90, 0x48, 0x74, 0xac, 0x15, 0x83, - 0x3d, 0x80, 0xaa, 0xf2, 0xa7, 0x23, 0x16, 0xd7, 0x46, 0x42, 0x6a, 0xba, 0x20, 0xec, 0x4b, 0x80, - 0xde, 0x5b, 0x48, 0xd2, 0xa8, 0xfc, 0x72, 0xd4, 0x09, 0xec, 0xfc, 0x40, 0x63, 0x12, 0x94, 0x9d, - 0xfd, 0x39, 0x60, 0x8f, 0xc4, 0x62, 0x58, 0x32, 0x8a, 0xfd, 0xfe, 0x43, 0xc6, 0x3e, 0x86, 0x83, - 0x38, 0xe7, 0x3b, 0x38, 0xe5, 0xdc, 0x95, 0x2e, 0x66, 0xe4, 0x09, 0x7c, 0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xbe, 0x32, 0x39, 0xb5, 0xbc, 0xe6, - 0x06, 0x79, 0x5f, 0x43, 0x49, 0x6d, 0x73, 0x66, 0xc9, 0xe2, 0x3c, 0x2b, 0x1b, 0xcf, 0x6e, 0x7d, - 0x9e, 0x93, 0xa3, 0xa0, 0x77, 0xfa, 0x1d, 0xa3, 0x70, 0x63, 0xf3, 0x57, 0x47, 0x41, 0x2f, 0xfd, - 0xf7, 0x27, 0xbf, 0xdd, 0x1b, 0xb8, 0x62, 0x38, 0xbd, 0x6e, 0xf7, 0xfd, 0x89, 0x35, 0xf1, 0xa3, - 0xe9, 0x88, 0x5b, 0x7d, 0x12, 0xe9, 0x3f, 0x3f, 0xd7, 0x5b, 0xea, 0xd7, 0x17, 0xff, 0x07, 0x00, - 0x00, 0xff, 0xff, 0x89, 0x53, 0x3c, 0xa1, 0x4a, 0x09, 0x00, 0x00, + // 1016 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x56, 0xdd, 0x6e, 0xdb, 0x46, + 0x13, 0x8d, 0xfe, 0x6c, 0x79, 0x24, 0xdb, 0xcc, 0x58, 0xd6, 0xe7, 0xd0, 0xf9, 0x9c, 0x78, 0x83, + 0xa6, 0xae, 0x5b, 0x8b, 0x8d, 0x5b, 0xf4, 0xc7, 0x68, 0x2e, 0x52, 0xd7, 0x08, 0xda, 0x38, 0x8d, + 0x41, 0xb5, 0x29, 0xd0, 0x1b, 0x63, 0x4d, 0x8e, 0x65, 0x56, 0x32, 0xc9, 0x92, 0x2b, 0xa5, 0x42, + 0x90, 0x9b, 0x02, 0x7d, 0x82, 0xa2, 0x4f, 0xd6, 0x57, 0xe8, 0x83, 0x14, 0xfb, 0x43, 0x51, 0xb2, + 0xc4, 0x26, 0x57, 0xe2, 0xee, 0x9c, 0x3d, 0x73, 0x76, 0x66, 0xf6, 0x40, 0x80, 0x71, 0x12, 0x89, + 0xe8, 0x62, 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90, 0x29, 0x72, 0x27, 0x61, 0xa9, 0x3e, + 0x15, 0x5c, 0xd0, 0x56, 0x45, 0xd1, 0xe8, 0x05, 0xfb, 0xab, 0x04, 0xcb, 0xc7, 0x83, 0x61, 0x2a, + 0x28, 0xc1, 0x03, 0xa8, 0x85, 0x91, 0x4f, 0x32, 0x51, 0x65, 0xaf, 0x71, 0xf8, 0x3f, 0xc5, 0x64, + 0x82, 0x1d, 0xa9, 0x28, 0x3d, 0x09, 0x45, 0x32, 0x76, 0x35, 0x0a, 0xdb, 0xb0, 0x34, 0x20, 0xee, + 0x53, 0x62, 0xee, 0x60, 0x56, 0xf6, 0x31, 0x40, 0x0e, 0x46, 0x0b, 0x2a, 0x7d, 0x1a, 0x1b, 0xed, + 0xf2, 0x13, 0xef, 0x41, 0x6d, 0xc4, 0x07, 0x43, 0x32, 0x82, 0x57, 0x54, 0x1a, 0x79, 0xc2, 0xd5, + 0xfb, 0x47, 0xe5, 0x2f, 0x4a, 0xec, 0x2b, 0x68, 0x7c, 0x17, 0x05, 0xa1, 0x4b, 0xbf, 0x0e, 0x29, + 0x15, 0xb8, 0x06, 0xe5, 0xc0, 0x37, 0x24, 0xe5, 0xc0, 0xc7, 0xff, 0x43, 0x55, 0x8a, 0x98, 0xa7, + 0x50, 0xdb, 0x6c, 0x07, 0x9a, 0xa7, 0xc4, 0x47, 0x54, 0x70, 0x9c, 0x1d, 0x40, 0x53, 0xa1, 0xb3, + 0xce, 0x66, 0x74, 0xa5, 0xc5, 0x74, 0x5f, 0xc2, 0xba, 0x29, 0xc3, 0xe4, 0xc4, 0x43, 0x58, 0xf6, + 0xf4, 0x96, 0x39, 0xd4, 0x9c, 0xae, 0x96, 0x9b, 0x05, 0xd9, 0x0e, 0xc0, 0x53, 0x12, 0x99, 0x8e, + 0xb9, 0x62, 0xb0, 0x07, 0xd0, 0x50, 0xf1, 0x7c, 0xc4, 0x74, 0x6d, 0x24, 0xa4, 0x69, 0x0a, 0xc2, + 0xde, 0x83, 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09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConn +var _ grpc.ClientConnInterface // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +const _ = grpc.SupportPackageIsVersion6 // KVSClient is the client API for KVS service. // @@ -985,6 +1071,7 @@ type KVSClient interface { Leave(ctx context.Context, in *LeaveRequest, opts ...grpc.CallOption) (*empty.Empty, error) Snapshot(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) + Scan(ctx context.Context, in *ScanRequest, opts ...grpc.CallOption) (*ScanResponse, error) Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*empty.Empty, error) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*empty.Empty, error) Watch(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (KVS_WatchClient, error) @@ -992,10 +1079,10 @@ type KVSClient interface { } type kVSClient struct { - cc *grpc.ClientConn + cc grpc.ClientConnInterface } -func NewKVSClient(cc *grpc.ClientConn) KVSClient { +func NewKVSClient(cc grpc.ClientConnInterface) KVSClient { return &kVSClient{cc} } @@ -1071,6 +1158,15 @@ func (c *kVSClient) Get(ctx context.Context, in *GetRequest, opts ...grpc.CallOp return out, nil } +func (c *kVSClient) Scan(ctx context.Context, in *ScanRequest, opts ...grpc.CallOption) (*ScanResponse, error) { + out := new(ScanResponse) + err := c.cc.Invoke(ctx, "/kvs.KVS/Scan", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *kVSClient) Set(ctx context.Context, in *SetRequest, opts ...grpc.CallOption) (*empty.Empty, error) { out := new(empty.Empty) err := c.cc.Invoke(ctx, "/kvs.KVS/Set", in, out, opts...) @@ -1140,6 +1236,7 @@ type KVSServer interface { Leave(context.Context, *LeaveRequest) (*empty.Empty, error) Snapshot(context.Context, *empty.Empty) (*empty.Empty, error) Get(context.Context, *GetRequest) (*GetResponse, error) + Scan(context.Context, *ScanRequest) (*ScanResponse, error) Set(context.Context, *SetRequest) (*empty.Empty, error) Delete(context.Context, *DeleteRequest) (*empty.Empty, error) Watch(*empty.Empty, KVS_WatchServer) error @@ -1174,6 +1271,9 @@ func (*UnimplementedKVSServer) Snapshot(ctx context.Context, req *empty.Empty) ( func (*UnimplementedKVSServer) Get(ctx context.Context, req *GetRequest) (*GetResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Get not implemented") } +func (*UnimplementedKVSServer) Scan(ctx context.Context, req *ScanRequest) (*ScanResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Scan not implemented") +} func (*UnimplementedKVSServer) Set(ctx context.Context, req *SetRequest) (*empty.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method Set not implemented") } @@ -1335,6 +1435,24 @@ func _KVS_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{} return interceptor(ctx, in, info, handler) } +func _KVS_Scan_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ScanRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(KVSServer).Scan(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/kvs.KVS/Scan", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(KVSServer).Scan(ctx, req.(*ScanRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _KVS_Set_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SetRequest) if err := dec(in); err != nil { @@ -1446,6 +1564,10 @@ var _KVS_serviceDesc = grpc.ServiceDesc{ MethodName: "Get", Handler: _KVS_Get_Handler, }, + { + MethodName: "Scan", + Handler: _KVS_Scan_Handler, + }, { MethodName: "Set", Handler: _KVS_Set_Handler, diff --git a/protobuf/kvs.pb.gw.go b/protobuf/kvs.pb.gw.go index 40321a4..31464cd 100644 --- a/protobuf/kvs.pb.gw.go +++ b/protobuf/kvs.pb.gw.go @@ -300,6 +300,60 @@ func local_request_KVS_Get_0(ctx context.Context, marshaler runtime.Marshaler, s } +func request_KVS_Scan_0(ctx context.Context, marshaler runtime.Marshaler, client KVSClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ScanRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["prefix"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "prefix") + } + + protoReq.Prefix, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "prefix", err) + } + + msg, err := client.Scan(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_KVS_Scan_0(ctx context.Context, marshaler runtime.Marshaler, server KVSServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ScanRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["prefix"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "prefix") + } + + protoReq.Prefix, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "prefix", err) + } + + msg, err := server.Scan(ctx, &protoReq) + return msg, metadata, err + +} + func request_KVS_Set_0(ctx context.Context, marshaler runtime.Marshaler, client KVSClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SetRequest var metadata runtime.ServerMetadata @@ -607,6 +661,26 @@ func RegisterKVSHandlerServer(ctx context.Context, mux *runtime.ServeMux, server }) + mux.Handle("GET", pattern_KVS_Scan_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_KVS_Scan_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_KVS_Scan_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("PUT", pattern_KVS_Set_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -868,6 +942,26 @@ func RegisterKVSHandlerClient(ctx context.Context, mux *runtime.ServeMux, client }) + mux.Handle("GET", pattern_KVS_Scan_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_KVS_Scan_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_KVS_Scan_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("PUT", pattern_KVS_Set_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -948,6 +1042,8 @@ var ( pattern_KVS_Get_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 3, 0, 4, 1, 5, 2}, []string{"v1", "data", "key"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_KVS_Scan_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 3, 0, 4, 1, 5, 2}, []string{"v1", "data", "prefix"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_KVS_Set_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 3, 0, 4, 1, 5, 2}, []string{"v1", "data", "key"}, "", runtime.AssumeColonVerbOpt(true))) pattern_KVS_Delete_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 3, 0, 4, 1, 5, 2}, []string{"v1", "data", "key"}, "", runtime.AssumeColonVerbOpt(true))) @@ -972,6 +1068,8 @@ var ( forward_KVS_Get_0 = runtime.ForwardResponseMessage + forward_KVS_Scan_0 = runtime.ForwardResponseMessage + forward_KVS_Set_0 = runtime.ForwardResponseMessage forward_KVS_Delete_0 = runtime.ForwardResponseMessage diff --git a/protobuf/kvs.proto b/protobuf/kvs.proto index ebda213..5116f0d 100644 --- a/protobuf/kvs.proto +++ b/protobuf/kvs.proto @@ -55,12 +55,20 @@ service KVS { get: "/v1/data/{key=**}" }; } + + rpc Scan (ScanRequest) returns (ScanResponse) { + option (google.api.http) = { + get: "/v1/data/{prefix=**}" + }; + } + rpc Set (SetRequest) returns (google.protobuf.Empty) { option (google.api.http) = { put: "/v1/data/{key=**}" body: "*" }; } + rpc Delete (DeleteRequest) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v1/data/{key=**}" @@ -125,6 +133,14 @@ message GetResponse { bytes value = 1; } +message ScanRequest { + string prefix = 1; +} + +message ScanResponse { + repeated bytes values = 1; +} + message SetRequest { string key = 1; bytes value = 2; diff --git a/server/grpc_service.go b/server/grpc_service.go index 881a48f..02f528a 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -349,6 +349,23 @@ func (s *GRPCService) Get(ctx context.Context, req *protobuf.GetRequest) (*proto return resp, nil } +func (s *GRPCService) Scan(ctx context.Context, req *protobuf.ScanRequest) (*protobuf.ScanResponse, error) { + resp := &protobuf.ScanResponse{} + + var err error + + resp, err = s.raftServer.Scan(req) + if err != nil { + switch err { + default: + s.logger.Debug("failed to scan data", zap.String("prefix", req.Prefix), zap.String("err", err.Error())) + return resp, status.Error(codes.Internal, err.Error()) + } + } + + return resp, nil +} + func (s *GRPCService) Set(ctx context.Context, req *protobuf.SetRequest) (*empty.Empty, error) { resp := &empty.Empty{} diff --git a/server/raft_fsm.go b/server/raft_fsm.go index 3119f8b..51e0f65 100644 --- a/server/raft_fsm.go +++ b/server/raft_fsm.go @@ -71,6 +71,16 @@ func (f *RaftFSM) Get(key string) ([]byte, error) { return value, nil } +func (f *RaftFSM) Scan(prefix string) ([][]byte, error) { + values, err := f.kvs.Scan(prefix) + if err != nil { + f.logger.Error("failed to scan values", zap.String("prefix", prefix), zap.Error(err)) + return nil, err + } + + return values, nil +} + func (f *RaftFSM) applySet(key string, value []byte) interface{} { err := f.kvs.Set(key, value) if err != nil { diff --git a/server/raft_server.go b/server/raft_server.go index 8c98b2f..bf8e371 100644 --- a/server/raft_server.go +++ b/server/raft_server.go @@ -606,6 +606,20 @@ func (s *RaftServer) Get(req *protobuf.GetRequest) (*protobuf.GetResponse, error return resp, nil } +func (s *RaftServer) Scan(req *protobuf.ScanRequest) (*protobuf.ScanResponse, error) { + values, err := s.fsm.Scan(req.Prefix) + if err != nil { + s.logger.Error("failed to scan", zap.Any("prefix", req.Prefix), zap.Error(err)) + return nil, err + } + + resp := &protobuf.ScanResponse{ + Values: values, + } + + return resp, nil +} + func (s *RaftServer) Set(req *protobuf.SetRequest) error { kvpAny := &any.Any{} if err := marshaler.UnmarshalAny(req, kvpAny); err != nil { diff --git a/storage/kvs.go b/storage/kvs.go index a570b86..ca50f11 100644 --- a/storage/kvs.go +++ b/storage/kvs.go @@ -79,6 +79,34 @@ func (k *KVS) Get(key string) ([]byte, error) { return value, nil } +func (k *KVS) Scan(prefix string) ([][]byte, error) { + start := time.Now() + + var value [][]byte + if err := k.db.View(func(txn *badger.Txn) error { + it := txn.NewIterator(badger.DefaultIteratorOptions) + defer it.Close() + prefixBytes := []byte(prefix) + for it.Seek(prefixBytes); it.ValidForPrefix(prefixBytes); it.Next() { + item := it.Item() + err := item.Value(func(val []byte) error { + value = append(value, append([]byte{}, val...)) + return nil + }) + if err != nil { + return err + } + } + return nil + }); err != nil { + k.logger.Error("failed to scan value", zap.String("prefix", prefix), zap.Error(err)) + return nil, err + } + + k.logger.Debug("scan", zap.String("prefix", prefix), zap.Float64("time", float64(time.Since(start))/float64(time.Second))) + return value, nil +} + func (k *KVS) Set(key string, value []byte) error { start := time.Now()