mylet

package
v0.0.0-...-b49765e Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Hour8 = 8 * time.Hour
	Day   = 24 * time.Hour

	BackupFilename = "mylet_backup"
	DatetimeLayout = "20060102.150405"
	CompressExt    = ".tar.gz"
)
View Source
const (
	Timeout1m = time.Minute
	Timeout5s = 5 * time.Second
)
View Source
const (
	RW = true
	RO = false
)
View Source
const MaxStartup = 720 // 1h
View Source
const MyCnfTmpl = `` /* 1821-byte string literal not displayed */
View Source
const RunSQL = `` /* 484-byte string literal not displayed */

Variables

View Source
var (
	HttpAddr   = ":80"
	HttpsAddr  = os.Getenv("HTTPS_ADDR")
	HttpsCert  = os.Getenv("HTTPS_CERT")
	HttpsKey   = os.Getenv("HTTPS_KEY")
	Http2Https = false
)
View Source
var RandId = time.Now().UnixNano() // 启动时间、冲突检测

Functions

func AccessDenied

func AccessDenied(err error) bool

func CheckMyCnf

func CheckMyCnf()

TODO

func CheckMysqldCmdVersion

func CheckMysqldCmdVersion()

func CrossCheck

func CrossCheck(ctx context.Context, mysql *v1.Mysql) map[int]error

func DailCheck

func DailCheck(ctx context.Context, addr string) error

TODO more check

func GetIncrementals

func GetIncrementals(dir string) (a []int, err error)

func GroupToken

func GroupToken(mysql *v1.Mysql) string

func IndexNotDigit

func IndexNotDigit(s string) int

func IsEmpty

func IsEmpty(name string) (bool, error)

func LoadTimeZone

func LoadTimeZone() (string, error)

func Open

func Open(dsn string, params ...string) (*sql.DB, error)

func PushToken

func PushToken(ctx *tiny.Context)

func ReadBackupInfo

func ReadBackupInfo(dir string) (t time.Time, d time.Duration, err error)

func Serve

func Serve()

func SoloToken

func SoloToken(mysql *v1.Mysql, name string) string

func WriteBackupInfo

func WriteBackupInfo(dir string, t time.Time) error

Types

type Mylet

type Mylet struct {
	sync.Mutex

	Mysql *v1.Mysql
	v1.MysqlSolo

	ReadinessProbe bool
	LivenessProbe  bool
	StartupProbe   bool

	Backing    string
	Running    bool
	ExitChan   chan struct{}
	SwitchChan chan int
}

func Fetch

func Fetch(myctlAddr, soloName, groupToken string) (*Mylet, error)

func (*Mylet) AdjustBackup

func (mylet *Mylet) AdjustBackup(id int) error

func (*Mylet) BackupDir

func (mylet *Mylet) BackupDir() string

func (*Mylet) BackupFile

func (mylet *Mylet) BackupFile(src string) error

func (*Mylet) ChangeLocalPassword

func (mylet *Mylet) ChangeLocalPassword() error

func (*Mylet) ChangePrimary

func (mylet *Mylet) ChangePrimary(newId int) (err error)

func (*Mylet) CheckPosition

func (mylet *Mylet) CheckPosition() error

TODO

func (*Mylet) CheckVersion

func (mylet *Mylet) CheckVersion(v string) error

func (*Mylet) CompressBackup

func (mylet *Mylet) CompressBackup(dir string) (string, error)

func (*Mylet) CompressLastBackup

func (mylet *Mylet) CompressLastBackup() (string, error)

func (*Mylet) Configure

func (mylet *Mylet) Configure() error

func (*Mylet) CreateBackupUser

func (mylet *Mylet) CreateBackupUser() error

TODO

func (*Mylet) DataDir

func (mylet *Mylet) DataDir() string

func (*Mylet) ExecFile

func (mylet *Mylet) ExecFile(username, password, dbname, f string) error

func (*Mylet) ExporterUser

func (mylet *Mylet) ExporterUser() error

func (*Mylet) FetchAndPrepare

func (mylet *Mylet) FetchAndPrepare() error

func (*Mylet) FixPasswordId

func (mylet *Mylet) FixPasswordId(id int) error

func (*Mylet) FullBackup

func (mylet *Mylet) FullBackup() (time.Time, error)

func (*Mylet) GetBackupDir

func (mylet *Mylet) GetBackupDir(t time.Time) string

name.date.time/

base
inc1
inc...

func (*Mylet) GetBackups

func (mylet *Mylet) GetBackups() (a []time.Time, err error)

TODO time corrupt

func (*Mylet) GetCompresses

func (mylet *Mylet) GetCompresses() (a []time.Time, err error)

func (*Mylet) GetMysqldVersion

func (mylet *Mylet) GetMysqldVersion(id int) (v string, err error)

func (*Mylet) IncrementalBackup

func (mylet *Mylet) IncrementalBackup(t time.Time) (int, error)

func (*Mylet) InitDB

func (mylet *Mylet) InitDB() error

func (*Mylet) Initialize

func (mylet *Mylet) Initialize() error

func (*Mylet) IsPrimary

func (mylet *Mylet) IsPrimary() bool

func (*Mylet) IsReplica

func (mylet *Mylet) IsReplica() bool

func (*Mylet) LockBackup

func (mylet *Mylet) LockBackup(s string) string

func (*Mylet) MyCnf

func (mylet *Mylet) MyCnf() string

func (*Mylet) Mysqld

func (mylet *Mylet) Mysqld(ctx context.Context, args ...string) *exec.Cmd

func (*Mylet) PrepareBackup

func (mylet *Mylet) PrepareBackup(id int, dir string) error

func (*Mylet) PrepareLastBackup

func (mylet *Mylet) PrepareLastBackup() error

func (*Mylet) ReadGtid

func (mylet *Mylet) ReadGtid() (gtid string, err error)

func (*Mylet) Read_binlog_pos

func (mylet *Mylet) Read_binlog_pos() (gtid string, err error)

TODO: multiline

func (*Mylet) Reload

func (let *Mylet) Reload(ss SizeSpec) error

func (*Mylet) RenameRoot

func (mylet *Mylet) RenameRoot() error

func (*Mylet) RestoreBackup

func (mylet *Mylet) RestoreBackup(id int, dir string, move bool) error

func (*Mylet) Run

func (mylet *Mylet) Run()

func (*Mylet) SelfCheck

func (mylet *Mylet) SelfCheck() error

func (*Mylet) SendReport

func (let *Mylet) SendReport(ctx context.Context, r *MysqlReport) error

func (*Mylet) SetupPrimary

func (mylet *Mylet) SetupPrimary() error

func (*Mylet) SetupReplica

func (mylet *Mylet) SetupReplica() error

func (*Mylet) Socket

func (mylet *Mylet) Socket() string

func (*Mylet) Start

func (mylet *Mylet) Start() error

func (*Mylet) StopPrimary

func (mylet *Mylet) StopPrimary() error

func (*Mylet) StopReplica

func (mylet *Mylet) StopReplica() error

func (*Mylet) SwitchPrimary

func (mylet *Mylet) SwitchPrimary(rw bool) error

func (*Mylet) UnlockBackup

func (mylet *Mylet) UnlockBackup()

func (*Mylet) WaitRelay

func (mylet *Mylet) WaitRelay() error

TODO

type MysqlReport

type MysqlReport struct {
	Name string
	SizeSpec
	States []json.RawMessage
	Hang   int
}

type MysqlState

type MysqlState struct {
	StateKey

	GreenTime     time.Time
	GreenDuration time.Duration

	YellowTime     time.Time
	YellowDuration time.Duration

	RedTime     time.Time
	RedDuration time.Duration

	LastError  string //TODO max length
	ErrorCount int
}

type Querier

type Querier interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
}

type ReportResult

type ReportResult struct {
	ReceiveTime time.Time
	SizeSpec
}

type SizeSpec

type SizeSpec struct {
	PrimaryMode string
	Primaries   int
	Replicas    int
	PrimaryId   int
	AutoSwitch  bool
}

func NewSizeSpec

func NewSizeSpec(mysql *v1.Mysql) SizeSpec

type StateKey

type StateKey struct {
	FromId int
	ToId   int
}

type Token

type Token struct {
	Name       string
	GroupName  string
	Id         int
	Myctl      bool
	RandId     int
	GroupToken string
}

func ParseToken

func ParseToken(s string) (t Token, err error)

func PullToken

func PullToken(ctx *tiny.Context) *Token

Jump to

Keyboard shortcuts

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