Skip to content
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
4 changes: 2 additions & 2 deletions go/vt/vtadmin/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,12 @@ func (c *Cluster) getTabletsToQueryForSchemas(ctx context.Context, keyspace stri

for _, shard := range shards {
if !shard.Shard.IsMasterServing {
log.Infof("%s/%s is not serving; ignoring because IncludeNonServingShards=false", keyspace, shard.Name)
log.Infof("%s/%s is not serving; ignoring ...", keyspace, shard.Name)
continue
}

shardTablets := vtadminproto.FilterTablets(func(tablet *vtadminpb.Tablet) bool {
return tablet.Tablet.Shard == shard.Name && tablet.State == vtadminpb.Tablet_SERVING
return tablet.Tablet.Keyspace == keyspace && tablet.Tablet.Shard == shard.Name && tablet.State == vtadminpb.Tablet_SERVING
}, opts.Tablets, len(opts.Tablets))

if len(shardTablets) == 0 {
Expand Down
141 changes: 141 additions & 0 deletions go/vt/vtadmin/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,147 @@ func TestGetSchema(t *testing.T) {
expected: nil,
shouldErr: true,
},
{
name: "tablet filtering checks keyspace field",
cfg: testutil.TestClusterConfig{
Cluster: &vtadminpb.Cluster{
Id: "c0",
Name: "cluster0",
},
Tablets: []*vtadminpb.Tablet{
{
Tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-80",
},
State: vtadminpb.Tablet_SERVING,
},
{
Tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 200,
},
Keyspace: "testkeyspace",
Shard: "80-",
},
State: vtadminpb.Tablet_SERVING,
},
},
VtctldClient: &testutil.VtctldClient{
FindAllShardsInKeyspaceResults: map[string]struct {
Response *vtctldatapb.FindAllShardsInKeyspaceResponse
Error error
}{
"testkeyspace": {
Response: &vtctldatapb.FindAllShardsInKeyspaceResponse{
Shards: map[string]*vtctldatapb.Shard{
"-80": {
Name: "-80",
Shard: &topodatapb.Shard{
IsMasterServing: true,
},
},
"80-": {
Name: "80-",
Shard: &topodatapb.Shard{
IsMasterServing: true,
},
},
},
},
},
},
GetSchemaResults: map[string]struct {
Response *vtctldatapb.GetSchemaResponse
Error error
}{
"zone1-0000000100": {
Response: &vtctldatapb.GetSchemaResponse{
Schema: &tabletmanagerdatapb.SchemaDefinition{
DatabaseSchema: "CREATE DATABASE vt_testkeyspcae",
TableDefinitions: []*tabletmanagerdatapb.TableDefinition{
{
Name: "foo",
Schema: "CREATE TABLE foo (\n\tid INT(11) NOT NULL\n) ENGINE=InnoDB",
DataLength: 100,
RowCount: 5,
},
},
},
},
},
"zone1-0000000200": {
Response: &vtctldatapb.GetSchemaResponse{
Schema: &tabletmanagerdatapb.SchemaDefinition{
DatabaseSchema: "CREATE DATABASE vt_testkeyspcae",
TableDefinitions: []*tabletmanagerdatapb.TableDefinition{
{
Name: "foo",
Schema: "CREATE TABLE foo (\n\tid INT(11) NOT NULL\n) ENGINE=InnoDB",
DataLength: 200,
RowCount: 420,
},
},
},
},
},
"zone1-0000000300": {
Response: &vtctldatapb.GetSchemaResponse{
Schema: &tabletmanagerdatapb.SchemaDefinition{
DatabaseSchema: "CREATE DATABASE vt_otherkeyspacekeyspcae",
TableDefinitions: []*tabletmanagerdatapb.TableDefinition{
{
Name: "bar",
Schema: "CREATE TABLE bar (\n\tid INT(11) NOT NULL\n) ENGINE=InnoDB",
DataLength: 101,
RowCount: 202,
},
},
},
},
},
},
},
},
keyspace: "testkeyspace",
opts: cluster.GetSchemaOptions{
TableSizeOptions: &vtadminpb.GetSchemaTableSizeOptions{
AggregateSizes: true,
},
Tablets: []*vtadminpb.Tablet{
{
Tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-80",
},
State: vtadminpb.Tablet_SERVING,
},
{
Tablet: &topodatapb.Tablet{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 300,
},
// Note this is for another keyspace, so we fail to find a tablet for testkeyspace/-80.
Keyspace: "otherkeyspace",
Shard: "80-",
},
State: vtadminpb.Tablet_SERVING,
},
},
},
expected: nil,
shouldErr: true,
},
}

for _, tt := range tests {
Expand Down