From d0c31264972530feaceed1664caf761e19cc9a4d Mon Sep 17 00:00:00 2001 From: notfelineit Date: Fri, 29 Mar 2024 12:50:02 -0700 Subject: [PATCH] Update cluster getTablets to fetch from vtctld Signed-off-by: notfelineit --- go/vt/vtadmin/cluster/cluster.go | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/go/vt/vtadmin/cluster/cluster.go b/go/vt/vtadmin/cluster/cluster.go index 0afed99c24d..6259cc5170e 100644 --- a/go/vt/vtadmin/cluster/cluster.go +++ b/go/vt/vtadmin/cluster/cluster.go @@ -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