go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletmanager Index | Files | Directories

package tabletmanager

import "gopkg.in/src-d/go-vitess.v1/vt/vttablet/tabletmanager"

Package tabletmanager 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 'vtctl 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

Package Files

action_agent.go healthcheck.go heartbeat_reporter.go init_tablet.go initial_rebuild.go orchestrator.go replication_reporter.go restore.go rpc_actions.go rpc_agent.go rpc_backup.go rpc_external_reparent.go rpc_lock_tables.go rpc_query.go rpc_replication.go rpc_schema.go rpc_server.go state_change.go vreplication.go

Variables

var RegisterQueryServices []RegisterQueryService

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

func ConfigHTML Uses

func ConfigHTML() template.HTML

ConfigHTML returns a formatted summary of health checking config values.

func SetReparentFlags Uses

func SetReparentFlags(timeout time.Duration)

SetReparentFlags changes flag values. It should only be used in tests.

type ActionAgent Uses

type ActionAgent struct {
    // The following fields are set during creation
    QueryServiceControl tabletserver.Controller
    UpdateStream        binlog.UpdateStreamControl
    HealthReporter      health.Reporter
    TopoServer          *topo.Server
    TabletAlias         *topodatapb.TabletAlias
    Cnf                 *mysqlctl.Mycnf
    MysqlDaemon         mysqlctl.MysqlDaemon
    DBConfigs           *dbconfigs.DBConfigs
    VREngine            *vreplication.Engine

    // 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 Uses

func NewActionAgent(
    batchCtx context.Context,
    ts *topo.Server,
    mysqld mysqlctl.MysqlDaemon,
    queryServiceControl tabletserver.Controller,
    tabletAlias *topodatapb.TabletAlias,
    dbcfgs *dbconfigs.DBConfigs,
    mycnf *mysqlctl.Mycnf,
    port, gRPCPort int32,
) (agent *ActionAgent, err error)

NewActionAgent creates a new ActionAgent and registers all the associated services.

batchCtx is the context that the agent will use for any background tasks it spawns.

func NewComboActionAgent Uses

func NewComboActionAgent(batchCtx context.Context, ts *topo.Server, tabletAlias *topodatapb.TabletAlias, vtPort, grpcPort int32, queryServiceControl tabletserver.Controller, dbcfgs *dbconfigs.DBConfigs, mysqlDaemon mysqlctl.MysqlDaemon, keyspace, shard, dbname, tabletType string) *ActionAgent

NewComboActionAgent creates an agent tailored specifically to run within the vtcombo binary. It cannot be called concurrently, as it changes the flags.

func NewTestActionAgent Uses

func NewTestActionAgent(batchCtx context.Context, ts *topo.Server, tabletAlias *topodatapb.TabletAlias, vtPort, grpcPort int32, mysqlDaemon mysqlctl.MysqlDaemon, preStart func(*ActionAgent)) *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 Uses

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

ApplySchema will apply a schema change

func (*ActionAgent) Backup Uses

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

Backup takes a db backup and sends it to the BackupStorage

func (*ActionAgent) BlacklistedTables Uses

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

BlacklistedTables returns the list of currently blacklisted tables.

func (*ActionAgent) ChangeType Uses

func (agent *ActionAgent) ChangeType(ctx context.Context, tabletType topodatapb.TabletType) error

ChangeType changes the tablet type

func (*ActionAgent) Close Uses

func (agent *ActionAgent) 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 (*ActionAgent) DemoteMaster Uses

func (agent *ActionAgent) DemoteMaster(ctx context.Context) (string, error)

DemoteMaster marks the server read-only, wait until it is done with its current transactions, and returns its master position.

func (*ActionAgent) DisallowQueryService Uses

func (agent *ActionAgent) DisallowQueryService() string

DisallowQueryService returns the reason the query service should be disabled, if any.

func (*ActionAgent) EnableUpdateStream Uses

func (agent *ActionAgent) EnableUpdateStream() bool

EnableUpdateStream returns if we should enable update stream or not

func (*ActionAgent) ExecuteFetchAsAllPrivs Uses

func (agent *ActionAgent) 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 (*ActionAgent) ExecuteFetchAsApp Uses

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

ExecuteFetchAsApp will execute the given query.

func (*ActionAgent) ExecuteFetchAsDba Uses

func (agent *ActionAgent) 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 (*ActionAgent) ExecuteHook Uses

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

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

func (*ActionAgent) GetPermissions Uses

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

GetPermissions returns the db permissions.

func (*ActionAgent) GetSchema Uses

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

GetSchema returns the schema.

func (*ActionAgent) GetSlaves Uses

func (agent *ActionAgent) GetSlaves(ctx context.Context) ([]string, error)

GetSlaves returns the address of all the slaves

func (*ActionAgent) HandleRPCPanic Uses

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

HandleRPCPanic is part of the RPCAgent interface.

func (*ActionAgent) Healthy Uses

func (agent *ActionAgent) Healthy() (time.Duration, error)

Healthy reads the result of the latest healthcheck, protected by mutex. If that status is too old, it means healthcheck hasn't run for a while, and is probably stuck, this is not good, we're not healthy.

func (*ActionAgent) IgnoreHealthError Uses

func (agent *ActionAgent) IgnoreHealthError(ctx context.Context, pattern string) error

IgnoreHealthError sets the regexp for health check errors to ignore.

func (*ActionAgent) InitMaster Uses

func (agent *ActionAgent) InitMaster(ctx context.Context) (string, error)

InitMaster enables writes and returns the replication position.

func (*ActionAgent) InitSlave Uses

func (agent *ActionAgent) InitSlave(ctx context.Context, parent *topodatapb.TabletAlias, position string, timeCreatedNS int64) error

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

func (*ActionAgent) InitTablet Uses

func (agent *ActionAgent) InitTablet(port, gRPCPort int32) error

InitTablet initializes the tablet record if necessary.

func (*ActionAgent) LockTables Uses

func (agent *ActionAgent) LockTables(ctx context.Context) error

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

func (*ActionAgent) MasterPosition Uses

func (agent *ActionAgent) MasterPosition(ctx context.Context) (string, error)

MasterPosition returns the master position

func (*ActionAgent) Ping Uses

func (agent *ActionAgent) Ping(ctx context.Context, args string) string

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

func (*ActionAgent) PopulateReparentJournal Uses

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

PopulateReparentJournal adds an entry into the reparent_journal table.

func (*ActionAgent) PreflightSchema Uses

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

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

func (*ActionAgent) PromoteSlave Uses

func (agent *ActionAgent) PromoteSlave(ctx context.Context) (string, error)

PromoteSlave makes the current tablet the master

func (*ActionAgent) PromoteSlaveWhenCaughtUp Uses

func (agent *ActionAgent) PromoteSlaveWhenCaughtUp(ctx context.Context, position string) (string, error)

PromoteSlaveWhenCaughtUp waits for this slave to be caught up on replication up to the provided point, and then makes the slave the shard master.

func (*ActionAgent) RefreshState Uses

func (agent *ActionAgent) RefreshState(ctx context.Context) error

RefreshState reload the tablet record from the topo server.

func (*ActionAgent) ReloadSchema Uses

func (agent *ActionAgent) 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 (*ActionAgent) ResetReplication Uses

func (agent *ActionAgent) 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 (*ActionAgent) RestoreData Uses

func (agent *ActionAgent) RestoreData(ctx context.Context, logger logutil.Logger, 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 (*ActionAgent) RestoreFromBackup Uses

func (agent *ActionAgent) RestoreFromBackup(ctx context.Context, logger logutil.Logger) error

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

func (*ActionAgent) RunHealthCheck Uses

func (agent *ActionAgent) RunHealthCheck(ctx context.Context)

RunHealthCheck will manually run the health check on the tablet.

func (*ActionAgent) SetMaster Uses

func (agent *ActionAgent) SetMaster(ctx context.Context, parentAlias *topodatapb.TabletAlias, timeCreatedNS int64, forceStartSlave bool) error

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

func (*ActionAgent) SetReadOnly Uses

func (agent *ActionAgent) SetReadOnly(ctx context.Context, rdonly bool) error

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

func (*ActionAgent) SlaveStatus Uses

func (agent *ActionAgent) SlaveStatus(ctx context.Context) (*replicationdatapb.Status, error)

SlaveStatus returns the replication status

func (*ActionAgent) SlaveWasPromoted Uses

func (agent *ActionAgent) SlaveWasPromoted(ctx context.Context) error

SlaveWasPromoted promotes a slave to master, no questions asked.

func (*ActionAgent) SlaveWasRestarted Uses

func (agent *ActionAgent) SlaveWasRestarted(ctx context.Context, parent *topodatapb.TabletAlias) error

SlaveWasRestarted updates the parent record for a tablet.

func (*ActionAgent) Sleep Uses

func (agent *ActionAgent) Sleep(ctx context.Context, duration time.Duration)

Sleep sleeps for the duration

func (*ActionAgent) Start Uses

func (agent *ActionAgent) Start(ctx context.Context, mysqlHost string, mysqlPort, vtPort, gRPCPort int32, initUpdateStream bool) error

Start validates and updates the topology records for the tablet, and performs the initial state change callback to start tablet services. If initUpdateStream is set, update stream service will also be registered.

func (*ActionAgent) StartSlave Uses

func (agent *ActionAgent) StartSlave(ctx context.Context) error

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

func (*ActionAgent) StartSlaveUntilAfter Uses

func (agent *ActionAgent) StartSlaveUntilAfter(ctx context.Context, position string, waitTime time.Duration) error

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

func (*ActionAgent) Stop Uses

func (agent *ActionAgent) Stop()

Stop shuts down the agent. 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 agent immediately.

func (*ActionAgent) StopReplicationAndGetStatus Uses

func (agent *ActionAgent) StopReplicationAndGetStatus(ctx context.Context) (*replicationdatapb.Status, error)

StopReplicationAndGetStatus stops MySQL replication, and returns the current status.

func (*ActionAgent) StopSlave Uses

func (agent *ActionAgent) StopSlave(ctx context.Context) error

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

func (*ActionAgent) StopSlaveMinimum Uses

func (agent *ActionAgent) StopSlaveMinimum(ctx context.Context, position string, waitTime time.Duration) (string, error)

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

func (*ActionAgent) Tablet Uses

func (agent *ActionAgent) Tablet() *topodatapb.Tablet

Tablet reads the stored Tablet from the agent, protected by mutex.

func (*ActionAgent) TabletExternallyReparented Uses

func (agent *ActionAgent) TabletExternallyReparented(ctx context.Context, externalID string) error

TabletExternallyReparented updates all topo records so the current tablet is the new master for this shard.

func (*ActionAgent) UndoDemoteMaster Uses

func (agent *ActionAgent) 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 (*ActionAgent) UnlockTables Uses

func (agent *ActionAgent) UnlockTables(ctx context.Context) error

UnlockTables will unlock all tables (idempotent)

func (*ActionAgent) VReplicationExec Uses

func (agent *ActionAgent) VReplicationExec(ctx context.Context, query string) (*querypb.QueryResult, error)

VReplicationExec executes a vreplication command.

func (*ActionAgent) VReplicationWaitForPos Uses

func (agent *ActionAgent) VReplicationWaitForPos(ctx context.Context, id int, pos string) error

VReplicationWaitForPos waits for the specified position.

type HealthRecord Uses

type HealthRecord struct {
    Time             time.Time
    Error            error
    IgnoredError     error
    IgnoreErrorExpr  string
    ReplicationDelay time.Duration
}

HealthRecord records one run of the health checker.

func (*HealthRecord) Class Uses

func (r *HealthRecord) Class() string

Class returns a human-readable one word version of the health state.

func (*HealthRecord) Degraded Uses

func (r *HealthRecord) Degraded() bool

Degraded returns true if the replication delay is beyond degradedThreshold.

func (*HealthRecord) ErrorString Uses

func (r *HealthRecord) ErrorString() string

ErrorString returns Error as a string.

func (*HealthRecord) HTML Uses

func (r *HealthRecord) HTML() template.HTML

HTML returns an HTML version to be displayed on UIs.

func (*HealthRecord) IgnoredErrorString Uses

func (r *HealthRecord) IgnoredErrorString() string

IgnoredErrorString returns IgnoredError as a string.

func (*HealthRecord) IsDuplicate Uses

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

IsDuplicate implements history.Deduplicable

type RPCAgent Uses

type RPCAgent 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)

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

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

    StopSlave(ctx context.Context) error

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

    StartSlave(ctx context.Context) error

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

    TabletExternallyReparented(ctx context.Context, externalID string) error

    GetSlaves(ctx context.Context) ([]string, 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

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

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

    UndoDemoteMaster(ctx context.Context) error

    PromoteSlaveWhenCaughtUp(ctx context.Context, replicationPosition string) (string, error)

    SlaveWasPromoted(ctx context.Context) error

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

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

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

    PromoteSlave(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)
}

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

type RegisterQueryService Uses

type RegisterQueryService func(*ActionAgent)

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

type Reporter Uses

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

Reporter is a wrapper around a heartbeat Reader, to be used as an interface from the health check system.

func (*Reporter) HTMLName Uses

func (r *Reporter) HTMLName() template.HTML

HTMLName is part of the health.Reporter interface.

func (*Reporter) Report Uses

func (r *Reporter) Report(isSlaveType, shouldQueryServiceBeRunning bool) (time.Duration, error)

Report is part of the health.Reporter interface. It returns the last reported value written by the watchHeartbeat goroutine. If we're the master, it just returns 0.

Directories

PathSynopsis
eventsPackage events contains event structs used by the tabletmanager package.
vreplication

Package tabletmanager imports 61 packages (graph) and is imported by 6 packages. Updated 2019-06-13. Refresh now. Tools for package owners.