Skip to content

Commit

Permalink
Make Durabler interface methods public (#15548)
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
Signed-off-by: Manan Gupta <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
  • Loading branch information
timvaillancourt and GuptaManan100 authored Mar 29, 2024
1 parent 6d88acd commit aa52fbd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
12 changes: 12 additions & 0 deletions changelog/20.0/20.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [`shutdown_grace_period` Default Change](#shutdown-grace-period-default)
- [New `unmanaged` Flag and `disable_active_reparents` deprecation](#unmanaged-flag)
- [`mysqlctld` `onterm-timeout` Default Change](#mysqlctld-onterm-timeout)
- [`Durabler` interface method renaming](#durabler-interface-method-renaming)
- **[Query Compatibility](#query-compatibility)**
- [Vindex Hints](#vindex-hints)
- [Update with Limit Support](#update-limit)
Expand Down Expand Up @@ -45,6 +46,17 @@ The `--onterm_timeout` flag default value has changed for `mysqlctld`. It now is

This is necessary since otherwise MySQL would never shut down cleanly with the old defaults, since `mysqlctld` would shut down already after 10 seconds by default.

#### <a id="durabler-interface-method-renaming"/>`Durabler` interface method renaming

The methods of [the `Durabler` interface](https://github.com/vitessio/vitess/blob/main/go/vt/vtctl/reparentutil/durability.go#L70-L79) in `go/vt/vtctl/reparentutil` were renamed to be public _(capitalized)_ methods to make it easier to integrate custom Durability Policies from external packages. See [RFC for details](https://github.com/vitessio/vitess/issues/15544).

Users of custom Durability Policies must rename private `Durabler` methods.

Changes:
- The `promotionRule` method was renamed to `PromotionRule`
- The `semiSyncAckers` method was renamed to `SemiSyncAckers`
- The `isReplicaSemiSync` method was renamed to `IsReplicaSemiSync`

### <a id="query-compatibility"/>Query Compatibility

#### <a id="vindex-hints"/> Vindex Hints
Expand Down
66 changes: 33 additions & 33 deletions go/vt/vtctl/reparentutil/durability.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func init() {

// Durabler is the interface which is used to get the promotion rules for candidates and the semi sync setup
type Durabler interface {
// promotionRule represents the precedence in which we want to tablets to be promoted.
// PromotionRule represents the precedence in which we want to tablets to be promoted.
// The higher the promotion rule of a tablet, the more we want it to be promoted in case of a failover
promotionRule(*topodatapb.Tablet) promotionrule.CandidatePromotionRule
// semiSyncAckers represents the number of semi-sync ackers required for a given tablet if it were to become the PRIMARY instance
semiSyncAckers(*topodatapb.Tablet) int
// isReplicaSemiSync returns whether the "replica" should send semi-sync acks if "primary" were to become the PRIMARY instance
isReplicaSemiSync(primary, replica *topodatapb.Tablet) bool
PromotionRule(*topodatapb.Tablet) promotionrule.CandidatePromotionRule
// SemiSyncAckers represents the number of semi-sync ackers required for a given tablet if it were to become the PRIMARY instance
SemiSyncAckers(*topodatapb.Tablet) int
// IsReplicaSemiSync returns whether the "replica" should send semi-sync acks if "primary" were to become the PRIMARY instance
IsReplicaSemiSync(primary, replica *topodatapb.Tablet) bool
}

func RegisterDurability(name string, newDurablerFunc NewDurabler) {
Expand Down Expand Up @@ -108,13 +108,13 @@ func PromotionRule(durability Durabler, tablet *topodatapb.Tablet) promotionrule
if tablet == nil || tablet.Alias == nil {
return promotionrule.MustNot
}
return durability.promotionRule(tablet)
return durability.PromotionRule(tablet)
}

// SemiSyncAckers returns the primary semi-sync setting for the instance.
// 0 means none. Non-zero specifies the number of required ackers.
func SemiSyncAckers(durability Durabler, tablet *topodatapb.Tablet) int {
return durability.semiSyncAckers(tablet)
return durability.SemiSyncAckers(tablet)
}

// IsReplicaSemiSync returns the replica semi-sync setting from the tablet record.
Expand All @@ -124,30 +124,30 @@ func IsReplicaSemiSync(durability Durabler, primary, replica *topodatapb.Tablet)
if primary == nil || primary.Alias == nil || replica == nil || replica.Alias == nil {
return false
}
return durability.isReplicaSemiSync(primary, replica)
return durability.IsReplicaSemiSync(primary, replica)
}

//=======================================================================

// durabilityNone has no semi-sync and returns NeutralPromoteRule for Primary and Replica tablet types, MustNotPromoteRule for everything else
type durabilityNone struct{}

// promotionRule implements the Durabler interface
func (d *durabilityNone) promotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
// PromotionRule implements the Durabler interface
func (d *durabilityNone) PromotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
switch tablet.Type {
case topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA:
return promotionrule.Neutral
}
return promotionrule.MustNot
}

// semiSyncAckers implements the Durabler interface
func (d *durabilityNone) semiSyncAckers(tablet *topodatapb.Tablet) int {
// SemiSyncAckers implements the Durabler interface
func (d *durabilityNone) SemiSyncAckers(tablet *topodatapb.Tablet) int {
return 0
}

// isReplicaSemiSync implements the Durabler interface
func (d *durabilityNone) isReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
// IsReplicaSemiSync implements the Durabler interface
func (d *durabilityNone) IsReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
return false
}

Expand All @@ -159,22 +159,22 @@ type durabilitySemiSync struct {
rdonlySemiSync bool
}

// promotionRule implements the Durabler interface
func (d *durabilitySemiSync) promotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
// PromotionRule implements the Durabler interface
func (d *durabilitySemiSync) PromotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
switch tablet.Type {
case topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA:
return promotionrule.Neutral
}
return promotionrule.MustNot
}

// semiSyncAckers implements the Durabler interface
func (d *durabilitySemiSync) semiSyncAckers(tablet *topodatapb.Tablet) int {
// SemiSyncAckers implements the Durabler interface
func (d *durabilitySemiSync) SemiSyncAckers(tablet *topodatapb.Tablet) int {
return 1
}

// isReplicaSemiSync implements the Durabler interface
func (d *durabilitySemiSync) isReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
// IsReplicaSemiSync implements the Durabler interface
func (d *durabilitySemiSync) IsReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
switch replica.Type {
case topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA:
return true
Expand All @@ -193,22 +193,22 @@ type durabilityCrossCell struct {
rdonlySemiSync bool
}

// promotionRule implements the Durabler interface
func (d *durabilityCrossCell) promotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
// PromotionRule implements the Durabler interface
func (d *durabilityCrossCell) PromotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
switch tablet.Type {
case topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA:
return promotionrule.Neutral
}
return promotionrule.MustNot
}

// semiSyncAckers implements the Durabler interface
func (d *durabilityCrossCell) semiSyncAckers(tablet *topodatapb.Tablet) int {
// SemiSyncAckers implements the Durabler interface
func (d *durabilityCrossCell) SemiSyncAckers(tablet *topodatapb.Tablet) int {
return 1
}

// isReplicaSemiSync implements the Durabler interface
func (d *durabilityCrossCell) isReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
// IsReplicaSemiSync implements the Durabler interface
func (d *durabilityCrossCell) IsReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
switch replica.Type {
case topodatapb.TabletType_PRIMARY, topodatapb.TabletType_REPLICA:
return primary.Alias.Cell != replica.Alias.Cell
Expand All @@ -223,8 +223,8 @@ func (d *durabilityCrossCell) isReplicaSemiSync(primary, replica *topodatapb.Tab
// durabilityTest is like durabilityNone. It overrides the type for a specific tablet to prefer. It is only meant to be used for testing purposes!
type durabilityTest struct{}

// promotionRule implements the Durabler interface
func (d *durabilityTest) promotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
// PromotionRule implements the Durabler interface
func (d *durabilityTest) PromotionRule(tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule {
if topoproto.TabletAliasString(tablet.Alias) == "zone2-0000000200" {
return promotionrule.Prefer
}
Expand All @@ -236,12 +236,12 @@ func (d *durabilityTest) promotionRule(tablet *topodatapb.Tablet) promotionrule.
return promotionrule.MustNot
}

// semiSyncAckers implements the Durabler interface
func (d *durabilityTest) semiSyncAckers(tablet *topodatapb.Tablet) int {
// SemiSyncAckers implements the Durabler interface
func (d *durabilityTest) SemiSyncAckers(tablet *topodatapb.Tablet) int {
return 0
}

// isReplicaSemiSync implements the Durabler interface
func (d *durabilityTest) isReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
// IsReplicaSemiSync implements the Durabler interface
func (d *durabilityTest) IsReplicaSemiSync(primary, replica *topodatapb.Tablet) bool {
return false
}
2 changes: 1 addition & 1 deletion go/vt/vtctl/reparentutil/durability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestDurabilityTest(t *testing.T) {

for _, testcase := range testcases {
t.Run(topoproto.TabletAliasString(testcase.tablet.Alias), func(t *testing.T) {
rule := durabilityRules.promotionRule(testcase.tablet)
rule := durabilityRules.PromotionRule(testcase.tablet)
assert.Equal(t, testcase.promotionRule, rule)
})
}
Expand Down

0 comments on commit aa52fbd

Please sign in to comment.