Documentation ¶
Index ¶
- func ChooseNewPrimary(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]mysql.Position, error)
- func ReplicaWasRunning(stopStatus *replicationdatapb.StopReplicationStatus) (bool, error)
- func StopReplicationAndBuildStatusMaps(ctx context.Context, tmc tmclient.TabletManagerClient, ev *events.Reparent, ...) (map[string]*replicationdatapb.StopReplicationStatus, ...)
- func WaitForRelayLogsToApply(ctx context.Context, tmc tmclient.TabletManagerClient, ...) error
- type EmergencyReparentOptions
- type EmergencyReparenter
- type PlannedReparentOptions
- type PlannedReparenter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChooseNewPrimary ¶
func ChooseNewPrimary( ctx context.Context, tmc tmclient.TabletManagerClient, shardInfo *topo.ShardInfo, tabletMap map[string]*topo.TabletInfo, avoidPrimaryAlias *topodatapb.TabletAlias, waitReplicasTimeout time.Duration, logger logutil.Logger, ) (*topodatapb.TabletAlias, error)
ChooseNewPrimary 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.
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 MASTER (if any) has the most recent MasterTermStartTime, which is the same rule that vtgate uses to route master 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 MASTER, or if multiple tablets claim to be type MASTER and happen to have the same MasterTermStartTime 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.MasterStatus, ) (map[string]mysql.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 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 StopReplicationAndBuildStatusMaps ¶
func StopReplicationAndBuildStatusMaps( ctx context.Context, tmc tmclient.TabletManagerClient, ev *events.Reparent, tabletMap map[string]*topo.TabletInfo, waitReplicasTimeout time.Duration, ignoredTablets sets.String, logger logutil.Logger, ) (map[string]*replicationdatapb.StopReplicationStatus, map[string]*replicationdatapb.MasterStatus, error)
StopReplicationAndBuildStatusMaps stops replication on all replicas, then collects and returns a mapping of TabletAlias (as string) to their current replication positions.
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 EmergencyReparentOptions ¶
type EmergencyReparentOptions struct { NewPrimaryAlias *topodatapb.TabletAlias IgnoreReplicas sets.String WaitReplicasTimeout time.Duration // 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 PlannedReparentOptions ¶
type PlannedReparentOptions struct { NewPrimaryAlias *topodatapb.TabletAlias AvoidPrimaryAlias *topodatapb.TabletAlias WaitReplicasTimeout 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.