Signed-off-by: Sugu Sougoumarane <ssougou@gmail.com>
This commit is contained in:
Sugu Sougoumarane 2020-08-23 20:03:59 -07:00
Родитель cb926e9599
Коммит 26c2dd3869
2 изменённых файлов: 38 добавлений и 0 удалений

Просмотреть файл

@ -1,5 +1,6 @@
{
"Debug": true,
"Durability": "cross_cell",
"MySQLTopologyUser": "orc_client_user",
"MySQLTopologyPassword": "orc_client_user_password",
"MySQLReplicaUser": "vt_repl",

Просмотреть файл

@ -23,6 +23,8 @@ import (
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)
//=======================================================================
var (
durabilityPolicies = make(map[string]durabler)
curDurabilityPolicy durabler
@ -31,6 +33,7 @@ var (
func init() {
registerDurability("none", &durabilityNone{})
registerDurability("semi_sync", &durabilitySemiSync{})
registerDurability("cross_cell", &durabilityCrossCell{})
}
type durabler interface {
@ -46,6 +49,8 @@ func registerDurability(name string, d durabler) {
durabilityPolicies[name] = d
}
//=======================================================================
func SetDurabilityPolicy(name string) error {
curDurabilityPolicy = durabilityPolicies[name]
if curDurabilityPolicy == nil {
@ -85,6 +90,8 @@ func ReplicaSemiSyncFromTablet(master, replica *topodatapb.Tablet) bool {
return curDurabilityPolicy.replicaSemiSync(master, replica)
}
//=======================================================================
type durabilityNone struct{}
func (d *durabilityNone) promotionRule(tablet *topodatapb.Tablet) CandidatePromotionRule {
@ -103,6 +110,8 @@ func (d *durabilityNone) replicaSemiSync(master, replica *topodatapb.Tablet) boo
return false
}
//=======================================================================
type durabilitySemiSync struct{}
func (d *durabilitySemiSync) promotionRule(tablet *topodatapb.Tablet) CandidatePromotionRule {
@ -124,3 +133,31 @@ func (d *durabilitySemiSync) replicaSemiSync(master, replica *topodatapb.Tablet)
}
return false
}
//=======================================================================
type durabilityCrossCell struct{}
func (d *durabilityCrossCell) promotionRule(tablet *topodatapb.Tablet) CandidatePromotionRule {
switch tablet.Type {
case topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA:
return NeutralPromoteRule
}
return MustNotPromoteRule
}
func (d *durabilityCrossCell) masterSemiSync(instanceKey InstanceKey) int {
return 1
}
func (d *durabilityCrossCell) replicaSemiSync(master, replica *topodatapb.Tablet) bool {
// Prevent panics.
if master.Alias == nil || replica.Alias == nil {
return false
}
switch replica.Type {
case topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA:
return master.Alias.Cell != replica.Alias.Cell
}
return false
}