tidb advancer_conf 源码

  • 2022-09-19
  • 浏览 (458)

tidb advancer_conf 代码

文件路径:/br/pkg/streamhelper/config/advancer_conf.go

// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0.

package config

import (
	"time"

	"github.com/spf13/pflag"
)

const (
	flagBackoffTime      = "backoff-time"
	flagTickInterval     = "tick-interval"
	flagFullScanDiffTick = "full-scan-tick"
	flagAdvancingByCache = "advancing-by-cache"

	DefaultConsistencyCheckTick = 5
	DefaultTryAdvanceThreshold  = 108 * time.Second
	DefaultBackOffTime          = 5 * time.Second
	DefaultTickInterval         = 12 * time.Second
	DefaultFullScanTick         = 4
	DefaultAdvanceByCache       = true
)

var (
	DefaultMaxConcurrencyAdvance = 8
)

type Config struct {
	// The gap between two retries.
	BackoffTime time.Duration `toml:"backoff-time" json:"backoff-time"`
	// The gap between calculating checkpoints.
	TickDuration time.Duration `toml:"tick-interval" json:"tick-interval"`
	// The backoff time of full scan.
	FullScanTick int `toml:"full-scan-tick" json:"full-scan-tick"`

	// Whether enable the optimization -- use a cached heap to advancing the global checkpoint.
	// This may reduce the gap of checkpoint but may cost more CPU.
	AdvancingByCache bool `toml:"advancing-by-cache" json:"advancing-by-cache"`
}

func DefineFlagsForCheckpointAdvancerConfig(f *pflag.FlagSet) {
	f.Duration(flagBackoffTime, DefaultBackOffTime, "The gap between two retries.")
	f.Duration(flagTickInterval, DefaultTickInterval, "From how long we trigger the tick (advancing the checkpoint).")
	f.Bool(flagAdvancingByCache, DefaultAdvanceByCache, "Whether enable the optimization -- use a cached heap to advancing the global checkpoint.")
	f.Int(flagFullScanDiffTick, DefaultFullScanTick, "The backoff of full scan.")
}

func Default() Config {
	return Config{
		BackoffTime:      DefaultBackOffTime,
		TickDuration:     DefaultTickInterval,
		FullScanTick:     DefaultFullScanTick,
		AdvancingByCache: DefaultAdvanceByCache,
	}
}

func (conf *Config) GetFromFlags(f *pflag.FlagSet) error {
	var err error
	conf.BackoffTime, err = f.GetDuration(flagBackoffTime)
	if err != nil {
		return err
	}
	conf.TickDuration, err = f.GetDuration(flagTickInterval)
	if err != nil {
		return err
	}
	conf.FullScanTick, err = f.GetInt(flagFullScanDiffTick)
	if err != nil {
		return err
	}
	conf.AdvancingByCache, err = f.GetBool(flagAdvancingByCache)
	if err != nil {
		return err
	}
	return nil
}

相关信息

tidb 源码目录

相关文章

tidb bind_cache 源码

tidb bind_record 源码

tidb handle 源码

tidb session_handle 源码

tidb stat 源码

tidb backup 源码

tidb cmd 源码

tidb debug 源码

tidb main 源码

tidb restore 源码

0  赞