tabletmanager

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2021 License: Apache-2.0 Imports: 57 Imported by: 5

Documentation

Overview

Package tabletmanager exports the TabletManager object. It keeps the local tablet state, starts / stops all associated services (query service, update stream, binlog players, ...), and handles tabletmanager RPCs to update the state.

The tm is responsible for maintaining the tablet record in the topology server. Only 'vtctl DeleteTablet' should be run by other processes, everything else should ask the tablet server to make the change.

Most RPC calls obtain the actionSema, except the easy read-only ones. RPC calls that change the tablet record will also call updateState.

See rpc_server.go for all cases, and which actions take the actionSema, and which run changeCallback.

Index

Constants

View Source
const (
	DBActionNone = DBAction(iota)
	DBActionSetReadWrite
)

Allowed values for DBAction

Variables

View Source
var RegisterTabletManagers []RegisterTabletManager

RegisterTabletManagers is a list of functions to call when the delayed registration is triggered.

Functions

func BuildTabletFromInput

func BuildTabletFromInput(alias *topodatapb.TabletAlias, port, grpcPort int32) (*topodatapb.Tablet, error)

BuildTabletFromInput builds a tablet record from input parameters.

Types

type DBAction added in v0.8.0

type DBAction int

DBAction is used to tell ChangeTabletType whether to call SetReadOnly on change to MASTER tablet type

type RPCTM

type RPCTM interface {
	Ping(ctx context.Context, args string) string

	GetSchema(ctx context.Context, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)

	GetPermissions(ctx context.Context) (*tabletmanagerdatapb.Permissions, error)

	SetReadOnly(ctx context.Context, rdonly bool) error

	ChangeType(ctx context.Context, tabletType topodatapb.TabletType) error

	Sleep(ctx context.Context, duration time.Duration)

	ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult

	RefreshState(ctx context.Context) error

	RunHealthCheck(ctx context.Context)

	IgnoreHealthError(ctx context.Context, pattern string) error

	ReloadSchema(ctx context.Context, waitPosition string) error

	PreflightSchema(ctx context.Context, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)

	ApplySchema(ctx context.Context, change *tmutils.SchemaChange) (*tabletmanagerdatapb.SchemaChangeResult, error)

	LockTables(ctx context.Context) error

	UnlockTables(ctx context.Context) error

	ExecuteFetchAsDba(ctx context.Context, query []byte, dbName string, maxrows int, disableBinlogs bool, reloadSchema bool) (*querypb.QueryResult, error)

	ExecuteFetchAsAllPrivs(ctx context.Context, query []byte, dbName string, maxrows int, reloadSchema bool) (*querypb.QueryResult, error)

	ExecuteFetchAsApp(ctx context.Context, query []byte, maxrows int) (*querypb.QueryResult, error)

	// Replication related methods
	MasterStatus(ctx context.Context) (*replicationdatapb.MasterStatus, error)

	ReplicationStatus(ctx context.Context) (*replicationdatapb.Status, error)

	StopReplication(ctx context.Context) error

	StopReplicationMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error)

	StartReplication(ctx context.Context) error

	StartReplicationUntilAfter(ctx context.Context, position string, waitTime time.Duration) error

	GetReplicas(ctx context.Context) ([]string, error)

	MasterPosition(ctx context.Context) (string, error)

	WaitForPosition(ctx context.Context, pos string) error

	// VExec generic API
	VExec(ctx context.Context, query, workflow, keyspace string) (*querypb.QueryResult, error)

	// VReplication API
	VReplicationExec(ctx context.Context, query string) (*querypb.QueryResult, error)
	VReplicationWaitForPos(ctx context.Context, id int, pos string) error

	ResetReplication(ctx context.Context) error

	InitMaster(ctx context.Context) (string, error)

	PopulateReparentJournal(ctx context.Context, timeCreatedNS int64, actionName string, masterAlias *topodatapb.TabletAlias, pos string) error

	InitReplica(ctx context.Context, parent *topodatapb.TabletAlias, replicationPosition string, timeCreatedNS int64) error

	DemoteMaster(ctx context.Context) (*replicationdatapb.MasterStatus, error)

	UndoDemoteMaster(ctx context.Context) error

	ReplicaWasPromoted(ctx context.Context) error

	SetMaster(ctx context.Context, parent *topodatapb.TabletAlias, timeCreatedNS int64, waitPosition string, forceStartReplication bool) error

	StopReplicationAndGetStatus(ctx context.Context, stopReplicationMode replicationdatapb.StopReplicationMode) (StopReplicationAndGetStatusResponse, error)

	ReplicaWasRestarted(ctx context.Context, parent *topodatapb.TabletAlias) error

	PromoteReplica(ctx context.Context) (string, error)

	Backup(ctx context.Context, concurrency int, logger logutil.Logger, allowMaster bool) error

	RestoreFromBackup(ctx context.Context, logger logutil.Logger) error

	// HandleRPCPanic is to be called in a defer statement in each
	// RPC input point.
	HandleRPCPanic(ctx context.Context, name string, args, reply interface{}, verbose bool, err *error)
}

RPCTM defines the interface implemented by the TM for RPCs. It is useful for RPC implementations to test their full stack.

type RegisterTabletManager

type RegisterTabletManager func(*TabletManager)

RegisterTabletManager is used to delay registration of RPC servers until we have all the objects.

type StopReplicationAndGetStatusResponse

type StopReplicationAndGetStatusResponse struct {
	// HybridStatus is deprecated. It currently represents a hybrid struct where all data represents the before state,
	// except for all position related data which comes from the after state. Please use status instead, which holds
	// discrete replication status calls before and after stopping the replica, or stopping the replica's io_thread.
	HybridStatus *replicationdatapb.Status

	// Status represents the replication status call right before, and right after telling the replica to stop.
	Status *replicationdatapb.StopReplicationStatus
}

StopReplicationAndGetStatusResponse holds the original hybrid Status struct, as well as a new Status field, which hold the result of show replica status called before stopping replication, and after stopping replication.

type TabletManager

type TabletManager struct {
	// The following fields are set during creation
	BatchCtx            context.Context
	TopoServer          *topo.Server
	Cnf                 *mysqlctl.Mycnf
	MysqlDaemon         mysqlctl.MysqlDaemon
	DBConfigs           *dbconfigs.DBConfigs
	QueryServiceControl tabletserver.Controller
	UpdateStream        binlog.UpdateStreamControl
	VREngine            *vreplication.Engine
	// contains filtered or unexported fields
}

TabletManager is the main class for the tablet manager.

func (*TabletManager) ApplySchema

ApplySchema will apply a schema change

func (*TabletManager) Backup

func (tm *TabletManager) Backup(ctx context.Context, concurrency int, logger logutil.Logger, allowMaster bool) error

Backup takes a db backup and sends it to the BackupStorage

func (*TabletManager) BlacklistedTables

func (tm *TabletManager) BlacklistedTables() []string

BlacklistedTables returns the list of currently blacklisted tables.

func (*TabletManager) ChangeType

func (tm *TabletManager) ChangeType(ctx context.Context, tabletType topodatapb.TabletType) error

ChangeType changes the tablet type

func (*TabletManager) Close

func (tm *TabletManager) Close()

Close prepares a tablet for shutdown. First we check our tablet ownership and then prune the tablet topology entry of all post-init fields. This prevents stale identifiers from hanging around in topology.

func (*TabletManager) DemoteMaster

DemoteMaster prepares a MASTER tablet to give up mastership to another tablet.

It attemps to idempotently ensure the following guarantees upon returning successfully:

  • No future writes will be accepted.
  • No writes are in-flight.
  • MySQL is in read-only mode.
  • Semi-sync settings are consistent with a REPLICA tablet.

If necessary, it waits for all in-flight writes to complete or time out.

It should be safe to call this on a MASTER tablet that was already demoted, or on a tablet that already transitioned to REPLICA.

If a step fails in the middle, it will try to undo any changes it made.

func (*TabletManager) ExecuteFetchAsAllPrivs

func (tm *TabletManager) ExecuteFetchAsAllPrivs(ctx context.Context, query []byte, dbName string, maxrows int, reloadSchema bool) (*querypb.QueryResult, error)

ExecuteFetchAsAllPrivs will execute the given query, possibly reloading schema.

func (*TabletManager) ExecuteFetchAsApp

func (tm *TabletManager) ExecuteFetchAsApp(ctx context.Context, query []byte, maxrows int) (*querypb.QueryResult, error)

ExecuteFetchAsApp will execute the given query.

func (*TabletManager) ExecuteFetchAsDba

func (tm *TabletManager) ExecuteFetchAsDba(ctx context.Context, query []byte, dbName string, maxrows int, disableBinlogs bool, reloadSchema bool) (*querypb.QueryResult, error)

ExecuteFetchAsDba will execute the given query, possibly disabling binlogs and reload schema.

func (*TabletManager) ExecuteHook

func (tm *TabletManager) ExecuteHook(ctx context.Context, hk *hook.Hook) *hook.HookResult

ExecuteHook executes the provided hook locally, and returns the result.

func (*TabletManager) GetPermissions

func (tm *TabletManager) GetPermissions(ctx context.Context) (*tabletmanagerdatapb.Permissions, error)

GetPermissions returns the db permissions.

func (*TabletManager) GetReplicas

func (tm *TabletManager) GetReplicas(ctx context.Context) ([]string, error)

GetReplicas returns the address of all the replicas

func (*TabletManager) GetSchema

func (tm *TabletManager) GetSchema(ctx context.Context, tables, excludeTables []string, includeViews bool) (*tabletmanagerdatapb.SchemaDefinition, error)

GetSchema returns the schema.

func (*TabletManager) HandleRPCPanic

func (tm *TabletManager) HandleRPCPanic(ctx context.Context, name string, args, reply interface{}, verbose bool, err *error)

HandleRPCPanic is part of the RPCTM interface.

func (*TabletManager) IgnoreHealthError

func (tm *TabletManager) IgnoreHealthError(ctx context.Context, pattern string) error

IgnoreHealthError sets the regexp for health check errors to ignore.

func (*TabletManager) InitMaster

func (tm *TabletManager) InitMaster(ctx context.Context) (string, error)

InitMaster enables writes and returns the replication position.

func (*TabletManager) InitReplica

func (tm *TabletManager) InitReplica(ctx context.Context, parent *topodatapb.TabletAlias, position string, timeCreatedNS int64) error

InitReplica sets replication master and position, and waits for the reparent_journal table entry up to context timeout

func (*TabletManager) LockTables

func (tm *TabletManager) LockTables(ctx context.Context) error

LockTables will lock all tables with read locks, effectively pausing replication while the lock is held (idempotent)

func (*TabletManager) MasterPosition

func (tm *TabletManager) MasterPosition(ctx context.Context) (string, error)

MasterPosition returns the master position

func (*TabletManager) MasterStatus

MasterStatus returns the replication status fopr a master tablet.

func (*TabletManager) Ping

func (tm *TabletManager) Ping(ctx context.Context, args string) string

Ping makes sure RPCs work, and refreshes the tablet record.

func (*TabletManager) PopulateReparentJournal

func (tm *TabletManager) PopulateReparentJournal(ctx context.Context, timeCreatedNS int64, actionName string, masterAlias *topodatapb.TabletAlias, position string) error

PopulateReparentJournal adds an entry into the reparent_journal table.

func (*TabletManager) PreflightSchema

func (tm *TabletManager) PreflightSchema(ctx context.Context, changes []string) ([]*tabletmanagerdatapb.SchemaChangeResult, error)

PreflightSchema will try out the schema changes in "changes".

func (*TabletManager) PromoteReplica

func (tm *TabletManager) PromoteReplica(ctx context.Context) (string, error)

PromoteReplica makes the current tablet the master

func (*TabletManager) RefreshState

func (tm *TabletManager) RefreshState(ctx context.Context) error

RefreshState reload the tablet record from the topo server.

func (*TabletManager) ReloadSchema

func (tm *TabletManager) ReloadSchema(ctx context.Context, waitPosition string) error

ReloadSchema will reload the schema This doesn't need the action mutex because periodic schema reloads happen in the background anyway.

func (*TabletManager) ReplicaWasPromoted

func (tm *TabletManager) ReplicaWasPromoted(ctx context.Context) error

ReplicaWasPromoted promotes a replica to master, no questions asked.

func (*TabletManager) ReplicaWasRestarted

func (tm *TabletManager) ReplicaWasRestarted(ctx context.Context, parent *topodatapb.TabletAlias) error

ReplicaWasRestarted updates the parent record for a tablet.

func (*TabletManager) ReplicationStatus

func (tm *TabletManager) ReplicationStatus(ctx context.Context) (*replicationdatapb.Status, error)

ReplicationStatus returns the replication status

func (*TabletManager) ResetReplication

func (tm *TabletManager) ResetReplication(ctx context.Context) error

ResetReplication completely resets the replication on the host. All binary and relay logs are flushed. All replication positions are reset.

func (*TabletManager) RestoreData

func (tm *TabletManager) RestoreData(ctx context.Context, logger logutil.Logger, waitForBackupInterval time.Duration, deleteBeforeRestore bool) error

RestoreData is the main entry point for backup restore. It will either work, fail gracefully, or return an error in case of a non-recoverable error. It takes the action lock so no RPC interferes.

func (*TabletManager) RestoreFromBackup

func (tm *TabletManager) RestoreFromBackup(ctx context.Context, logger logutil.Logger) error

RestoreFromBackup deletes all local data and restores anew from the latest backup.

func (*TabletManager) RunHealthCheck

func (tm *TabletManager) RunHealthCheck(ctx context.Context)

RunHealthCheck will manually run the health check on the tablet.

func (*TabletManager) SetMaster

func (tm *TabletManager) SetMaster(ctx context.Context, parentAlias *topodatapb.TabletAlias, timeCreatedNS int64, waitPosition string, forceStartReplication bool) error

SetMaster sets replication master, and waits for the reparent_journal table entry up to context timeout

func (*TabletManager) SetReadOnly

func (tm *TabletManager) SetReadOnly(ctx context.Context, rdonly bool) error

SetReadOnly makes the mysql instance read-only or read-write.

func (*TabletManager) Sleep

func (tm *TabletManager) Sleep(ctx context.Context, duration time.Duration)

Sleep sleeps for the duration

func (*TabletManager) Start

func (tm *TabletManager) Start(tablet *topodatapb.Tablet, healthCheckInterval time.Duration) error

Start starts the TabletManager.

func (*TabletManager) StartReplication

func (tm *TabletManager) StartReplication(ctx context.Context) error

StartReplication will start the mysql. Works both when Vitess manages replication or not (using hook if not).

func (*TabletManager) StartReplicationUntilAfter

func (tm *TabletManager) StartReplicationUntilAfter(ctx context.Context, position string, waitTime time.Duration) error

StartReplicationUntilAfter will start the replication and let it catch up until and including the transactions in `position`

func (*TabletManager) Stop

func (tm *TabletManager) Stop()

Stop shuts down the tm. Normally this is not necessary, since we use servenv OnTerm and OnClose hooks to coordinate shutdown automatically, while taking lameduck into account. However, this may be useful for tests, when you want to clean up an tm immediately.

func (*TabletManager) StopReplication

func (tm *TabletManager) StopReplication(ctx context.Context) error

StopReplication will stop the mysql. Works both when Vitess manages replication or not (using hook if not).

func (*TabletManager) StopReplicationAndGetStatus

func (tm *TabletManager) StopReplicationAndGetStatus(ctx context.Context, stopReplicationMode replicationdatapb.StopReplicationMode) (StopReplicationAndGetStatusResponse, error)

StopReplicationAndGetStatus stops MySQL replication, and returns the current status.

func (*TabletManager) StopReplicationMinimum

func (tm *TabletManager) StopReplicationMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error)

StopReplicationMinimum will stop the replication after it reaches at least the provided position. Works both when Vitess manages replication or not (using hook if not).

func (*TabletManager) Tablet

func (tm *TabletManager) Tablet() *topodatapb.Tablet

Tablet reads the stored Tablet from the tm.

func (*TabletManager) UndoDemoteMaster

func (tm *TabletManager) UndoDemoteMaster(ctx context.Context) error

UndoDemoteMaster reverts a previous call to DemoteMaster it sets read-only to false, fixes semi-sync and returns its master position.

func (*TabletManager) UnlockTables

func (tm *TabletManager) UnlockTables(ctx context.Context) error

UnlockTables will unlock all tables (idempotent)

func (*TabletManager) VExec added in v0.8.0

func (tm *TabletManager) VExec(ctx context.Context, query, workflow, keyspace string) (*querypb.QueryResult, error)

VExec executes a generic VExec command.

func (*TabletManager) VReplicationExec

func (tm *TabletManager) VReplicationExec(ctx context.Context, query string) (*querypb.QueryResult, error)

VReplicationExec executes a vreplication command.

func (*TabletManager) VReplicationWaitForPos

func (tm *TabletManager) VReplicationWaitForPos(ctx context.Context, id int, pos string) error

VReplicationWaitForPos waits for the specified position.

func (*TabletManager) WaitForPosition

func (tm *TabletManager) WaitForPosition(ctx context.Context, pos string) error

WaitForPosition returns the master position

Directories

Path Synopsis
Package events contains event structs used by the tabletmanager package.
Package events contains event structs used by the tabletmanager package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL