-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
br: add chaos testing for advancer owner #58183
Merged
ti-chi-bot
merged 5 commits into
pingcap:master
from
Tristan1900:expose-config-for-test
Dec 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,19 @@ import ( | |
const ( | ||
flagBackoffTime = "backoff-time" | ||
flagTickInterval = "tick-interval" | ||
flagFullScanDiffTick = "full-scan-tick" | ||
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. removed since not used |
||
flagAdvancingByCache = "advancing-by-cache" | ||
flagTryAdvanceThreshold = "try-advance-threshold" | ||
flagCheckPointLagLimit = "check-point-lag-limit" | ||
|
||
DefaultConsistencyCheckTick = 5 | ||
DefaultTryAdvanceThreshold = 4 * time.Minute | ||
DefaultCheckPointLagLimit = 48 * time.Hour | ||
DefaultBackOffTime = 5 * time.Second | ||
DefaultTickInterval = 12 * time.Second | ||
DefaultFullScanTick = 4 | ||
DefaultAdvanceByCache = true | ||
// used for chaos testing | ||
BornChanger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flagOwnerRetireInterval = "advance-owner-resign-interval" | ||
|
||
DefaultTryAdvanceThreshold = 4 * time.Minute | ||
DefaultCheckPointLagLimit = 48 * time.Hour | ||
BornChanger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
DefaultBackOffTime = 5 * time.Second | ||
DefaultTickInterval = 12 * time.Second | ||
|
||
// used for chaos testing, default to disable | ||
DefaultAdvancerOwnerRetireInterval = 0 | ||
) | ||
|
||
var ( | ||
|
@@ -38,6 +39,11 @@ type Config struct { | |
TryAdvanceThreshold time.Duration `toml:"try-advance-threshold" json:"try-advance-threshold"` | ||
// The maximum lag could be tolerated for the checkpoint lag. | ||
CheckPointLagLimit time.Duration `toml:"check-point-lag-limit" json:"check-point-lag-limit"` | ||
|
||
// Following configs are used in chaos testings, better not to enable in prod | ||
// | ||
// used to periodically retire advancer owner for chaos testing | ||
AdvancerOwnerRetireInterval time.Duration `toml:"advancer-owner-retire-interval" json:"advancer-owner-retire-interval"` | ||
} | ||
|
||
func DefineFlagsForCheckpointAdvancerConfig(f *pflag.FlagSet) { | ||
|
@@ -49,6 +55,10 @@ func DefineFlagsForCheckpointAdvancerConfig(f *pflag.FlagSet) { | |
"If the checkpoint lag is greater than how long, we would try to poll TiKV for checkpoints.") | ||
f.Duration(flagCheckPointLagLimit, DefaultCheckPointLagLimit, | ||
"The maximum lag could be tolerated for the checkpoint lag.") | ||
|
||
// used for chaos testing | ||
f.Duration(flagOwnerRetireInterval, DefaultAdvancerOwnerRetireInterval, | ||
"The interval that the owner will retire itself") | ||
} | ||
|
||
func Default() Config { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ func TestDaemon(t *testing.T) { | |
req := require.New(t) | ||
app := newTestApp(t) | ||
ow := owner.NewMockManager(ctx, "owner_daemon_test", nil, "owner_key") | ||
d := daemon.New(app, ow, 100*time.Millisecond) | ||
d := daemon.New(app, ow, 100*time.Millisecond, 0) | ||
|
||
app.AssertService(req, false) | ||
f, err := d.Begin(ctx) | ||
|
@@ -149,10 +149,44 @@ func TestDaemon(t *testing.T) { | |
ow.RetireOwner() | ||
req.False(ow.IsOwner()) | ||
app.AssertNotRunning(1 * time.Second) | ||
ow.CampaignOwner() | ||
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. it doesn't need to campaign again to become leader since only one node |
||
req.Eventually(func() bool { | ||
return ow.IsOwner() | ||
}, 1*time.Second, 100*time.Millisecond) | ||
app.AssertStart(1 * time.Second) | ||
app.AssertTick(1 * time.Second) | ||
|
||
// make sure chaos did not kick in so never retires | ||
req.Neverf(func() bool { | ||
return !ow.IsOwner() | ||
}, 5*time.Second, 100*time.Millisecond, "should never retire") | ||
} | ||
|
||
func TestDaemonWithChaos(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
req := require.New(t) | ||
app := newTestApp(t) | ||
ow := owner.NewMockManager(ctx, "owner_daemon_test", nil, "owner_key") | ||
d := daemon.New(app, ow, 100*time.Millisecond, 2*time.Second) | ||
|
||
app.AssertService(req, false) | ||
f, err := d.Begin(ctx) | ||
req.NoError(err) | ||
app.AssertService(req, true) | ||
go f() | ||
|
||
// wait for it to become owner | ||
req.Eventually(func() bool { | ||
return ow.IsOwner() | ||
}, 1*time.Second, 100*time.Millisecond) | ||
|
||
// wait for chaos test to kick in to auto retire | ||
req.Eventually(func() bool { | ||
return !ow.IsOwner() | ||
}, 3*time.Second, 500*time.Millisecond) | ||
|
||
// sanity check it will try to become leader in background again | ||
req.Eventually(func() bool { | ||
return ow.IsOwner() | ||
}, 2*time.Second, 500*time.Millisecond) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
removed since not used