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

GetTablets from Vtctldclient #15596

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
32 changes: 32 additions & 0 deletions go/vt/vtadmin/api_authz_test.go

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

206 changes: 206 additions & 0 deletions go/vt/vtadmin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,25 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -181,6 +200,13 @@ func TestFindSchema(t *testing.T) {
{Name: "testkeyspace"},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: nil,
Error: assert.AnError,
},
},
},
},
Expand All @@ -204,6 +230,25 @@ func TestFindSchema(t *testing.T) {
}{
Error: fmt.Errorf("GetKeyspaces: %w", assert.AnError),
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -251,6 +296,25 @@ func TestFindSchema(t *testing.T) {
Error: fmt.Errorf("GetSchema: %w", assert.AnError),
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -306,6 +370,25 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -361,6 +444,25 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -407,6 +509,25 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone2",
Uid: 200,
},
Keyspace: "testkeyspace",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone2-0000000200": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -462,6 +583,25 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone1",
Uid: 100,
},
Keyspace: "testkeyspace1",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -508,6 +648,25 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "zone2",
Uid: 200,
},
Keyspace: "testkeyspace2",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"zone2-0000000200": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -675,6 +834,34 @@ func TestFindSchema(t *testing.T) {
},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "c1zone1",
Uid: 100,
},
Keyspace: "testkeyspace",
Shard: "-80",
},
{
Alias: &topodatapb.TabletAlias{
Cell: "c1zone1",
Uid: 200,
},
Keyspace: "testkeyspace",
Shard: "80-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"c1zone1-0000000100": nil,
"c1zone1-0000000200": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down Expand Up @@ -747,6 +934,25 @@ func TestFindSchema(t *testing.T) {
Response: &vtctldatapb.GetSchemaResponse{},
},
},
GetTabletsResults: &struct {
Tablets []*topodatapb.Tablet
Error error
}{
Tablets: []*topodatapb.Tablet{
{
Alias: &topodatapb.TabletAlias{
Cell: "c2z1",
Uid: 100,
},
Keyspace: "ks2",
Shard: "-",
},
},
Error: nil,
},
RunHealthCheckResults: map[string]error{
"c2z1-0000000100": nil,
},
},
Tablets: []*vtadminpb.Tablet{
{
Expand Down
38 changes: 36 additions & 2 deletions go/vt/vtadmin/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,12 +1314,46 @@ func (c *Cluster) GetTablets(ctx context.Context) ([]*vtadminpb.Tablet, error) {
}

func (c *Cluster) getTablets(ctx context.Context) ([]*vtadminpb.Tablet, error) {
rows, err := c.DB.ShowTablets(ctx)
res, err := c.Vtctld.GetTablets(ctx, &vtctldatapb.GetTabletsRequest{})
if err != nil {
return nil, err
}

return c.parseTablets(rows)
var (
m sync.Mutex
wg sync.WaitGroup
)

tablets := make([]*vtadminpb.Tablet, len(res.Tablets))

for i, t := range res.Tablets {
wg.Add(1)

go func(tablet *topodatapb.Tablet) {
defer wg.Done()
var state vtadminpb.Tablet_ServingState
_, err := c.Vtctld.RunHealthCheck(ctx, &vtctldatapb.RunHealthCheckRequest{
TabletAlias: tablet.Alias,
})
if err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropping the original comment from @ajm188 here:

just dropping a placeholder so i don't forget about the UNKNOWN vs NOT_SERVING distinction here

state = vtadminpb.Tablet_UNKNOWN
} else {
state = vtadminpb.Tablet_SERVING
}

m.Lock()
defer m.Unlock()

tablets[i] = &vtadminpb.Tablet{
Cluster: c.ToProto(),
Tablet: tablet,
State: state,
}
}(t)
}

wg.Wait()
return tablets, nil
}

// GetSchemaOptions contains the options that modify the behavior of the
Expand Down
Loading
Loading