diff --git a/executor/adapter.go b/executor/adapter.go index b638b28690c8b..db9fbbaa929e0 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -191,12 +191,13 @@ func (a *recordSet) OnFetchReturned() { // TelemetryInfo records some telemetry information during execution. type TelemetryInfo struct { - UseNonRecursive bool - UseRecursive bool - UseMultiSchemaChange bool - UesExchangePartition bool - PartitionTelemetry *PartitionTelemetryInfo - AccountLockTelemetry *AccountLockTelemetryInfo + UseNonRecursive bool + UseRecursive bool + UseMultiSchemaChange bool + UesExchangePartition bool + UseFlashbackToCluster bool + PartitionTelemetry *PartitionTelemetryInfo + AccountLockTelemetry *AccountLockTelemetryInfo } // PartitionTelemetryInfo records table partition telemetry information during execution. diff --git a/executor/builder.go b/executor/builder.go index 55a21bd88babb..1b88b6e4047c6 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -1105,6 +1105,8 @@ func (b *executorBuilder) setTelemetryInfo(v *plannercore.DDL) { } } } + case *ast.FlashBackToTimestampStmt: + b.Ti.UseFlashbackToCluster = true } } diff --git a/metrics/telemetry.go b/metrics/telemetry.go index ab86890d4f6c9..e7629bcd76f6a 100644 --- a/metrics/telemetry.go +++ b/metrics/telemetry.go @@ -148,6 +148,13 @@ var ( Name: "add_index_ingest_usage", Help: "Counter of usage of add index acceleration solution", }) + TelemetryFlashbackClusterCnt = prometheus.NewCounter( + prometheus.CounterOpts{ + Namespace: "tidb", + Subsystem: "telemetry", + Name: "flashback_cluster_usage", + Help: "Counter of usage of flashback cluster", + }) ) // readCounter reads the value of a prometheus.Counter. @@ -354,22 +361,25 @@ func GetLazyPessimisticUniqueCheckSetCounter() int64 { return readCounter(LazyPessimisticUniqueCheckSetCount) } -// DDLUsageCounter records the usages of Add Index with acceleration solution. +// DDLUsageCounter records the usages of DDL related features. type DDLUsageCounter struct { - AddIndexIngestUsed int64 `json:"add_index_ingest_used"` - MetadataLockUsed bool `json:"metadata_lock_used"` + AddIndexIngestUsed int64 `json:"add_index_ingest_used"` + MetadataLockUsed bool `json:"metadata_lock_used"` + FlashbackClusterUsed int64 `json:"flashback_cluster_used"` } // Sub returns the difference of two counters. func (a DDLUsageCounter) Sub(rhs DDLUsageCounter) DDLUsageCounter { return DDLUsageCounter{ - AddIndexIngestUsed: a.AddIndexIngestUsed - rhs.AddIndexIngestUsed, + AddIndexIngestUsed: a.AddIndexIngestUsed - rhs.AddIndexIngestUsed, + FlashbackClusterUsed: a.FlashbackClusterUsed - rhs.FlashbackClusterUsed, } } // GetDDLUsageCounter gets the add index acceleration solution counts. func GetDDLUsageCounter() DDLUsageCounter { return DDLUsageCounter{ - AddIndexIngestUsed: readCounter(TelemetryAddIndexIngestCnt), + AddIndexIngestUsed: readCounter(TelemetryAddIndexIngestCnt), + FlashbackClusterUsed: readCounter(TelemetryFlashbackClusterCnt), } } diff --git a/session/session.go b/session/session.go index 1c2e0de9b7b92..38439a977fd94 100644 --- a/session/session.go +++ b/session/session.go @@ -129,6 +129,7 @@ var ( telemetryCTEUsageNonRecurCTE = metrics.TelemetrySQLCTECnt.WithLabelValues("nonRecurCTE") telemetryCTEUsageNotCTE = metrics.TelemetrySQLCTECnt.WithLabelValues("notCTE") telemetryMultiSchemaChangeUsage = metrics.TelemetryMultiSchemaChangeCnt + telemetryFlashbackClusterUsage = metrics.TelemetryFlashbackClusterCnt telemetryTablePartitionUsage = metrics.TelemetryTablePartitionCnt telemetryTablePartitionListUsage = metrics.TelemetryTablePartitionListCnt @@ -3518,6 +3519,10 @@ func (s *session) updateTelemetryMetric(es *executor.ExecStmt) { telemetryMultiSchemaChangeUsage.Inc() } + if ti.UseFlashbackToCluster { + telemetryFlashbackClusterUsage.Inc() + } + if ti.UesExchangePartition { telemetryExchangePartitionUsage.Inc() } diff --git a/telemetry/data_feature_usage.go b/telemetry/data_feature_usage.go index 5be16b51bed1b..9da8586aa8410 100644 --- a/telemetry/data_feature_usage.go +++ b/telemetry/data_feature_usage.go @@ -380,6 +380,7 @@ func getCostModelVer2UsageInfo(ctx sessionctx.Context) bool { func getPagingUsageInfo(ctx sessionctx.Context) bool { return ctx.GetSessionVars().EnablePaging } + func getDDLUsageInfo(ctx sessionctx.Context) *m.DDLUsageCounter { curr := m.GetDDLUsageCounter() diff := curr.Sub(initialDDLUsageCounter) diff --git a/telemetry/data_feature_usage_test.go b/telemetry/data_feature_usage_test.go index 8b2a77ba2ffdc..072bb618fb3cb 100644 --- a/telemetry/data_feature_usage_test.go +++ b/telemetry/data_feature_usage_test.go @@ -445,6 +445,27 @@ func TestLazyPessimisticUniqueCheck(t *testing.T) { require.Equal(t, int64(2), usage.LazyUniqueCheckSetCounter) } +func TestFlashbackCluster(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk1 := testkit.NewTestKit(t, store) + + usage, err := telemetry.GetFeatureUsage(tk.Session()) + require.Equal(t, int64(0), usage.DDLUsageCounter.FlashbackClusterUsed) + require.NoError(t, err) + + tk.MustExecToErr("flashback cluster to timestamp '2011-12-21 00:00:00'") + usage, err = telemetry.GetFeatureUsage(tk.Session()) + require.Equal(t, int64(1), usage.DDLUsageCounter.FlashbackClusterUsed) + require.NoError(t, err) + + tk1.MustExec("use test") + tk1.MustExec("create table t(a int)") + usage, err = telemetry.GetFeatureUsage(tk1.Session()) + require.Equal(t, int64(1), usage.DDLUsageCounter.FlashbackClusterUsed) + require.NoError(t, err) +} + func TestAddIndexAccelerationAndMDL(t *testing.T) { if !variable.EnableConcurrentDDL.Load() { t.Skipf("test requires concurrent ddl")