Skip to content

Commit

Permalink
Cover configuration changes
Browse files Browse the repository at this point in the history
Signed-off-by: MyonKeminta <MyonKeminta@users.noreply.github.com>
  • Loading branch information
MyonKeminta committed Nov 6, 2024
1 parent 5a322d8 commit 59d5568
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions oracle/oracles/pd.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ func (o *pdOracle) nextUpdateInterval(now time.Time, requiredStaleness time.Dura
}

lastReachDropThresholdTime := time.UnixMilli(o.adaptiveUpdateIntervalState.lastReachDropThresholdTime.Load())
if now.Sub(lastReachDropThresholdTime) < adaptiveUpdateTSIntervalDelayBeforeRecovering {
if now.Sub(lastReachDropThresholdTime) < adaptiveUpdateTSIntervalDelayBeforeRecovering && currentAdaptiveInterval != configuredInterval {
// There is a recent request that requires a short staleness. Keep the current adaptive interval.

if currentAdaptiveInterval != configuredInterval && o.adaptiveUpdateIntervalState.state != adaptiveUpdateTSIntervalStateAdapting {
if o.adaptiveUpdateIntervalState.state != adaptiveUpdateTSIntervalStateAdapting {
logutil.Logger(context.Background()).Info("update low resolution ts interval is not recovering as there is a recent read requesting a short staleness",
zap.Duration("currentAdaptiveUpdateInterval", currentAdaptiveInterval),
zap.Duration("configuredInterval", configuredInterval),
Expand Down
39 changes: 39 additions & 0 deletions oracle/oracles/pd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,44 @@ func TestNextUpdateTSInterval(t *testing.T) {
// Test adjusting configurations manually.
// When the adaptive update interval is not taking effect, the actual used update interval follows the change of
// the configuration immediately.
err = o.SetLowResolutionTimestampUpdateInterval(time.Second * 1)
assert.NoError(t, err)
assert.Equal(t, time.Second, time.Duration(o.adaptiveLastTSUpdateInterval.Load()))
assert.Equal(t, time.Second, o.nextUpdateInterval(now, 0))

err = o.SetLowResolutionTimestampUpdateInterval(time.Second * 2)
assert.NoError(t, err)
assert.Equal(t, time.Second*2, time.Duration(o.adaptiveLastTSUpdateInterval.Load()))
assert.Equal(t, time.Second*2, o.nextUpdateInterval(now, 0))

// If the adaptive update interval is taking effect, the configuration change doesn't immediately affect the actual
// update interval.
now = now.Add(time.Second)
o.adjustUpdateLowResolutionTSIntervalWithRequestedStaleness(mockTS(time.Second), mockTS(0), now)
mustNotifyShrinking(time.Second)
expectedInterval = time.Second - adaptiveUpdateTSIntervalShrinkingPreserve
assert.Equal(t, expectedInterval, o.nextUpdateInterval(now, time.Second))
assert.Equal(t, adaptiveUpdateTSIntervalStateAdapting, o.adaptiveUpdateIntervalState.state)
err = o.SetLowResolutionTimestampUpdateInterval(time.Second * 3)
assert.NoError(t, err)
assert.Equal(t, expectedInterval, time.Duration(o.adaptiveLastTSUpdateInterval.Load()))
assert.Equal(t, expectedInterval, o.nextUpdateInterval(now, 0))
err = o.SetLowResolutionTimestampUpdateInterval(time.Second)
assert.NoError(t, err)
assert.Equal(t, expectedInterval, time.Duration(o.adaptiveLastTSUpdateInterval.Load()))
assert.Equal(t, expectedInterval, o.nextUpdateInterval(now, 0))

// ...unless it's set to a value shorter than the current actual update interval.
err = o.SetLowResolutionTimestampUpdateInterval(time.Millisecond * 800)
assert.NoError(t, err)
assert.Equal(t, time.Millisecond*800, time.Duration(o.adaptiveLastTSUpdateInterval.Load()))
assert.Equal(t, time.Millisecond*800, o.nextUpdateInterval(now, 0))
assert.Equal(t, adaptiveUpdateTSIntervalStateNormal, o.adaptiveUpdateIntervalState.state)

// If the configured value is too short, the actual update interval won't be adaptive
err = o.SetLowResolutionTimestampUpdateInterval(minAllowedAdaptiveUpdateTSInterval / 2)
assert.NoError(t, err)
assert.Equal(t, minAllowedAdaptiveUpdateTSInterval/2, time.Duration(o.adaptiveLastTSUpdateInterval.Load()))
assert.Equal(t, minAllowedAdaptiveUpdateTSInterval/2, o.nextUpdateInterval(now, 0))
assert.Equal(t, adaptiveUpdateTSIntervalStateUnadjustable, o.adaptiveUpdateIntervalState.state)
}

0 comments on commit 59d5568

Please sign in to comment.