Skip to content
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

Make Durabler interface methods public #15548

Merged
merged 11 commits into from
Mar 29, 2024
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
Loading