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

Implement ListShards and GetShardInfo #439

Merged
merged 2 commits into from
Jan 23, 2024
Merged
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
22 changes: 18 additions & 4 deletions pkg/coord/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package coord

import (
"context"
"github.com/pg-sharding/spqr/pkg/config"
"github.com/pg-sharding/spqr/pkg/models/spqrerror"

"github.com/pg-sharding/spqr/pkg/models/datashards"
Expand Down Expand Up @@ -340,15 +341,28 @@ func (a *adapter) AddWorldShard(ctx context.Context, shard *datashards.DataShard
}

// TODO : unit tests
// TODO : implement
func (a *adapter) ListShards(ctx context.Context) ([]*datashards.DataShard, error) {
return nil, spqrerror.New(spqrerror.SPQR_NOT_IMPLEMENTED, "ListShards not implemented")
c := proto.NewShardServiceClient(a.conn)
resp, err := c.ListShards(ctx, &proto.ListShardsRequest{})
shards := resp.Shards
var ds []*datashards.DataShard
for _, shard := range shards {
ds = append(ds, &datashards.DataShard{
ID: shard.Id,
Cfg: &config.Shard{Hosts: shard.Hosts},
})
}
return ds, err
}

// TODO : unit tests
// TODO : implement
func (a *adapter) GetShardInfo(ctx context.Context, shardID string) (*datashards.DataShard, error) {
return nil, spqrerror.New(spqrerror.SPQR_NOT_IMPLEMENTED, "GetShardInfo not implemented")
c := proto.NewShardServiceClient(a.conn)
resp, err := c.GetShardInfo(ctx, &proto.ShardRequest{Id: shardID})
return &datashards.DataShard{
ID: resp.ShardInfo.Id,
Cfg: &config.Shard{Hosts: resp.ShardInfo.Hosts},
}, err
}

// TODO : unit tests
Expand Down
Loading