-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Skip recalculating the rate in MaxReplicationLagModule when it can't be done #12620
Changes from 3 commits
94ba253
23fdd00
8b3f654
8c06d54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"vitess.io/vitess/go/vt/log" | ||
|
||
"vitess.io/vitess/go/vt/discovery" | ||
|
@@ -83,6 +85,12 @@ func (tf *testFixture) process(lagRecord replicationLagRecord) { | |
tf.m.processRecord(lagRecord) | ||
} | ||
|
||
// recalculateRate does the same thing as MaxReplicationLagModule.recalculateRate() does | ||
// for a new "lagRecord". | ||
func (tf *testFixture) recalculateRate(lagRecord replicationLagRecord) { | ||
tf.m.recalculateRate(lagRecord) | ||
} | ||
|
||
func (tf *testFixture) checkState(state state, rate int64, lastRateChange time.Time) error { | ||
if got, want := tf.m.currentState, state; got != want { | ||
return fmt.Errorf("module in wrong state. got = %v, want = %v", got, want) | ||
|
@@ -96,6 +104,47 @@ func (tf *testFixture) checkState(state state, rate int64, lastRateChange time.T | |
return nil | ||
} | ||
|
||
func TestNewMaxReplicationLagModule_recalculateRate(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
lagRecord replicationLagRecord | ||
expectPanic bool | ||
}{ | ||
{ | ||
name: "Zero lag", | ||
lagRecord: replicationLagRecord{ | ||
time: time.Time{}, | ||
TabletHealth: discovery.TabletHealth{Stats: nil}, | ||
}, | ||
expectPanic: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not in this PR, but we should revisit all the panics in the throttler code base. Better to return a well-known error and exit cleanly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I was very surprised when I saw that this code just panics There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deepthi / @ejortegau: |
||
}, | ||
{ | ||
name: "nil lag record stats", | ||
lagRecord: replicationLagRecord{ | ||
time: time.Now(), | ||
TabletHealth: discovery.TabletHealth{Stats: nil}, | ||
}, | ||
expectPanic: false, | ||
}, | ||
} | ||
|
||
for _, aTestCase := range testCases { | ||
theCase := aTestCase | ||
|
||
t.Run(theCase.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
fixture, err := newTestFixtureWithMaxReplicationLag(5) | ||
assert.NoError(t, err) | ||
|
||
if theCase.expectPanic { | ||
assert.Panics(t, func() { fixture.recalculateRate(theCase.lagRecord) }) | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
|
||
func TestMaxReplicationLagModule_RateNotZeroWhenDisabled(t *testing.T) { | ||
tf, err := newTestFixtureWithMaxReplicationLag(ReplicationLagModuleDisabled) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Isn't this zero time, not zero lag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I called it Zero lag because it tests the case here trigerring a panic when
lagRecordNow.isZero()
isTrue
.