tabletmanager

package
v0.0.0-...-d271c08 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2014 License: BSD-3-Clause Imports: 48 Imported by: 0

Documentation

Overview

Package agent exports the ActionAgent 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 agent is responsible for maintaining the tablet record in the topology server. Only 'ScrapTablet -force' and 'DeleteTablet' should be run by other processes, everything else should ask the tablet server to make the change.

Most RPC calls lock the actionMutex, 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 actionMutex, and which run changeCallback.

Index

Constants

View Source
const (
	BPM_STATE_RUNNING int64 = iota
	BPM_STATE_STOPPED
)

Variables

View Source
var RegisterQueryServices []RegisterQueryService

Functions

func HttpHandleSnapshots

func HttpHandleSnapshots(mycnf *mysqlctl.Mycnf, uid uint32)

HttpHandleSnapshots handles the serving of files from the local tablet

func RegisterBinlogPlayerMap

func RegisterBinlogPlayerMap(blm *BinlogPlayerMap)

RegisterBinlogPlayerMap registers the varz for the players

Types

type ActionAgent

type ActionAgent struct {
	// The following fields are set during creation
	TopoServer      topo.Server
	TabletAlias     topo.TabletAlias
	Mysqld          *mysqlctl.Mysqld
	MysqlDaemon     mysqlctl.MysqlDaemon
	DBConfigs       *dbconfigs.DBConfigs
	SchemaOverrides []tabletserver.SchemaOverride
	BinlogPlayerMap *BinlogPlayerMap
	LockTimeout     time.Duration

	// This is the History of the health checks, public so status
	// pages can display it
	History *history.History
	// contains filtered or unexported fields
}

ActionAgent is the main class for the agent.

func NewActionAgent

func NewActionAgent(
	tabletAlias topo.TabletAlias,
	dbcfgs *dbconfigs.DBConfigs,
	mycnf *mysqlctl.Mycnf,
	port, securePort int,
	overridesFile string,
	lockTimeout time.Duration,
) (agent *ActionAgent, err error)

NewActionAgent creates a new ActionAgent and registers all the associated services

func NewTestActionAgent

func NewTestActionAgent(ts topo.Server, tabletAlias topo.TabletAlias, port int, mysqlDaemon mysqlctl.MysqlDaemon) (agent *ActionAgent)

NewTestActionAgent creates an agent for test purposes. Only a subset of features are supported now, but we'll add more over time.

func (*ActionAgent) ApplySchema

func (agent *ActionAgent) ApplySchema(change *myproto.SchemaChange) (*myproto.SchemaChangeResult, error)

ApplySchema will apply a schema change Should be called under RpcWrapLockAction.

func (*ActionAgent) BlacklistedTables

func (agent *ActionAgent) BlacklistedTables() []string

func (*ActionAgent) BreakSlaves

func (agent *ActionAgent) BreakSlaves() error

BreakSlaves will tinker with the replication stream in a way that will stop all the slaves. Should be called under RpcWrapLockAction.

func (*ActionAgent) ChangeType

func (agent *ActionAgent) ChangeType(tabletType topo.TabletType) error

ChangeType changes the tablet type Should be called under RpcWrapLockAction.

func (*ActionAgent) DemoteMaster

func (agent *ActionAgent) DemoteMaster() error

DemoteMaster demotes the current master, and marks it read-only in the topo. Should be called under RpcWrapLockAction.

func (*ActionAgent) ExecuteFetch

func (agent *ActionAgent) ExecuteFetch(query string, maxrows int, wantFields, disableBinlogs bool) (*proto.QueryResult, error)

ExecuteFetch will execute the given query, possibly disabling binlogs. Should be called under RpcWrap.

func (*ActionAgent) ExecuteHook

func (agent *ActionAgent) ExecuteHook(hk *hook.Hook) *hook.HookResult

ExecuteHook executes the provided hook locally, and returns the result. Should be called under RpcWrapLockAction.

func (*ActionAgent) GetPermissions

func (agent *ActionAgent) GetPermissions() (*myproto.Permissions, error)

GetPermissions returns the db permissions. Should be called under RpcWrap.

func (*ActionAgent) GetSchema

func (agent *ActionAgent) GetSchema(tables, excludeTables []string, includeViews bool) (*myproto.SchemaDefinition, error)

GetSchema returns the schema. Should be called under RpcWrap.

func (*ActionAgent) GetSlaves

func (agent *ActionAgent) GetSlaves() ([]string, error)

GetSlaves returns the address of all the slaves Should be called under RpcWrap.

func (*ActionAgent) IsRunningHealthCheck

func (agent *ActionAgent) IsRunningHealthCheck() bool

func (*ActionAgent) MasterPosition

func (agent *ActionAgent) MasterPosition() (myproto.ReplicationPosition, error)

MasterPosition returns the master position Should be called under RpcWrap.

func (*ActionAgent) MultiRestore

func (agent *ActionAgent) MultiRestore(args *actionnode.MultiRestoreArgs, logger logutil.Logger) error

MultiRestore performs the multi-part restore. Should be called under RpcWrapLockAction.

func (*ActionAgent) MultiSnapshot

func (agent *ActionAgent) MultiSnapshot(args *actionnode.MultiSnapshotArgs, logger logutil.Logger) (*actionnode.MultiSnapshotReply, error)

MultiSnapshot takes a multi-part snapshot Should be called under RpcWrapLockAction.

func (*ActionAgent) Ping

func (agent *ActionAgent) Ping(args string) string

Ping makes sure RPCs work, and refreshes the tablet record. Should be called under RpcWrap.

func (*ActionAgent) PreflightSchema

func (agent *ActionAgent) PreflightSchema(change string) (*myproto.SchemaChangeResult, error)

PreflightSchema will try out the schema change Should be called under RpcWrapLockAction.

func (*ActionAgent) PromoteSlave

func (agent *ActionAgent) PromoteSlave() (*actionnode.RestartSlaveData, error)

PromoteSlave transforms the current tablet from a slave to a master. It returns the data needed for other tablets to become a slave. Should be called under RpcWrapLockAction.

func (*ActionAgent) RefreshState

func (agent *ActionAgent) RefreshState()

RefreshState reload the tablet record from the topo server. Should be called under RpcWrapLockAction, so it actually works.

func (*ActionAgent) ReloadSchema

func (agent *ActionAgent) ReloadSchema()

ReloadSchema will reload the schema Should be called under RpcWrapLockAction.

func (*ActionAgent) ReparentPosition

func (agent *ActionAgent) ReparentPosition(rp *myproto.ReplicationPosition) (*actionnode.RestartSlaveData, error)

ReparentPosition returns the RestartSlaveData for the provided ReplicationPosition. Should be called under RpcWrap.

func (*ActionAgent) ReserveForRestore

func (agent *ActionAgent) ReserveForRestore(args *actionnode.ReserveForRestoreArgs) error

ReserveForRestore reserves the current tablet for an upcoming restore operation. Should be called under RpcWrapLockAction.

func (*ActionAgent) RestartSlave

func (agent *ActionAgent) RestartSlave(rsd *actionnode.RestartSlaveData) error

RestartSlave tells the tablet it has a new master Should be called under RpcWrapLockAction.

func (*ActionAgent) Restore

func (agent *ActionAgent) Restore(args *actionnode.RestoreArgs, logger logutil.Logger) error

Operate on restore tablet. Check that the SnapshotManifest is valid and the master has not changed. Shutdown mysqld. Load the snapshot from source tablet. Restart mysqld and replication. Put tablet into the replication graph as a spare. Should be called under RpcWrapLockAction.

func (*ActionAgent) RpcWrap

func (agent *ActionAgent) RpcWrap(ctx context.Context, name string, args, reply interface{}, f func() error) error

func (*ActionAgent) RpcWrapLock

func (agent *ActionAgent) RpcWrapLock(ctx context.Context, name string, args, reply interface{}, verbose bool, f func() error) error

func (*ActionAgent) RpcWrapLockAction

func (agent *ActionAgent) RpcWrapLockAction(ctx context.Context, name string, args, reply interface{}, verbose bool, f func() error) error

func (*ActionAgent) RunBlpUntil

func (agent *ActionAgent) RunBlpUntil(bpl *blproto.BlpPositionList, waitTime time.Duration) (*myproto.ReplicationPosition, error)

RunBlpUntil runs the binlog player server until the position is reached, and returns the current mysql master replication position.

func (*ActionAgent) Scrap

func (agent *ActionAgent) Scrap() error

Scrap scraps the live running tablet Should be called under RpcWrapLockAction.

func (*ActionAgent) SetReadOnly

func (agent *ActionAgent) SetReadOnly(rdonly bool) error

SetReadOnly makes the mysql instance read-only or read-write Should be called under RpcWrapLockAction.

func (*ActionAgent) SlaveStatus

func (agent *ActionAgent) SlaveStatus() (*myproto.ReplicationStatus, error)

SlaveStatus returns the replication status Should be called under RpcWrap.

func (*ActionAgent) SlaveWasPromoted

func (agent *ActionAgent) SlaveWasPromoted() error

SlaveWasPromoted promotes a slave to master, no questions asked. Should be called under RpcWrapLockAction.

func (*ActionAgent) SlaveWasRestarted

func (agent *ActionAgent) SlaveWasRestarted(swrd *actionnode.SlaveWasRestartedArgs) error

SlaveWasRestarted updates the parent record for a tablet. Should be called under RpcWrapLockAction.

func (*ActionAgent) Sleep

func (agent *ActionAgent) Sleep(duration time.Duration)

Sleep sleeps for the duration Should be called under RpcWrapLockAction.

func (*ActionAgent) Snapshot

func (agent *ActionAgent) Snapshot(args *actionnode.SnapshotArgs, logger logutil.Logger) (*actionnode.SnapshotReply, error)

Snapshot takes a db snapshot Should be called under RpcWrapLockAction.

func (*ActionAgent) SnapshotSourceEnd

func (agent *ActionAgent) SnapshotSourceEnd(args *actionnode.SnapshotSourceEndArgs) error

SnapshotSourceEnd restores the state of the server after a Snapshot(server_mode =true) Should be called under RpcWrapLockAction.

func (*ActionAgent) Start

func (agent *ActionAgent) Start(mysqlPort, vtPort, vtsPort int) error

bindAddr: the address for the query service advertised by this agent

func (*ActionAgent) StartBlp

func (agent *ActionAgent) StartBlp() error

StartBlp starts the binlog players Should be called under RpcWrapLockAction.

func (*ActionAgent) StartSlave

func (agent *ActionAgent) StartSlave() error

StartSlave will start the replication Should be called under RpcWrapLock.

func (*ActionAgent) Stop

func (agent *ActionAgent) Stop()

Stop shutdowns this agent.

func (*ActionAgent) StopBlp

func (agent *ActionAgent) StopBlp() (*blproto.BlpPositionList, error)

StopBlp stops the binlog players, and return their positions. Should be called under RpcWrapLockAction.

func (*ActionAgent) StopSlave

func (agent *ActionAgent) StopSlave() error

StopSlave will stop the replication Should be called under RpcWrapLock.

func (*ActionAgent) StopSlaveMinimum

func (agent *ActionAgent) StopSlaveMinimum(position myproto.ReplicationPosition, waitTime time.Duration) (*myproto.ReplicationStatus, error)

StopSlaveMinimum will stop the slave after it reaches at least the provided position.

func (*ActionAgent) Tablet

func (agent *ActionAgent) Tablet() *topo.TabletInfo

func (*ActionAgent) TabletExternallyReparented

func (agent *ActionAgent) TabletExternallyReparented(actionTimeout time.Duration) error

TabletExternallyReparented updates all topo records so the current tablet is the new master for this shard. Should be called under RpcWrapLock.

func (*ActionAgent) WaitBlpPosition

func (agent *ActionAgent) WaitBlpPosition(blpPosition *blproto.BlpPosition, waitTime time.Duration) error

WaitBlpPosition waits until a specific filtered replication position is reached. Should be called under RpcWrapLock.

func (*ActionAgent) WaitSlavePosition

func (agent *ActionAgent) WaitSlavePosition(position myproto.ReplicationPosition, waitTimeout time.Duration) (*myproto.ReplicationStatus, error)

WaitSlavePosition waits until we reach the provided position, and returns the current position Should be called under RpcWrapLock.

type BinlogPlayerController

type BinlogPlayerController struct {
	// contains filtered or unexported fields
}

BinlogPlayerController controls one player

func (*BinlogPlayerController) BlpPosition

func (bpc *BinlogPlayerController) BlpPosition(vtClient *binlogplayer.DBClient) (*blproto.BlpPosition, string, error)

BlpPosition returns the current position for a controller, as read from the database.

func (*BinlogPlayerController) Iteration

func (bpc *BinlogPlayerController) Iteration() (err error)

Iteration is a single iteration for the player: get the current status, try to play, and plays until interrupted, or until an error occurs.

func (*BinlogPlayerController) Loop

func (bpc *BinlogPlayerController) Loop()

Loop runs the main player loop: try to play, and in case of error, sleep for 5 seconds and try again.

func (*BinlogPlayerController) Start

func (bpc *BinlogPlayerController) Start()

Start will start the player in the background and run forever

func (*BinlogPlayerController) StartUntil

func (bpc *BinlogPlayerController) StartUntil(stopPos myproto.ReplicationPosition) error

StartUntil will start the Player until we reach the given position.

func (*BinlogPlayerController) Stop

func (bpc *BinlogPlayerController) Stop()

Stop will ask the controller to stop playing, and wait until it is stopped.

func (*BinlogPlayerController) String

func (bpc *BinlogPlayerController) String() string

func (*BinlogPlayerController) WaitForStop

func (bpc *BinlogPlayerController) WaitForStop(waitTimeout time.Duration) error

WaitForStop will wait until the player is stopped. Use this after StartUntil.

type BinlogPlayerControllerStatus

type BinlogPlayerControllerStatus struct {
	// configuration values
	Index        uint32
	SourceShard  topo.SourceShard
	StopPosition myproto.ReplicationPosition

	// stats and current values
	LastPosition        myproto.ReplicationPosition
	SecondsBehindMaster int64
	Counts              map[string]int64
	Rates               map[string][]float64
	State               string
	SourceTablet        topo.TabletAlias
	LastError           string
}

BinlogPlayerControllerStatus is the status of an individual controller

type BinlogPlayerControllerStatusList

type BinlogPlayerControllerStatusList []*BinlogPlayerControllerStatus

BinlogPlayerControllerStatusList is the list of statuses

func (BinlogPlayerControllerStatusList) Len

Len is part of sort.Interface

func (BinlogPlayerControllerStatusList) Less

func (bpcsl BinlogPlayerControllerStatusList) Less(i, j int) bool

Less is part of sort.Interface

func (BinlogPlayerControllerStatusList) Swap

func (bpcsl BinlogPlayerControllerStatusList) Swap(i, j int)

Swap is part of sort.Interface

type BinlogPlayerMap

type BinlogPlayerMap struct {
	// contains filtered or unexported fields
}

BinlogPlayerMap controls all the players. It can be stopped and restarted.

func NewBinlogPlayerMap

func NewBinlogPlayerMap(ts topo.Server, dbConfig *mysql.ConnectionParams, mysqld *mysqlctl.Mysqld) *BinlogPlayerMap

NewBinlogPlayerMap creates a new map of players

func (*BinlogPlayerMap) BlpPositionList

func (blm *BinlogPlayerMap) BlpPositionList() (*blproto.BlpPositionList, error)

BlpPositionList returns the current position of all the players

func (*BinlogPlayerMap) RefreshMap

func (blm *BinlogPlayerMap) RefreshMap(tablet *topo.Tablet, keyspaceInfo *topo.KeyspaceInfo, shardInfo *topo.ShardInfo)

RefreshMap reads the right data from topo.Server and makes sure we're playing the right logs.

func (*BinlogPlayerMap) RunUntil

func (blm *BinlogPlayerMap) RunUntil(blpPositionList *blproto.BlpPositionList, waitTimeout time.Duration) error

RunUntil will run all the players until they reach the given position. Holds the map lock during that exercise, shouldn't take long at all.

func (*BinlogPlayerMap) Start

func (blm *BinlogPlayerMap) Start()

Start restarts the current players

func (*BinlogPlayerMap) Status

func (blm *BinlogPlayerMap) Status() *BinlogPlayerMapStatus

Status returns the BinlogPlayerMapStatus for the BinlogPlayerMap

func (*BinlogPlayerMap) Stop

func (blm *BinlogPlayerMap) Stop()

Stop stops the current players, but does not remove them from the map. Call 'Start' to restart the playback.

func (*BinlogPlayerMap) StopAllPlayersAndReset

func (blm *BinlogPlayerMap) StopAllPlayersAndReset()

StopAllPlayersAndReset stops all the binlog players, and reset the map of players.

type BinlogPlayerMapStatus

type BinlogPlayerMapStatus struct {
	State       string
	Controllers BinlogPlayerControllerStatusList
}

BinlogPlayerMapStatus is the complete player status

type HealthRecord

type HealthRecord struct {
	Error  error
	Result map[string]string
	Time   time.Time
}

HealthRecord records one run of the health checker

func (*HealthRecord) Class

func (r *HealthRecord) Class() string

This returns a readable one word version of the health

func (*HealthRecord) IsDuplicate

func (r *HealthRecord) IsDuplicate(other interface{}) bool

IsDuplicate implements history.Deduplicable

type RegisterQueryService

type RegisterQueryService func(*ActionAgent)

type RpcAgent

type RpcAgent interface {
	Ping(args string) string

	GetSchema(tables, excludeTables []string, includeViews bool) (*myproto.SchemaDefinition, error)

	GetPermissions() (*myproto.Permissions, error)

	SetReadOnly(rdonly bool) error

	ChangeType(topo.TabletType) error

	Scrap() error

	Sleep(duration time.Duration)

	ExecuteHook(hk *hook.Hook) *hook.HookResult

	RefreshState()

	ReloadSchema()

	PreflightSchema(change string) (*myproto.SchemaChangeResult, error)

	ApplySchema(change *myproto.SchemaChange) (*myproto.SchemaChangeResult, error)

	ExecuteFetch(query string, maxrows int, wantFields, disableBinlogs bool) (*proto.QueryResult, error)

	SlaveStatus() (*myproto.ReplicationStatus, error)

	WaitSlavePosition(position myproto.ReplicationPosition, waitTimeout time.Duration) (*myproto.ReplicationStatus, error)

	MasterPosition() (myproto.ReplicationPosition, error)

	ReparentPosition(rp *myproto.ReplicationPosition) (*actionnode.RestartSlaveData, error)

	StopSlave() error

	StopSlaveMinimum(position myproto.ReplicationPosition, waitTime time.Duration) (*myproto.ReplicationStatus, error)

	StartSlave() error

	TabletExternallyReparented(actionTimeout time.Duration) error

	GetSlaves() ([]string, error)

	WaitBlpPosition(blpPosition *blproto.BlpPosition, waitTime time.Duration) error

	StopBlp() (*blproto.BlpPositionList, error)

	StartBlp() error

	RunBlpUntil(bpl *blproto.BlpPositionList, waitTime time.Duration) (*myproto.ReplicationPosition, error)

	DemoteMaster() error

	PromoteSlave() (*actionnode.RestartSlaveData, error)

	SlaveWasPromoted() error

	RestartSlave(rsd *actionnode.RestartSlaveData) error

	SlaveWasRestarted(swrd *actionnode.SlaveWasRestartedArgs) error

	BreakSlaves() error

	Snapshot(args *actionnode.SnapshotArgs, logger logutil.Logger) (*actionnode.SnapshotReply, error)

	SnapshotSourceEnd(args *actionnode.SnapshotSourceEndArgs) error

	ReserveForRestore(args *actionnode.ReserveForRestoreArgs) error

	Restore(args *actionnode.RestoreArgs, logger logutil.Logger) error

	MultiSnapshot(args *actionnode.MultiSnapshotArgs, logger logutil.Logger) (*actionnode.MultiSnapshotReply, error)

	MultiRestore(args *actionnode.MultiRestoreArgs, logger logutil.Logger) error

	// RPC helpers
	RpcWrap(ctx context.Context, name string, args, reply interface{}, f func() error) error
	RpcWrapLock(ctx context.Context, name string, args, reply interface{}, verbose bool, f func() error) error
	RpcWrapLockAction(ctx context.Context, name string, args, reply interface{}, verbose bool, f func() error) error
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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