From 239dc7eb134f9677fe938f8bcc73faabc1534f9e Mon Sep 17 00:00:00 2001 From: MyonKeminta <9948422+MyonKeminta@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:30:11 +0800 Subject: [PATCH] Fix the problem that adaptive update interval doesn't recovers back and there's too much logs about setting the config (#1502) Signed-off-by: MyonKeminta --- oracle/oracles/pd.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/oracle/oracles/pd.go b/oracle/oracles/pd.go index b03e3eb6f5..6e7fb9b6f1 100644 --- a/oracle/oracles/pd.go +++ b/oracle/oracles/pd.go @@ -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 { @@ -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)