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

Fix the problem that adaptive update interval doesn't recovers back and there's too much logs about setting the config #1502

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion oracle/oracles/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ func (o *pdOracle) updateTS(ctx context.Context) {
ticker := time.NewTicker(currentInterval)
defer ticker.Stop()

// Note that as `doUpdate` updates last tick time while `nextUpdateInterval` may perform calculation depending on the
// last tick time, `doUpdate` should be called after finishing calculating the next interval.
doUpdate := func(now time.Time) {
// Update the timestamp for each txnScope
o.lastTSMap.Range(func(key, _ interface{}) bool {
Expand All @@ -492,9 +494,12 @@ func (o *pdOracle) updateTS(ctx context.Context) {
for {
select {
case now := <-ticker.C:
// nextUpdateInterval has calculation that depends on the time of the last tick. Calculate next interval
// before `doUpdate` as `doUpdate` is responsible for updating the time of the last tick.
newInterval := o.nextUpdateInterval(now, 0)

doUpdate(now)

newInterval := o.nextUpdateInterval(now, 0)
if newInterval != currentInterval {
currentInterval = newInterval
ticker.Reset(currentInterval)
Expand Down Expand Up @@ -557,6 +562,11 @@ func (o *pdOracle) SetLowResolutionTimestampUpdateInterval(newUpdateInterval tim
prevConfigured := o.lastTSUpdateInterval.Swap(int64(newUpdateInterval))
adaptiveUpdateInterval := o.adaptiveLastTSUpdateInterval.Load()

if newUpdateInterval == time.Duration(prevConfigured) {
// The config is unchanged. Do nothing.
return nil
}

var adaptiveUpdateIntervalUpdated bool

if adaptiveUpdateInterval == prevConfigured || newUpdateInterval < time.Duration(adaptiveUpdateInterval) {
Expand Down
Loading