master

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRate      float64 = 10
	DefaultBurst             = 40
	ErrorNoEmitToken         = "fail to get emit opportunity for %s"
)

rate limit related constant value

Variables

View Source
var SampleConfigFile string

SampleConfigFile is sample config file of dm-master later we can read it from dm/master/dm-master.toml and assign it to SampleConfigFile while we build dm-master

Functions

func HandleStatus

func HandleStatus(mux *http.ServeMux)

HandleStatus handles functions for getting status by HTTP request

Types

type Agent

type Agent struct {
	ID int
}

Agent communicate with dm-workers

type AgentPool

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

AgentPool is a pool to control communication with dm-workers It provides rate limit control for agent acquire, including dispatch rate r and permits bursts of at most b tokens. caller shouldn't to hold agent to avoid deadlock

func NewAgentPool

func NewAgentPool(cfg *RateLimitConfig) *AgentPool

NewAgentPool returns a agent pool

func (*AgentPool) Apply

func (ap *AgentPool) Apply(ctx context.Context, id int) *Agent

Apply applies for a agent if ctx is canceled before we get an agent, returns nil

func (*AgentPool) Emit

func (ap *AgentPool) Emit(ctx context.Context, id int, fn emitFunc, errFn emitFunc, args ...interface{})

Emit applies for an agent to communicates with dm-worker

func (*AgentPool) Start

func (ap *AgentPool) Start(ctx context.Context)

Start starts AgentPool background dispatcher

type Config

type Config struct {
	*flag.FlagSet `json:"-"`

	LogLevel  string `toml:"log-level" json:"log-level"`
	LogFile   string `toml:"log-file" json:"log-file"`
	LogRotate string `toml:"log-rotate" json:"log-rotate"`

	RPCTimeoutStr string        `toml:"rpc-timeout" json:"rpc-timeout"`
	RPCTimeout    time.Duration `json:"-"`
	RPCRateLimit  float64       `toml:"rpc-rate-limit" json:"rpc-rate-limit"`
	RPCRateBurst  int           `toml:"rpc-rate-burst" json:"rpc-rate-burst"`

	MasterAddr string `toml:"master-addr" json:"master-addr"`

	Deploy    []*DeployMapper   `toml:"deploy" json:"-"`
	DeployMap map[string]string `json:"deploy"`

	ConfigFile string `json:"config-file"`
	// contains filtered or unexported fields
}

Config is the configuration for dm-master

func NewConfig

func NewConfig() *Config

NewConfig creates a config for dm-master

func (*Config) Parse

func (c *Config) Parse(arguments []string) error

Parse parses flag definitions from the argument list.

func (*Config) Reload

func (c *Config) Reload() error

Reload load config from local file

func (*Config) String

func (c *Config) String() string

func (*Config) UpdateConfigFile

func (c *Config) UpdateConfigFile(content string) error

UpdateConfigFile write config to local file if ConfigFile is nil, it will write to dm-master.toml

type DeployMapper

type DeployMapper struct {
	MySQL  string `toml:"mysql-instance" json:"mysql-instance"` //  deprecated, use source-id instead
	Source string `toml:"source-id" json:"source-id"`           // represents a MySQL/MariaDB instance or a replica group
	Worker string `toml:"dm-worker" json:"dm-worker"`
}

DeployMapper defines dm-worker's deploy mapper info: source id -> dm-worker ${host:ip}

func (*DeployMapper) Verify

func (d *DeployMapper) Verify() error

Verify verifies deploy configuration

type Lock

type Lock struct {
	sync.RWMutex
	ID    string   // lock's ID, constructed from task's name and SQL statement
	Task  string   // lock's corresponding task name
	Owner string   // lock's Owner, a dm-worker
	Stmts []string // SQL statement

	AutoRetry sync2.AtomicBool // whether re-try resolve at intervals
	Resolving sync2.AtomicBool // whether the lock is resolving
	// contains filtered or unexported fields
}

Lock used for process synchronization

func NewLock

func NewLock(id, task, owner string, stmts []string, workers []string) *Lock

NewLock creates a new Lock

func (*Lock) DDLs

func (l *Lock) DDLs() []string

DDLs returns the DDLs in syncing

func (*Lock) IsSync

func (l *Lock) IsSync() (bool, int)

IsSync returns whether the lock has synced

func (*Lock) Ready

func (l *Lock) Ready() map[string]bool

Ready returns the dm-workers and whether it's ready synced

func (*Lock) TrySync

func (l *Lock) TrySync(caller string, workers []string, ddls []string) (bool, int, error)

TrySync tries to sync the lock, does decrease on remain, reentrant new workers may join after DDL lock is in syncing so we need to merge these new workers

type LockKeeper

type LockKeeper struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LockKeeper used to keep and handle DDL lock

func NewLockKeeper

func NewLockKeeper() *LockKeeper

NewLockKeeper creates a new LockKeeper

func (*LockKeeper) FindLock

func (lk *LockKeeper) FindLock(lockID string) *Lock

FindLock finds a lock

func (*LockKeeper) Locks

func (lk *LockKeeper) Locks() map[string]*Lock

Locks returns a copy of all locks

func (*LockKeeper) RemoveLock

func (lk *LockKeeper) RemoveLock(lockID string) bool

RemoveLock removes a lock

func (*LockKeeper) TrySync

func (lk *LockKeeper) TrySync(task, schema, table, worker string, stmts []string, workers []string) (string, bool, int, error)

TrySync tries to sync the lock

type RateLimitConfig

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

RateLimitConfig holds rate limit config

type Server

type Server struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Server handles RPC requests for dm-master

func NewServer

func NewServer(cfg *Config) *Server

NewServer creates a new Server

func (*Server) BreakWorkerDDLLock

BreakWorkerDDLLock implements MasterServer.BreakWorkerDDLLock

func (*Server) CheckTask

func (s *Server) CheckTask(ctx context.Context, req *pb.CheckTaskRequest) (*pb.CheckTaskResponse, error)

CheckTask checks legality of task configuration

func (*Server) Close

func (s *Server) Close()

Close close the RPC server, this function can be called multiple times

func (*Server) HandleHTTPApis

func (s *Server) HandleHTTPApis(ctx context.Context, mux *http.ServeMux) error

HandleHTTPApis handles http apis and translate to grpc request

func (*Server) HandleSQLs

func (s *Server) HandleSQLs(ctx context.Context, req *pb.HandleSQLsRequest) (*pb.HandleSQLsResponse, error)

HandleSQLs implements MasterServer.HandleSQLs

func (*Server) MigrateWorkerRelay

func (s *Server) MigrateWorkerRelay(ctx context.Context, req *pb.MigrateWorkerRelayRequest) (*pb.CommonWorkerResponse, error)

MigrateWorkerRelay migrates dm-woker relay unit

func (*Server) OperateTask

func (s *Server) OperateTask(ctx context.Context, req *pb.OperateTaskRequest) (*pb.OperateTaskResponse, error)

OperateTask implements MasterServer.OperateTask

func (*Server) OperateWorkerRelayTask

func (s *Server) OperateWorkerRelayTask(ctx context.Context, req *pb.OperateWorkerRelayRequest) (*pb.OperateWorkerRelayResponse, error)

OperateWorkerRelayTask implements MasterServer.OperateWorkerRelayTask

func (*Server) PurgeWorkerRelay

func (s *Server) PurgeWorkerRelay(ctx context.Context, req *pb.PurgeWorkerRelayRequest) (*pb.PurgeWorkerRelayResponse, error)

PurgeWorkerRelay implements MasterServer.PurgeWorkerRelay

func (*Server) QueryError

QueryError implements MasterServer.QueryError

func (*Server) QueryStatus

QueryStatus implements MasterServer.QueryStatus

func (*Server) RefreshWorkerTasks

RefreshWorkerTasks implements MasterServer.RefreshWorkerTasks

func (*Server) ShowDDLLocks

func (s *Server) ShowDDLLocks(ctx context.Context, req *pb.ShowDDLLocksRequest) (*pb.ShowDDLLocksResponse, error)

ShowDDLLocks implements MasterServer.ShowDDLLocks

func (*Server) Start

func (s *Server) Start() error

Start starts to serving

func (*Server) StartTask

func (s *Server) StartTask(ctx context.Context, req *pb.StartTaskRequest) (*pb.StartTaskResponse, error)

StartTask implements MasterServer.StartTask

func (*Server) SwitchWorkerRelayMaster

SwitchWorkerRelayMaster implements MasterServer.SwitchWorkerRelayMaster

func (*Server) UnlockDDLLock

func (s *Server) UnlockDDLLock(ctx context.Context, req *pb.UnlockDDLLockRequest) (*pb.UnlockDDLLockResponse, error)

UnlockDDLLock implements MasterServer.UnlockDDLLock

func (*Server) UpdateMasterConfig

UpdateMasterConfig implements MasterServer.UpdateConfig

func (*Server) UpdateTask

func (s *Server) UpdateTask(ctx context.Context, req *pb.UpdateTaskRequest) (*pb.UpdateTaskResponse, error)

UpdateTask implements MasterServer.UpdateTask

func (*Server) UpdateWorkerRelayConfig

func (s *Server) UpdateWorkerRelayConfig(ctx context.Context, req *pb.UpdateWorkerRelayConfigRequest) (*pb.CommonWorkerResponse, error)

UpdateWorkerRelayConfig updates config for relay and (dm-worker)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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