Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log-backup: update method for telemetry to check usage of pitr feature #37896

Merged
merged 11 commits into from
Sep 19, 2022
2 changes: 2 additions & 0 deletions br/pkg/streamhelper/advancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,12 @@ func (c *CheckpointAdvancer) onTaskEvent(ctx context.Context, e TaskEvent) error
defer c.taskMu.Unlock()
switch e.Type {
case EventAdd:
utils.LogBackupTaskCountInc()
c.task = e.Info
c.taskRange = CollapseRanges(len(e.Ranges), func(i int) kv.KeyRange { return e.Ranges[i] })
log.Info("added event", zap.Stringer("task", e.Info), zap.Stringer("ranges", logutil.StringifyKeys(c.taskRange)))
case EventDel:
utils.LogBackupTaskCountDec()
c.task = nil
c.taskRange = nil
c.state = &fullScan{}
Expand Down
23 changes: 23 additions & 0 deletions br/pkg/utils/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"database/sql"
"strings"
"sync"

"github.com/pingcap/log"
"github.com/pingcap/tidb/kv"
Expand All @@ -18,6 +19,9 @@ var (
// check sql.DB and sql.Conn implement QueryExecutor and DBExecutor
_ DBExecutor = &sql.DB{}
_ DBExecutor = &sql.Conn{}

LogBackupTaskMutex sync.Mutex
logBackupTaskCount int
)

// QueryExecutor is a interface for exec query
Expand Down Expand Up @@ -89,3 +93,22 @@ func IsLogBackupEnabled(ctx sqlexec.RestrictedSQLExecutor) (bool, error) {
}
return true, nil
}

// CheckLogBackupTaskExist increases the count of log backup task.
func LogBackupTaskCountInc() {
LogBackupTaskMutex.Lock()
logBackupTaskCount++
LogBackupTaskMutex.Unlock()
}

// CheckLogBackupTaskExist decreases the count of log backup task.
func LogBackupTaskCountDec() {
LogBackupTaskMutex.Lock()
logBackupTaskCount--
LogBackupTaskMutex.Unlock()
}

// CheckLogBackupTaskExist checks that whether log-backup is existed.
func CheckLogBackupTaskExist() bool {
return logBackupTaskCount > 0
}
8 changes: 8 additions & 0 deletions br/pkg/utils/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ func TestIsLogBackupEnabled(t *testing.T) {
require.Error(t, err)
require.False(t, enabled)
}

func TestCheckLogBackupTaskExist(t *testing.T) {
require.False(t, utils.CheckLogBackupTaskExist())
utils.LogBackupTaskCountInc()
require.True(t, utils.CheckLogBackupTaskExist())
utils.LogBackupTaskCountDec()
require.False(t, utils.CheckLogBackupTaskExist())
}
2 changes: 1 addition & 1 deletion telemetry/data_feature_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func getGlobalKillUsageInfo() bool {
}

func getLogBackupUsageInfo(ctx sessionctx.Context) bool {
return utils.CheckLogBackupEnabled(ctx)
return utils.CheckLogBackupEnabled(ctx) && utils.CheckLogBackupTaskExist()
}

func getCostModelVer2UsageInfo(ctx sessionctx.Context) bool {
Expand Down