Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
Signed-off-by: youjiali1995 <zlwgx1023@gmail.com>
  • Loading branch information
youjiali1995 committed Mar 24, 2021
1 parent 6086f82 commit 300f885
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 74 deletions.
6 changes: 3 additions & 3 deletions store/tikv/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ func readCounter(m prometheus.Counter) int64 {
// TxnCommitCounter is the counter of transactions committed with
// different protocols, i.e. 2PC, async-commit, 1PC.
type TxnCommitCounter struct {
TwoPC int64
AsyncCommit int64
OnePC int64
TwoPC int64 `json:"twoPC"`
AsyncCommit int64 `json:"asyncCommit"`
OnePC int64 `json:"onePC"`
}

// Sub returns the difference of two counters.
Expand Down
56 changes: 0 additions & 56 deletions telemetry/data_feature_info.go

This file was deleted.

46 changes: 31 additions & 15 deletions telemetry/data_feature_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import (

"github.com/cznic/mathutil"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/tikv/metrics"
"github.com/pingcap/tidb/util/sqlexec"
)

type featureUsageInfo struct {
AsyncCommitUsed bool `json:"asyncCommitUsed"`
TxnUsageInfo *TxnUsageInfo `json:"txnUsageInfo"`
CoprCacheUsed []*CoprCacheUsedWindowItem `json:"coprCacheUsed"`
ClusterIndexUsed map[string]bool `json:"clusterIndexUsed"`
TiFlashUsed []*TiFlashUsageItem `json:"tiFlashUsed"`
Expand Down Expand Up @@ -225,20 +227,34 @@ func getTelemetryFeatureUsageInfo(ctx sessionctx.Context) (*featureUsageInfo, er
usageInfo.ClusterIndexUsed[row.GetString(0)] = isClustered
}

// async commit
stmt, err = exec.ParseWithParams(context.TODO(), `show config where name = 'storage.enable-async-apply-prewrite'`)
if err != nil {
return nil, err
}
rows, _, err = exec.ExecRestrictedStmt(context.TODO(), stmt)
if err != nil {
return nil, err
}
if len(rows) > 0 {
if rows[0].GetString(3) == "true" {
usageInfo.AsyncCommitUsed = true
}
}
// transaction related feature
usageInfo.TxnUsageInfo = GetTxnUsageInfo(ctx)

return &usageInfo, nil
}

// TxnUsageInfo records the usage info of transaction related features, including
// async-commit, 1PC and counters of transactions committed with different protocols.
type TxnUsageInfo struct {
AsyncCommitUsed bool `json:"asyncCommitUsed"`
OnePCUsed bool `json:"onePCUsed"`
TxnCommitCounter metrics.TxnCommitCounter `json:"txnCommitCounter"`
}

var initialTxnCommitCounter metrics.TxnCommitCounter

// GetTxnUsageInfo gets the usage info of transaction related features. It's exported for tests.
func GetTxnUsageInfo(ctx sessionctx.Context) *TxnUsageInfo {
asyncCommitUsed := false
if val, err := variable.GetGlobalSystemVar(ctx.GetSessionVars(), variable.TiDBEnableAsyncCommit); err == nil {
asyncCommitUsed = val == variable.BoolOn
}
onePCUsed := false
if val, err := variable.GetGlobalSystemVar(ctx.GetSessionVars(), variable.TiDBEnable1PC); err == nil {
onePCUsed = val == variable.BoolOn
}
curr := metrics.GetTxnCommitCounter()
diff := curr.Sub(initialTxnCommitCounter)
initialTxnCommitCounter = curr
return &TxnUsageInfo{asyncCommitUsed, onePCUsed, diff}
}
File renamed without changes.

0 comments on commit 300f885

Please sign in to comment.