Skip to content

Commit

Permalink
executor: fix data race in test (pingcap#12910)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway authored and XiaTianliang committed Dec 21, 2019
1 parent 4c8d495 commit 7e9afd0
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package session
import (
"context"
"sync"
"sync/atomic"
"time"

"github.com/opentracing/opentracing-go"
Expand Down Expand Up @@ -64,8 +65,8 @@ func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
return
}

ddlLease := schemaLease
statisticLease := statsLease
ddlLease := time.Duration(atomic.LoadInt64(&schemaLease))
statisticLease := time.Duration(atomic.LoadInt64(&statsLease))
err = util.RunWithRetry(util.DefaultMaxRetries, util.RetryInterval, func() (retry bool, err1 error) {
logutil.BgLogger().Info("new domain",
zap.String("store", store.UUID()),
Expand Down Expand Up @@ -111,27 +112,27 @@ var (
// Default schema lease time is 1 second, you can change it with a proper time,
// but you must know that too little may cause badly performance degradation.
// For production, you should set a big schema lease, like 300s+.
schemaLease = 1 * time.Second
schemaLease = int64(1 * time.Second)

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

// SetSchemaLease changes the default schema lease time for DDL.
// This function is very dangerous, don't use it if you really know what you do.
// SetSchemaLease only affects not local storage after bootstrapped.
func SetSchemaLease(lease time.Duration) {
schemaLease = lease
atomic.StoreInt64(&schemaLease, int64(lease))
}

// SetStatsLease changes the default stats lease time for loading stats info.
func SetStatsLease(lease time.Duration) {
statsLease = lease
atomic.StoreInt64(&statsLease, int64(lease))
}

// DisableStats4Test disables the stats for tests.
func DisableStats4Test() {
statsLease = -1
SetStatsLease(-1)
}

// Parse parses a query string to raw ast.StmtNode.
Expand Down

0 comments on commit 7e9afd0

Please sign in to comment.