Skip to content

Commit

Permalink
*: add index-usage-sync-lease config variable (pingcap#19842)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelice authored Sep 16, 2020
1 parent 205c401 commit d8e4321
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ type Performance struct {
CommitterConcurrency int `toml:"committer-concurrency" json:"committer-concurrency"`
MaxTxnTTL uint64 `toml:"max-txn-ttl" json:"max-txn-ttl"`
MemProfileInterval string `toml:"mem-profile-interval" json:"mem-profile-interval"`
IndexUsageSyncLease string `toml:"index-usage-sync-lease" json:"index-usage-sync-lease"`
}

// PlanCache is the PlanCache section of the config.
Expand Down Expand Up @@ -663,6 +664,7 @@ var defaultConf = Config{
CommitterConcurrency: 16,
MaxTxnTTL: 60 * 60 * 1000, // 1hour
MemProfileInterval: "1m",
IndexUsageSyncLease: "60s",
},
ProxyProtocol: ProxyProtocol{
Networks: "",
Expand Down
16 changes: 9 additions & 7 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Domain struct {
wg sync.WaitGroup
statsUpdating sync2.AtomicInt32
cancel context.CancelFunc
indexUsageSyncLease time.Duration
}

// loadInfoSchema loads infoschema at startTS into handle, usedSchemaVersion is the currently used
Expand Down Expand Up @@ -658,15 +659,16 @@ func (c *ddlCallback) OnChanged(err error) error {
const resourceIdleTimeout = 3 * time.Minute // resources in the ResourcePool will be recycled after idleTimeout

// NewDomain creates a new domain. Should not create multiple domains for the same store.
func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duration, factory pools.Factory) *Domain {
func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duration, idxUsageSyncLease time.Duration, factory pools.Factory) *Domain {
capacity := 200 // capacity of the sysSessionPool size
do := &Domain{
store: store,
exit: make(chan struct{}),
sysSessionPool: newSessionPool(capacity, factory),
statsLease: statsLease,
infoHandle: infoschema.NewHandle(store),
slowQuery: newTopNSlowQueries(30, time.Hour*24*7, 500),
store: store,
exit: make(chan struct{}),
sysSessionPool: newSessionPool(capacity, factory),
statsLease: statsLease,
infoHandle: infoschema.NewHandle(store),
slowQuery: newTopNSlowQueries(30, time.Hour*24*7, 500),
indexUsageSyncLease: idxUsageSyncLease,
}

do.SchemaValidator = NewSchemaValidator(ddlLease, do)
Expand Down
4 changes: 2 additions & 2 deletions domain/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestInfo(t *testing.T) {
mockStore := &mockEtcdBackend{
Storage: s,
pdAddrs: []string{clus.Members[0].GRPCAddr()}}
dom := NewDomain(mockStore, ddlLease, 0, mockFactory)
dom := NewDomain(mockStore, ddlLease, 0, 0, mockFactory)
defer func() {
dom.Close()
s.Close()
Expand Down Expand Up @@ -246,7 +246,7 @@ func (*testSuite) TestT(c *C) {
store, err := mockstore.NewMockStore()
c.Assert(err, IsNil)
ddlLease := 80 * time.Millisecond
dom := NewDomain(store, ddlLease, 0, mockFactory)
dom := NewDomain(store, ddlLease, 0, 0, mockFactory)
err = dom.Init(ddlLease, sysMockFactory)
c.Assert(err, IsNil)
ctx := mock.NewContext()
Expand Down
4 changes: 2 additions & 2 deletions domain/global_vars_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (gvcSuite *testGVCSuite) TestSimple(c *C) {
c.Assert(err, IsNil)
defer store.Close()
ddlLease := 50 * time.Millisecond
dom := NewDomain(store, ddlLease, 0, mockFactory)
dom := NewDomain(store, ddlLease, 0, 0, mockFactory)
err = dom.Init(ddlLease, sysMockFactory)
c.Assert(err, IsNil)
defer dom.Close()
Expand Down Expand Up @@ -177,7 +177,7 @@ func (gvcSuite *testGVCSuite) TestCheckEnableStmtSummary(c *C) {
c.Assert(err, IsNil)
defer store.Close()
ddlLease := 50 * time.Millisecond
dom := NewDomain(store, ddlLease, 0, mockFactory)
dom := NewDomain(store, ddlLease, 0, 0, mockFactory)
err = dom.Init(ddlLease, sysMockFactory)
c.Assert(err, IsNil)
defer dom.Close()
Expand Down
14 changes: 12 additions & 2 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {

ddlLease := time.Duration(atomic.LoadInt64(&schemaLease))
statisticLease := time.Duration(atomic.LoadInt64(&statsLease))
idxUsageSyncLease := time.Duration(atomic.LoadInt64(&indexUsageSyncLease))
err = util.RunWithRetry(util.DefaultMaxRetries, util.RetryInterval, func() (retry bool, err1 error) {
logutil.BgLogger().Info("new domain",
zap.String("store", store.UUID()),
zap.Stringer("ddl lease", ddlLease),
zap.Stringer("stats lease", statisticLease))
zap.Stringer("stats lease", statisticLease),
zap.Stringer("index usage sync lease", idxUsageSyncLease))
factory := createSessionFunc(store)
sysFactory := createSessionWithDomainFunc(store)
d = domain.NewDomain(store, ddlLease, statisticLease, factory)
d = domain.NewDomain(store, ddlLease, statisticLease, idxUsageSyncLease, factory)
err1 = d.Init(ddlLease, sysFactory)
if err1 != nil {
// If we don't clean it, there are some dirty data when retrying the function of Init.
Expand Down Expand Up @@ -115,6 +117,9 @@ var (

// statsLease is the time for reload stats table.
statsLease = int64(3 * time.Second)

// indexUsageSyncLease is the time for index usage synchronization.
indexUsageSyncLease = int64(60 * time.Second)
)

// ResetStoreForWithTiKVTest is only used in the test code.
Expand Down Expand Up @@ -150,6 +155,11 @@ func SetStatsLease(lease time.Duration) {
atomic.StoreInt64(&statsLease, int64(lease))
}

// SetIndexUsageSyncLease changes the default index usage sync lease time for loading info.
func SetIndexUsageSyncLease(lease time.Duration) {
atomic.StoreInt64(&indexUsageSyncLease, int64(lease))
}

// DisableStats4Test disables the stats for tests.
func DisableStats4Test() {
SetStatsLease(-1)
Expand Down
2 changes: 2 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ func setGlobalVars() {
session.SetSchemaLease(ddlLeaseDuration)
statsLeaseDuration := parseDuration(cfg.Performance.StatsLease)
session.SetStatsLease(statsLeaseDuration)
indexUsageSyncLeaseDuration := parseDuration(cfg.Performance.IndexUsageSyncLease)
session.SetIndexUsageSyncLease(indexUsageSyncLeaseDuration)
bindinfo.Lease = parseDuration(cfg.Performance.BindInfoLease)
domain.RunAutoAnalyze = cfg.Performance.RunAutoAnalyze
statistics.FeedbackProbability.Store(cfg.Performance.FeedbackProbability)
Expand Down

0 comments on commit d8e4321

Please sign in to comment.