Skip to content

Commit

Permalink
Merge branch 'master' into fix-40633
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Feb 10, 2023
2 parents 4805c45 + 6cb7374 commit cc81857
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ddl/dist_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ import (
)

// CheckBackfillJobFinishInterval is export for test.
var CheckBackfillJobFinishInterval = 300 * time.Millisecond
var (
CheckBackfillJobFinishInterval = 300 * time.Millisecond
telemetryDistReorgUsage = metrics.TelemetryDistReorgCnt
)

const (
distPhysicalTableConcurrency = 16
Expand All @@ -48,6 +51,9 @@ const (
func initDistReorg(reorgMeta *model.DDLReorgMeta) {
isDistReorg := variable.DDLEnableDistributeReorg.Load()
reorgMeta.IsDistReorg = isDistReorg
if isDistReorg {
metrics.TelemetryDistReorgCnt.Inc()
}
}

// BackfillJobRangeMeta is export for test.
Expand Down
10 changes: 10 additions & 0 deletions metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ var (
Name: "compact_partition_usage",
Help: "Counter of compact table partition",
})
TelemetryDistReorgCnt = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Subsystem: "telemetry",
Name: "distributed_reorg_count",
Help: "Counter of usage of distributed reorg DDL tasks count",
})
TelemetryStoreBatchedQueryCnt = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "tidb",
Expand Down Expand Up @@ -414,13 +421,15 @@ type DDLUsageCounter struct {
AddIndexIngestUsed int64 `json:"add_index_ingest_used"`
MetadataLockUsed bool `json:"metadata_lock_used"`
FlashbackClusterUsed int64 `json:"flashback_cluster_used"`
DistReorgUsed int64 `json:"dist_reorg_used"`
}

// Sub returns the difference of two counters.
func (a DDLUsageCounter) Sub(rhs DDLUsageCounter) DDLUsageCounter {
return DDLUsageCounter{
AddIndexIngestUsed: a.AddIndexIngestUsed - rhs.AddIndexIngestUsed,
FlashbackClusterUsed: a.FlashbackClusterUsed - rhs.FlashbackClusterUsed,
DistReorgUsed: a.DistReorgUsed - rhs.DistReorgUsed,
}
}

Expand All @@ -429,6 +438,7 @@ func GetDDLUsageCounter() DDLUsageCounter {
return DDLUsageCounter{
AddIndexIngestUsed: readCounter(TelemetryAddIndexIngestCnt),
FlashbackClusterUsed: readCounter(TelemetryFlashbackClusterCnt),
DistReorgUsed: readCounter(TelemetryDistReorgCnt),
}
}

Expand Down
31 changes: 31 additions & 0 deletions telemetry/data_feature_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,37 @@ func TestAddIndexAccelerationAndMDL(t *testing.T) {
require.Equal(t, true, usage.DDLUsageCounter.MetadataLockUsed)
}

func TestDistReorgUsage(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
usage, err := telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
initCount := usage.DDLUsageCounter.DistReorgUsed

tk.MustExec("set @@global.tidb_ddl_distribute_reorg = off")
allow := variable.DDLEnableDistributeReorg.Load()
require.Equal(t, false, allow)
tk.MustExec("use test")
tk.MustExec("drop table if exists tele_t")
tk.MustExec("create table tele_t(id int, b int)")
tk.MustExec("insert into tele_t values(1,1),(2,2);")
tk.MustExec("alter table tele_t add index idx_org(b)")
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
require.Equal(t, initCount, usage.DDLUsageCounter.DistReorgUsed)

tk.MustExec("set @@global.tidb_ddl_distribute_reorg = on")
allow = variable.DDLEnableDistributeReorg.Load()
require.Equal(t, true, allow)
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
require.Equal(t, initCount, usage.DDLUsageCounter.DistReorgUsed)
tk.MustExec("alter table tele_t add index idx_new(b)")
usage, err = telemetry.GetFeatureUsage(tk.Session())
require.NoError(t, err)
require.Equal(t, initCount+1, usage.DDLUsageCounter.DistReorgUsed)
}

func TestGlobalMemoryControl(t *testing.T) {
store := testkit.CreateMockStore(t)

Expand Down

0 comments on commit cc81857

Please sign in to comment.