Skip to content

Commit

Permalink
Fix the problem that adaptive update interval doesn't recovers back a…
Browse files Browse the repository at this point in the history
…nd there's too much logs about setting the config (tikv#1502) (tikv#1504)

 

Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
  • Loading branch information
MyonKeminta committed Dec 10, 2024
1 parent 3c490da commit 72f4990
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion oracle/oracles/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,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 @@ -478,9 +480,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

0 comments on commit 72f4990

Please sign in to comment.