Skip to content

Commit

Permalink
cherry pick #3091 to release-4.0 (#3094)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Song Gao <disxiaofei@163.com>
  • Loading branch information
ti-srebot and Yisaer authored Oct 22, 2020
1 parent 9e23890 commit 1f67ff2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/config/persist_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
type PersistOptions struct {
// configuration -> ttl value
ttl map[string]*cache.TTLString
ttlCancel map[string]context.CancelFunc
schedule atomic.Value
replication atomic.Value
pdServerConfig atomic.Value
Expand All @@ -55,6 +56,7 @@ func NewPersistOptions(cfg *Config) *PersistOptions {
o.labelProperty.Store(cfg.LabelProperty)
o.SetClusterVersion(&cfg.ClusterVersion)
o.ttl = make(map[string]*cache.TTLString, 6)
o.ttlCancel = make(map[string]context.CancelFunc, 6)
return o
}

Expand Down Expand Up @@ -613,12 +615,15 @@ func (o *PersistOptions) CheckLabelProperty(typ string, labels []*metapb.StoreLa
}

// SetTTLData set temporary configuration
func (o *PersistOptions) SetTTLData(ctx context.Context, key string, value interface{}, ttl time.Duration) {
func (o *PersistOptions) SetTTLData(parCtx context.Context, key string, value interface{}, ttl time.Duration) {
if data, ok := o.ttl[key]; ok {
data.Clear()
o.ttlCancel[key]()
}
ctx, cancel := context.WithCancel(parCtx)
o.ttl[key] = cache.NewStringTTL(ctx, 5*time.Second, ttl)
o.ttl[key].Put(key, value)
o.ttlCancel[key] = cancel
}

func (o *PersistOptions) getTTLData(key string) (interface{}, bool) {
Expand Down

0 comments on commit 1f67ff2

Please sign in to comment.