Skip to content

Commit

Permalink
Add GetKeyRange method to proto & EntityMgr (#567)
Browse files Browse the repository at this point in the history
* Add GetKeyRange to proto

* Add GetKeyRange to KeyRangeMgr

* Added GetKeyRange method to all of KeyRangeMgr's

* Changed id -> ids in GetKeyRange

* Implement GetKeyRange in KeyRangeServiceServer's
  • Loading branch information
EinKrebs authored Mar 27, 2024
1 parent c6d975e commit 35bca1b
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 79 deletions.
10 changes: 10 additions & 0 deletions coordinator/provider/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ func (qc *qdbCoordinator) AddKeyRange(ctx context.Context, keyRange *kr.KeyRange
})
}

// GetKeyRange gets key range by id
// TODO unit tests
func (qc *qdbCoordinator) GetKeyRange(ctx context.Context, krId string) (*kr.KeyRange, error) {
krDb, err := qc.db.GetKeyRange(ctx, krId)
if err != nil {
return nil, err
}
return kr.KeyRangeFromDB(krDb), nil
}

// TODO : unit tests
func (qc *qdbCoordinator) ListKeyRanges(ctx context.Context, distribution string) ([]*kr.KeyRange, error) {
keyRanges, err := qc.db.ListKeyRanges(ctx, distribution)
Expand Down
16 changes: 16 additions & 0 deletions coordinator/provider/keyranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ func (c *CoordinatorService) SplitKeyRange(ctx context.Context, request *protos.
return &protos.ModifyReply{}, nil
}

// GetKeyRange gets key ranges with given ids
// TODO unit tests
func (c *CoordinatorService) GetKeyRange(ctx context.Context, request *protos.GetKeyRangeRequest) (*protos.KeyRangeReply, error) {
res := make([]*protos.KeyRangeInfo, 0)
for _, id := range request.Ids {
krg, err := c.impl.GetKeyRange(ctx, id)
if err != nil {
return nil, err
}
if krg != nil {
res = append(res, krg.ToProto())
}
}
return &protos.KeyRangeReply{KeyRangesInfo: res}, nil
}

// TODO : unit tests
func (c *CoordinatorService) ListKeyRange(ctx context.Context, request *protos.ListKeyRangeRequest) (*protos.KeyRangeReply, error) {

Expand Down
16 changes: 16 additions & 0 deletions pkg/coord/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ func (a *Adapter) ShareKeyRange(id string) error {
return spqrerror.New(spqrerror.SPQR_NOT_IMPLEMENTED, "ShareKeyRange not implemented")
}

// GetKeyRange gets key range by id
// TODO unit tests
func (a *Adapter) GetKeyRange(ctx context.Context, krId string) (*kr.KeyRange, error) {
c := proto.NewKeyRangeServiceClient(a.conn)
reply, err := c.GetKeyRange(ctx, &proto.GetKeyRangeRequest{
Ids: []string{krId},
})
if err != nil {
return nil, err
}
if len(reply.KeyRangesInfo) == 0 {
return nil, nil
}
return kr.KeyRangeFromProto(reply.KeyRangesInfo[0]), nil
}

// TODO : unit tests
func (a *Adapter) ListKeyRanges(ctx context.Context, distribution string) ([]*kr.KeyRange, error) {
c := proto.NewKeyRangeServiceClient(a.conn)
Expand Down
10 changes: 10 additions & 0 deletions pkg/coord/local/clocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ func (qr *LocalCoordinator) Shards() []string {
return ret
}

// GetKeyRange gets key range by id
// TODO unit tests
func (lc *LocalCoordinator) GetKeyRange(ctx context.Context, krId string) (*kr.KeyRange, error) {
krDb, err := lc.qdb.GetKeyRange(ctx, krId)
if err != nil {
return nil, err
}
return kr.KeyRangeFromDB(krDb), nil
}

// TODO : unit tests
func (qr *LocalCoordinator) ListKeyRanges(ctx context.Context, distribution string) ([]*kr.KeyRange, error) {
var ret []*kr.KeyRange
Expand Down
1 change: 1 addition & 0 deletions pkg/models/kr/keyrangemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type UniteKeyRange struct {
}

type KeyRangeMgr interface {
GetKeyRange(ctx context.Context, krId string) (*KeyRange, error)
ListKeyRanges(ctx context.Context, distribution string) ([]*KeyRange, error)
ListAllKeyRanges(ctx context.Context) ([]*KeyRange, error)
AddKeyRange(ctx context.Context, kr *KeyRange) error
Expand Down
226 changes: 147 additions & 79 deletions pkg/protos/key_range.pb.go

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions pkg/protos/key_range_grpc.pb.go

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

5 changes: 5 additions & 0 deletions protos/key_range.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package spqr;
option go_package = "spqr/proto";

service KeyRangeService {
rpc GetKeyRange (GetKeyRangeRequest) returns (KeyRangeReply) {}
rpc ListKeyRange (ListKeyRangeRequest) returns (KeyRangeReply) {}
rpc ListAllKeyRanges (ListAllKeyRangesRequest) returns (KeyRangeReply) {}
rpc LockKeyRange (LockKeyRangeRequest) returns (ModifyReply) {}
Expand Down Expand Up @@ -96,3 +97,7 @@ message ResolveKeyRangeRequest {
message ResolveKeyRangeReply {
repeated string key_range_d = 1;
}

message GetKeyRangeRequest {
repeated string ids = 1;
}
16 changes: 16 additions & 0 deletions router/grpc/qrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ func (l *LocalQrouterServer) AddKeyRange(ctx context.Context, request *protos.Ad
return &protos.ModifyReply{}, nil
}

// GetKeyRange gets key ranges with given ids
// TODO unit tests
func (l *LocalQrouterServer) GetKeyRange(ctx context.Context, request *protos.GetKeyRangeRequest) (*protos.KeyRangeReply, error) {
res := make([]*protos.KeyRangeInfo, 0)
for _, id := range request.Ids {
krg, err := l.mgr.GetKeyRange(ctx, id)
if err != nil {
return nil, err
}
if krg != nil {
res = append(res, krg.ToProto())
}
}
return &protos.KeyRangeReply{KeyRangesInfo: res}, nil
}

// TODO : unit tests
func (l *LocalQrouterServer) ListKeyRange(ctx context.Context, request *protos.ListKeyRangeRequest) (*protos.KeyRangeReply, error) {
var krs []*protos.KeyRangeInfo
Expand Down

0 comments on commit 35bca1b

Please sign in to comment.