@@ -7,9 +7,11 @@ package schematelemetry
7
7
8
8
import (
9
9
"context"
10
+ "math"
10
11
11
12
"github.com/cockroachdb/cockroach/pkg/jobs"
12
13
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
14
+ "github.com/cockroachdb/cockroach/pkg/keys"
13
15
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
14
16
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
15
17
"github.com/cockroachdb/cockroach/pkg/sql"
@@ -63,6 +65,31 @@ func (t schemaTelemetryResumer) Resume(ctx context.Context, execCtx interface{})
63
65
if k := p .ExecCfg ().SchemaTelemetryTestingKnobs ; k != nil {
64
66
knobs = * k
65
67
}
68
+ // Notify the stats refresher to update the system.descriptors table stats,
69
+ // and update the object count in schema changer metrics.
70
+ err := p .ExecCfg ().InternalDB .DescsTxn (ctx , func (ctx context.Context , txn descs.Txn ) error {
71
+ desc , err := txn .Descriptors ().ByIDWithLeased (txn .KV ()).Get ().Table (ctx , keys .DescriptorTableID )
72
+ if err != nil {
73
+ return err
74
+ }
75
+ p .ExecCfg ().StatsRefresher .NotifyMutation (desc , math .MaxInt64 /* rowCount */ )
76
+
77
+ // Note: This won't be perfectly up-to-date, but it will make sure the
78
+ // metric gets updated periodically. It also gets updated after every
79
+ // schema change.
80
+ tableStats , err := p .ExecCfg ().TableStatsCache .GetTableStats (ctx , desc , nil /* typeResolver */ )
81
+ if err != nil {
82
+ return err
83
+ }
84
+ if len (tableStats ) > 0 {
85
+ // Use the row count from the most recent statistic.
86
+ p .ExecCfg ().SchemaChangerMetrics .ObjectCount .Update (int64 (tableStats [0 ].RowCount ))
87
+ }
88
+ return nil
89
+ })
90
+ if err != nil {
91
+ return errors .Wrap (err , "failed to notify stats refresher to update system.descriptors table stats" )
92
+ }
66
93
67
94
// Outside of tests, scan the catalog tables AS OF SYSTEM TIME slightly in the
68
95
// past. Schema telemetry is not latency-sensitive to the point where a few
0 commit comments