Skip to content

Commit

Permalink
Update cluster getTablets to fetch from vtctld
Browse files Browse the repository at this point in the history
Signed-off-by: notfelineit <[email protected]>
  • Loading branch information
notfelineit committed Mar 29, 2024
1 parent 308f1fc commit d0c3126
Showing 1 changed file with 36 additions and 2 deletions.
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 []*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_UNKNOWN
} else {
state = vtadminpb.Tablet_SERVING
}

m.Lock()
defer m.Unlock()

tablets = append(tablets, &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

0 comments on commit d0c3126

Please sign in to comment.