Skip to content

Commit

Permalink
refactor switch_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
suetin committed Jun 13, 2024
1 parent 1468bb5 commit 6937a8b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
30 changes: 10 additions & 20 deletions internal/mysql/switch_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,23 @@ type ISwitchHelper interface {
GetPriorityChoiceMaxLag() time.Duration
}

type DefaultSwitchHelper struct {
config *config.Config
}

type AsyncSwitchHelper struct {
config *config.Config
type SwitchHelper struct {
priorityChoiceMaxLag time.Duration
}

func NewSwitchHelper(config *config.Config) ISwitchHelper {
priorityChoiceMaxLag := config.PriorityChoiceMaxLag
if config.ASync {
return &AsyncSwitchHelper{
config: config,
AsyncAllowedLagTime := time.Duration(config.AsyncAllowedLag) * time.Second
if AsyncAllowedLagTime > config.PriorityChoiceMaxLag {
priorityChoiceMaxLag = AsyncAllowedLagTime
}
}
return &DefaultSwitchHelper{
config: config,
return &SwitchHelper{
priorityChoiceMaxLag: priorityChoiceMaxLag,
}
}

func (sh *DefaultSwitchHelper) GetPriorityChoiceMaxLag() time.Duration {
return sh.config.PriorityChoiceMaxLag
}

func (sh *AsyncSwitchHelper) GetPriorityChoiceMaxLag() time.Duration {
AsyncAllowedLagTime := time.Duration(sh.config.AsyncAllowedLag) * time.Second
if AsyncAllowedLagTime > sh.config.PriorityChoiceMaxLag {
return AsyncAllowedLagTime
}
return sh.config.PriorityChoiceMaxLag
func (sh *SwitchHelper) GetPriorityChoiceMaxLag() time.Duration {
return sh.priorityChoiceMaxLag
}
2 changes: 1 addition & 1 deletion tests/features/async_setting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Feature: mysync async mode tests
"""
INSERT INTO mysql.test_table1 VALUES ("D"), ("E"), ("F")
"""
And I wait for "70" seconds
And I wait for "40" seconds
When I run SQL on mysql host "mysql2"
"""
SELECT GROUP_CONCAT(value) as val from (SELECT value from mysql.test_table1 order by value) as t
Expand Down

0 comments on commit 6937a8b

Please sign in to comment.