Skip to content

Commit

Permalink
Refactoring to use healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
notfelineit committed Oct 23, 2023
1 parent 5450a53 commit 270ec15
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions go/vt/vtadmin/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,21 +1249,46 @@ func (c *Cluster) GetTablets(ctx context.Context) ([]*vtadminpb.Tablet, error) {

func (c *Cluster) getTablets(ctx context.Context) ([]*vtadminpb.Tablet, error) {
res, err := c.Vtctld.GetTablets(ctx, &vtctldatapb.GetTabletsRequest{})
tablets := make([]*vtadminpb.Tablet, len(res.Tablets))
for i, t := range res.Tablets {
tablets[i] = &vtadminpb.Tablet{
Cluster: c.ToProto(),
Tablet: t,
// TODO: Add serving state, return these results
}
}

rows, err := c.DB.ShowTablets(ctx)
if err != nil {
return nil, err
}

return c.parseTablets(rows)
var (
m sync.Mutex
wg sync.WaitGroup
tablets []*vtadminpb.Tablet
)

for _, 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 {
state = vtadminpb.Tablet_NOT_SERVING
} else {
state = vtadminpb.Tablet_SERVING
}

m.Lock()
defer m.Unlock()

tablets = append(tablets, &vtadminpb.Tablet{
Cluster: c.ToProto(),
Tablet: t,

Check failure on line 1283 in go/vt/vtadmin/cluster/cluster.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

loopclosure: loop variable t captured by func literal (govet)
State: state,
})
}(t)
}

wg.Wait()

return tablets, nil
}

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

0 comments on commit 270ec15

Please sign in to comment.