Documentation ¶
Index ¶
- func CheckDurabilityPolicyExists(name string) bool
- func ElectNewPrimary(ctx context.Context, tmc tmclient.TabletManagerClient, ...) (*topodatapb.TabletAlias, error)
- func FindCurrentPrimary(tabletMap map[string]*topo.TabletInfo, logger logutil.Logger) *topo.TabletInfo
- func FindValidEmergencyReparentCandidates(statusMap map[string]*replicationdatapb.StopReplicationStatus, ...) (map[string]replication.Position, error)
- func GetBackupCandidates(tablets []*topo.TabletInfo, stats []*replicationdatapb.Status) (res []*topo.TabletInfo)
- func IsReplicaSemiSync(durability Durabler, primary, replica *topodatapb.Tablet) bool
- func PromotionRule(durability Durabler, tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule
- func RegisterDurability(name string, newDurablerFunc NewDurabler)
- func ReplicaWasRunning(stopStatus *replicationdatapb.StopReplicationStatus) (bool, error)
- func SQLThreadWasRunning(stopStatus *replicationdatapb.StopReplicationStatus) (bool, error)
- func SemiSyncAckers(durability Durabler, tablet *topodatapb.Tablet) int
- func SemiSyncAckersForPrimary(durability Durabler, primary *topodatapb.Tablet, ...) (semiSyncAckers []*topodatapb.Tablet)
- func SetReplicationSource(ctx context.Context, ts *topo.Server, tmc tmclient.TabletManagerClient, ...) error
- func ShardReplicationStatuses(ctx context.Context, ts *topo.Server, tmc tmclient.TabletManagerClient, ...) ([]*topo.TabletInfo, []*replicationdatapb.Status, error)
- func WaitForRelayLogsToApply(ctx context.Context, tmc tmclient.TabletManagerClient, ...) error
- type Durabler
- type EmergencyReparentOptions
- type EmergencyReparenter
- type NewDurabler
- type PlannedReparentOptions
- type PlannedReparenter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckDurabilityPolicyExists ¶
CheckDurabilityPolicyExists is used to check if the durability policy is part of the registered policies
func ElectNewPrimary ¶
func ElectNewPrimary( ctx context.Context, tmc tmclient.TabletManagerClient, shardInfo *topo.ShardInfo, tabletMap map[string]*topo.TabletInfo, newPrimaryAlias *topodatapb.TabletAlias, avoidPrimaryAlias *topodatapb.TabletAlias, waitReplicasTimeout time.Duration, tolerableReplLag time.Duration, durability Durabler, logger logutil.Logger, ) (*topodatapb.TabletAlias, error)
ElectNewPrimary finds a tablet that should become a primary after reparent. The criteria for the new primary-elect are (preferably) to be in the same cell as the current primary, and to be different from avoidPrimaryAlias. The tablet with the most advanced replication position is chosen to minimize the amount of time spent catching up with the current primary. Further ties are broken by the durability rules. Note that the search for the most advanced replication position will race with transactions being executed on the current primary, so when all tablets are at roughly the same position, then the choice of new primary-elect will be somewhat unpredictable.
func FindCurrentPrimary ¶
func FindCurrentPrimary(tabletMap map[string]*topo.TabletInfo, logger logutil.Logger) *topo.TabletInfo
FindCurrentPrimary returns the current primary tablet of a shard, if any. The current primary is whichever tablet of type PRIMARY (if any) has the most recent PrimaryTermStartTime, which is the same rule that vtgate uses to route primary traffic.
The return value is nil if the current primary cannot be definitively determined. This can happen either if no tablet claims to be type PRIMARY, or if multiple tablets claim to be type PRIMARY and happen to have the same PrimaryTermStartTime timestamp (a tie).
The tabletMap must be a complete map (not a partial result) for the shard.
func FindValidEmergencyReparentCandidates ¶
func FindValidEmergencyReparentCandidates( statusMap map[string]*replicationdatapb.StopReplicationStatus, primaryStatusMap map[string]*replicationdatapb.PrimaryStatus, ) (map[string]replication.Position, error)
FindValidEmergencyReparentCandidates will find candidates for an emergency reparent, and, if successful, return a mapping of those tablet aliases (as raw strings) to their replication positions for later comparison.
func GetBackupCandidates ¶
func GetBackupCandidates(tablets []*topo.TabletInfo, stats []*replicationdatapb.Status) (res []*topo.TabletInfo)
GetBackupCandidates is used to get a list of healthy tablets for backup
func IsReplicaSemiSync ¶
func IsReplicaSemiSync(durability Durabler, primary, replica *topodatapb.Tablet) bool
IsReplicaSemiSync returns the replica semi-sync setting from the tablet record. Prefer using this function if tablet record is available.
func PromotionRule ¶
func PromotionRule(durability Durabler, tablet *topodatapb.Tablet) promotionrule.CandidatePromotionRule
PromotionRule returns the promotion rule for the instance.
func RegisterDurability ¶
func RegisterDurability(name string, newDurablerFunc NewDurabler)
func ReplicaWasRunning ¶
func ReplicaWasRunning(stopStatus *replicationdatapb.StopReplicationStatus) (bool, error)
ReplicaWasRunning returns true if a StopReplicationStatus indicates that the replica had running replication threads before being stopped. It returns an error if the Before state of replication is nil.
func SQLThreadWasRunning ¶
func SQLThreadWasRunning(stopStatus *replicationdatapb.StopReplicationStatus) (bool, error)
SQLThreadWasRunning returns true if a StopReplicationStatus indicates that the replica had a running sql thread. It returns an error if the Before state of replication is nil.
func SemiSyncAckers ¶
func SemiSyncAckers(durability Durabler, tablet *topodatapb.Tablet) int
SemiSyncAckers returns the primary semi-sync setting for the instance. 0 means none. Non-zero specifies the number of required ackers.
func SemiSyncAckersForPrimary ¶
func SemiSyncAckersForPrimary(durability Durabler, primary *topodatapb.Tablet, allTablets []*topodatapb.Tablet) (semiSyncAckers []*topodatapb.Tablet)
SemiSyncAckersForPrimary returns the list of tablets which are capable of sending Semi-Sync Acks for the given primary tablet
func SetReplicationSource ¶
func SetReplicationSource(ctx context.Context, ts *topo.Server, tmc tmclient.TabletManagerClient, tablet *topodatapb.Tablet) error
SetReplicationSource is used to set the replication source on the specified tablet to the current shard primary (if available). It also figures out if the tablet should be sending semi-sync ACKs or not and passes that to the tabletmanager RPC.
It does not start the replication forcefully. If we are unable to find the shard primary of the tablet from the topo server we exit out without any error.
func ShardReplicationStatuses ¶
func ShardReplicationStatuses(ctx context.Context, ts *topo.Server, tmc tmclient.TabletManagerClient, keyspace, shard string) ([]*topo.TabletInfo, []*replicationdatapb.Status, error)
ShardReplicationStatuses returns the ReplicationStatus for each tablet in a shard.
func WaitForRelayLogsToApply ¶
func WaitForRelayLogsToApply(ctx context.Context, tmc tmclient.TabletManagerClient, tabletInfo *topo.TabletInfo, status *replicationdatapb.StopReplicationStatus) error
WaitForRelayLogsToApply blocks execution waiting for the given tablet's relay logs to apply, unless the specified context is canceled or exceeded. Typically a caller will set a timeout of WaitReplicasTimeout on a context and use that context with this function.
Types ¶
type Durabler ¶
type Durabler interface { // 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 }
Durabler is the interface which is used to get the promotion rules for candidates and the semi sync setup
func GetDurabilityPolicy ¶
GetDurabilityPolicy is used to get a new durability policy from the registered policies
type EmergencyReparentOptions ¶
type EmergencyReparentOptions struct { NewPrimaryAlias *topodatapb.TabletAlias IgnoreReplicas sets.Set[string] // WaitAllTablets is used to specify whether ERS should wait for all the tablets to return and not proceed // further after n-1 tablets have returned. WaitAllTablets bool WaitReplicasTimeout time.Duration PreventCrossCellPromotion bool // contains filtered or unexported fields }
EmergencyReparentOptions provides optional parameters to EmergencyReparentShard operations. Options are passed by value, so it is safe for callers to mutate and reuse options structs for multiple calls.
type EmergencyReparenter ¶
type EmergencyReparenter struct {
// contains filtered or unexported fields
}
EmergencyReparenter performs EmergencyReparentShard operations.
func NewEmergencyReparenter ¶
func NewEmergencyReparenter(ts *topo.Server, tmc tmclient.TabletManagerClient, logger logutil.Logger) *EmergencyReparenter
NewEmergencyReparenter returns a new EmergencyReparenter object, ready to perform EmergencyReparentShard operations using the given topo.Server, TabletManagerClient, and logger.
Providing a nil logger instance is allowed.
func (*EmergencyReparenter) ReparentShard ¶
func (erp *EmergencyReparenter) ReparentShard(ctx context.Context, keyspace string, shard string, opts EmergencyReparentOptions) (*events.Reparent, error)
ReparentShard performs the EmergencyReparentShard operation on the given keyspace and shard.
type NewDurabler ¶
type NewDurabler func() Durabler
A NewDurabler is a function that creates a new Durabler based on the properties specified in the input map. Every Durabler must register a NewDurabler function.
type PlannedReparentOptions ¶
type PlannedReparentOptions struct { NewPrimaryAlias *topodatapb.TabletAlias AvoidPrimaryAlias *topodatapb.TabletAlias WaitReplicasTimeout time.Duration TolerableReplLag time.Duration // contains filtered or unexported fields }
PlannedReparentOptions provides optional parameters to PlannedReparentShard operations. Options are passed by value, so it is safe for callers to mutate resue options structs for multiple calls.
type PlannedReparenter ¶
type PlannedReparenter struct {
// contains filtered or unexported fields
}
PlannedReparenter performs PlannedReparentShard operations.
func NewPlannedReparenter ¶
func NewPlannedReparenter(ts *topo.Server, tmc tmclient.TabletManagerClient, logger logutil.Logger) *PlannedReparenter
NewPlannedReparenter returns a new PlannedReparenter object, ready to perform PlannedReparentShard operations using the given topo.Server, TabletManagerClient, and logger.
Providing a nil logger instance is allowed.
func (*PlannedReparenter) ReparentShard ¶
func (pr *PlannedReparenter) ReparentShard(ctx context.Context, keyspace string, shard string, opts PlannedReparentOptions) (*events.Reparent, error)
ReparentShard performs a PlannedReparentShard operation on the given keyspace and shard. It will make the provided tablet the primary for the shard, when both the current and desired primary are reachable and in a good state.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package reparenttestutil contains utility functions for writing tests
|
Package reparenttestutil contains utility functions for writing tests |