metrics, telemetry: add telemetry for metadata lock (#37915)
ref pingcap/tidb#37275
This commit is contained in:
@ -327,7 +327,8 @@ func GetLazyPessimisticUniqueCheckSetCounter() int64 {
|
||||
|
||||
// DDLUsageCounter records the usages of Add Index with acceleration solution.
|
||||
type DDLUsageCounter struct {
|
||||
AddIndexIngestUsed int64 `json:"add_index_Ingest_used"`
|
||||
AddIndexIngestUsed int64 `json:"add_index_ingest_used"`
|
||||
MetadataLockUsed bool `json:"metadata_lock_used"`
|
||||
}
|
||||
|
||||
// Sub returns the difference of two counters.
|
||||
|
||||
@ -67,6 +67,7 @@ func postReportTelemetryData() {
|
||||
postReportNonTransactionalCounter()
|
||||
PostSavepointCount()
|
||||
postReportLazyPessimisticUniqueCheckSetCount()
|
||||
postReportDDLUsage()
|
||||
}
|
||||
|
||||
// PostReportTelemetryDataForTest is for test.
|
||||
|
||||
@ -98,7 +98,7 @@ func getFeatureUsage(ctx context.Context, sctx sessionctx.Context) (*featureUsag
|
||||
|
||||
usage.EnableCostModelVer2 = getCostModelVer2UsageInfo(sctx)
|
||||
|
||||
usage.DDLUsageCounter = getAddIndexIngestUsageInfo()
|
||||
usage.DDLUsageCounter = getDDLUsageInfo(sctx)
|
||||
|
||||
return &usage, nil
|
||||
}
|
||||
@ -320,7 +320,7 @@ func postReportTablePartitionUsage() {
|
||||
initialTablePartitionCounter = m.ResetTablePartitionCounter(initialTablePartitionCounter)
|
||||
}
|
||||
|
||||
func postReportAddIndexIngestUsage() {
|
||||
func postReportDDLUsage() {
|
||||
initialDDLUsageCounter = m.GetDDLUsageCounter()
|
||||
}
|
||||
|
||||
@ -366,8 +366,12 @@ func getCostModelVer2UsageInfo(ctx sessionctx.Context) bool {
|
||||
func getPagingUsageInfo(ctx sessionctx.Context) bool {
|
||||
return ctx.GetSessionVars().EnablePaging
|
||||
}
|
||||
func getAddIndexIngestUsageInfo() *m.DDLUsageCounter {
|
||||
func getDDLUsageInfo(ctx sessionctx.Context) *m.DDLUsageCounter {
|
||||
curr := m.GetDDLUsageCounter()
|
||||
diff := curr.Sub(initialDDLUsageCounter)
|
||||
isEnable, err := ctx.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar("tidb_enable_metadata_lock")
|
||||
if err == nil {
|
||||
diff.MetadataLockUsed = isEnable == "ON"
|
||||
}
|
||||
return &diff
|
||||
}
|
||||
|
||||
@ -433,7 +433,11 @@ func TestLazyPessimisticUniqueCheck(t *testing.T) {
|
||||
require.Equal(t, int64(2), usage.LazyUniqueCheckSetCounter)
|
||||
}
|
||||
|
||||
func TestAddIndexAcceleration(t *testing.T) {
|
||||
func TestAddIndexAccelerationAndMDL(t *testing.T) {
|
||||
if !variable.EnableConcurrentDDL.Load() {
|
||||
t.Skipf("test requires concurrent ddl")
|
||||
}
|
||||
|
||||
store := testkit.CreateMockStore(t)
|
||||
tk := testkit.NewTestKit(t, store)
|
||||
usage, err := telemetry.GetFeatureUsage(tk.Session())
|
||||
@ -450,8 +454,10 @@ func TestAddIndexAcceleration(t *testing.T) {
|
||||
usage, err = telemetry.GetFeatureUsage(tk.Session())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(0), usage.DDLUsageCounter.AddIndexIngestUsed)
|
||||
require.Equal(t, false, usage.DDLUsageCounter.MetadataLockUsed)
|
||||
|
||||
tk.MustExec("set @@global.tidb_ddl_enable_fast_reorg = on")
|
||||
tk.MustExec("set global tidb_enable_metadata_lock = 1")
|
||||
allow = ddl.IsEnableFastReorg()
|
||||
require.Equal(t, true, allow)
|
||||
usage, err = telemetry.GetFeatureUsage(tk.Session())
|
||||
@ -461,4 +467,5 @@ func TestAddIndexAcceleration(t *testing.T) {
|
||||
usage, err = telemetry.GetFeatureUsage(tk.Session())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, int64(1), usage.DDLUsageCounter.AddIndexIngestUsed)
|
||||
require.Equal(t, true, usage.DDLUsageCounter.MetadataLockUsed)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user