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

vtctldclient: Apply tablet type filtering for keyspace+shard in GetTablets #14467

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,9 @@ func (s *VtctldServer) GetTablets(ctx context.Context, req *vtctldatapb.GetTable
defer panicHandler(&err)

span.Annotate("cells", strings.Join(req.Cells, ","))
if req.Keyspace != "" {
span.Annotate("keyspace", req.Keyspace)
}
if req.TabletType != topodatapb.TabletType_UNKNOWN {
span.Annotate("tablet_type", topodatapb.TabletType_name[int32(req.TabletType)])
}
Expand Down Expand Up @@ -1978,7 +1981,6 @@ func (s *VtctldServer) GetTablets(ctx context.Context, req *vtctldatapb.GetTable
err = fmt.Errorf("GetTabletMap(%v) failed: %w", req.TabletAliases, err)
}
case req.Keyspace != "" && req.Shard != "":
span.Annotate("keyspace", req.Keyspace)
span.Annotate("shard", req.Shard)

tabletMap, err = s.ts.GetTabletMapForShard(ctx, req.Keyspace, req.Shard)
Expand Down Expand Up @@ -2016,6 +2018,9 @@ func (s *VtctldServer) GetTablets(ctx context.Context, req *vtctldatapb.GetTable

tablets := make([]*topodatapb.Tablet, 0, len(tabletMap))
for _, ti := range tabletMap {
if req.TabletType != 0 && ti.Type != req.TabletType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this 0 and not UNKNOWN?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only because I copied the existing check/filter that was already used elsewhere in the function.🙂 I wish that I had changed both locations instead though. Whomever changes this file next should do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a non-functional change I snuck it in here:
459a27b

continue
}
adjustTypeForStalePrimary(ti, truePrimaryTimestamp)
tablets = append(tablets, ti.Tablet)
}
Expand Down
145 changes: 144 additions & 1 deletion go/vt/vtctl/grpcvtctldserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"vitess.io/vitess/go/test/utils"
hk "vitess.io/vitess/go/vt/hook"
"vitess.io/vitess/go/vt/mysqlctl/backupstorage"
"vitess.io/vitess/go/vt/proto/vttime"
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/memorytopo"
"vitess.io/vitess/go/vt/topo/topoproto"
Expand All @@ -57,7 +58,6 @@ import (
vschemapb "vitess.io/vitess/go/vt/proto/vschema"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice"
"vitess.io/vitess/go/vt/proto/vttime"
)

func init() {
Expand Down Expand Up @@ -6822,6 +6822,149 @@ func TestGetTablets(t *testing.T) {
expected: []*topodatapb.Tablet{},
shouldErr: false,
},
{
name: "tablet type filter",
cells: []string{"cell1"},
tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Keyspace: "ks1",
Shard: "-80",
Type: topodatapb.TabletType_PRIMARY,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 101,
},
Keyspace: "ks1",
Shard: "-80",
Type: topodatapb.TabletType_REPLICA,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 200,
},
Keyspace: "ks1",
Shard: "80-",
Type: topodatapb.TabletType_PRIMARY,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 201,
},
Keyspace: "ks1",
Shard: "80-",
Type: topodatapb.TabletType_REPLICA,
},
},
req: &vtctldatapb.GetTabletsRequest{
TabletType: topodatapb.TabletType_PRIMARY,
},
expected: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Keyspace: "ks1",
Shard: "-80",
Type: topodatapb.TabletType_PRIMARY,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 200,
},
Keyspace: "ks1",
Shard: "80-",
Type: topodatapb.TabletType_PRIMARY,
},
},
shouldErr: false,
},
{
name: "keyspace, shard, and tablet type filter",
cells: []string{"cell1"},
tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Keyspace: "ks1",
Shard: "-80",
Type: topodatapb.TabletType_PRIMARY,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 101,
},
Keyspace: "ks1",
Shard: "-80",
Type: topodatapb.TabletType_REPLICA,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 200,
},
Keyspace: "ks1",
Shard: "80-",
Type: topodatapb.TabletType_PRIMARY,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 201,
},
Keyspace: "ks1",
Shard: "80-",
Type: topodatapb.TabletType_REPLICA,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 300,
},
Keyspace: "ks2",
Shard: "-",
Type: topodatapb.TabletType_PRIMARY,
},
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 301,
},
Keyspace: "ks2",
Shard: "-",
Type: topodatapb.TabletType_REPLICA,
},
},
req: &vtctldatapb.GetTabletsRequest{
Keyspace: "ks1",
Shard: "-80",
TabletType: topodatapb.TabletType_PRIMARY,
},
expected: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 100,
},
Keyspace: "ks1",
Shard: "-80",
Type: topodatapb.TabletType_PRIMARY,
},
},
shouldErr: false,
},
}

for _, tt := range tests {
Expand Down
Loading