util

package
v0.0.0-...-a073ad2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMaster = errors.New("util/ops: Master Aggregator not found")
)

Set Custom error messages

Functions

func CatchSignals

func CatchSignals(c chan os.Signal, s os.Signal)

CatchSignals will setup Notify to relay specific OS signals to a specified channel and handle the signals that are on the channel

func ConnectToMemSQL

func ConnectToMemSQL(config Config) error

ConnectToMemSQL does just that

func ConstantRefresh

func ConstantRefresh(sleepTime time.Duration) func(int) time.Duration

func DBAttachLeaf

func DBAttachLeaf(host string, port int) error

DBAttachLeaf will attach a specified host (ATTACH LEAF 'host':port)

func DBDetachLeaf

func DBDetachLeaf(host string, port int) error

DBDetachLeaf will detach a specified host (DETACH LEAF 'host':port)

func DBGetUserDatabases

func DBGetUserDatabases() ([]string, error)

DBGetUserDatabases returns all user databases

func DBGetVariable

func DBGetVariable(varName string) (string, error)

DBGetVariable returns value of variable name specified

func DBRebalancePartitions

func DBRebalancePartitions(database string) error

DBRebalancePartitions will run rebalance on specified DB

func DBRestoreRedundancy

func DBRestoreRedundancy(database string) error

DBRestoreRedundancy will restore redundancy on specified DB

func DBRowCount

func DBRowCount(database, table string) (string, error)

DBRowCount returns a count for specified table

func DBSetVariable

func DBSetVariable(db string) error

DBSetVariable sets database variables

func DBSnapshotDatabase

func DBSnapshotDatabase(db string) error

DBSnapshotDatabase executes a snapshot of provided databse

func ExponentialBackoffRefresh

func ExponentialBackoffRefresh(tries int) time.Duration

func GetNodeIDs

func GetNodeIDs(nodeType string) ([]string, error)

GetNodeIDs returns a slice of MemSQL node IDs by type (e.g. MASTER)

func GetUserConfirmation

func GetUserConfirmation(message, instruction, confirmString string)

GetUserConfirmation waits for user to confirm

func LineWrapper

func LineWrapper(s string, maxLength int) string

LineWrapper returns a string with line breaks at the specified line length

func MasterSlaveCheck

func MasterSlaveCheck(partitions []*ClusterStatus) error

MasterSlaveCheck will check each partition has a Master and Slave masterSlaveCheck Requires a slice if partitions from Cluster Status util.ClusterStatus will return a slice of pointers to the struct

func OpsMemsqlGetVersion

func OpsMemsqlGetVersion(memsqlID string) (string, error)

OpsMemsqlGetVersion returns MemSQL Version for provided memsql_id

func OpsMemsqlUpdateConfig

func OpsMemsqlUpdateConfig(memsqlID, key, value string, option ...string) error

OpsMemsqlUpdateConfig updates memsql.cnf Accepts memsqlID, key, value, and a list of options We return output of the command and nill if not err

func OpsMemsqlUpgrade

func OpsMemsqlUpgrade(memsqlID string, arguments ...string) error

OpsMemsqlUpgrade upgrades a specified memsql node

func OpsNodeManagement

func OpsNodeManagement(command, memsqlID string, arguments ...string) error

OpsNodeManagement executes memsql-ops commands which take a single memsql_id as a positional argument. (start, stop ...)

func OpsVersionCheck

func OpsVersionCheck() ([]string, error)

OpsVersionCheck return Memsql Ops Version memsql-ops version --client-version-only

func OpsWaitMemsqlsOnlineConnected

func OpsWaitMemsqlsOnlineConnected(numNodes int) error

OpsWaitMemsqlsOnlineConnected checks and waits for the state of a specified number of nodes to be online and connected

func OrphanCheck

func OrphanCheck(partitions []*ClusterStatus) error

OrphanCheck will check for any orphan partitions orphanCheck requires a slice if partitions from Cluster Status util.ClusterStatus will return a slice of pointers to the struct

func SetupLogging

func SetupLogging(config Config) (func(), error)

func TestGetDB

func TestGetDB(t *testing.T) *sqlx.DB

TestGetDB exposes the private dbConn variable for testing. Should not be used in any of the actual code - all queries should be materialized as tested functions in this package instead.

Types

type AgentInfo

type AgentInfo struct {
	AgentID string `json:"agent_id"`
	Host    string `json:"host"`
	Port    int    `json:"port"`
	Role    string `json:"role"`
	State   string `json:"state"`
	Version string `json:"version"`
}

AgentInfo struct for memsql-ops agent-list

func OpsAgentList

func OpsAgentList() ([]AgentInfo, error)

OpsAgentList returns a slice of agent-list

type ClusterStatus

type ClusterStatus struct {
	Host     string  `db:"Host"`
	Port     int     `db:"Port"`
	Database string  `db:"Database"`
	Role     string  `db:"Role"`
	State    string  `db:"State"`
	Position []uint8 `db:"Position"`
	Details  string  `db:"Details"`
}

ClusterStatus - struct for data returned from query

func DBShowClusterStatus

func DBShowClusterStatus() ([]*ClusterStatus, error)

DBShowClusterStatus returns output of show cluster status Return a slice of pointers to the ClusterStatus struct

type Config

type Config struct {
	MasterHost       string
	MasterPort       int
	MasterUser       string
	MasterPass       string
	LogPath          string
	VersionHash      string
	SkipVersionCheck bool
	OutputWidth      int
}

Config struct for commandline flags

func ParseFlags

func ParseFlags() Config

ParseFlags parses command line args

type Leaf

type Leaf struct {
	Host     string  `db:"Host"`
	Port     int     `db:"Port"`
	PairHost string  `db:"Pair_Host"`
	PairPort int     `db:"Pair_Port"`
	AG       int     `db:"Availability_Group"`
	OpenConn int     `db:"Opened_Connections"`
	AvgRT    []uint8 `db:"Average_Roundtrip_Latency_ms"`
	State    string  `db:"State"`
}

Leaf - struct for leaf data return from query

func DBShowLeaves

func DBShowLeaves() ([]*Leaf, error)

DBShowLeaves returns the output of show leaves Return a slice of pointers to the Leaf struct

type MemsqlInfo

type MemsqlInfo struct {
	MemsqlID string `json:"memsql_id"`

	AgentID       string `json:"agent_id"`
	MemsqlVersion string `json:"memsql_version"`
	Role          string `json:"role"`
	Host          string `json:"host"`
	Port          int    `json:"port"`
	Group         int    `json:"availability_group"`
	ClusterState  string `json:"cluster_state"`
	RunState      string `json:"run_state"`
	State         string `json:"state"`
}

MemsqlInfo struct for memsql-ops memsql-list

func OpsMemsqlList

func OpsMemsqlList(args ...string) ([]MemsqlInfo, error)

OpsMemsqlList return a slice of memsql-list By default we expect json. Do not pass in `-q`

type RestoreRedundancy

type RestoreRedundancy struct {
	Action     string `db:"Action"`
	Ordinal    int    `db:"Ordinal"`
	TargetHost string `db:"Target_Host"`
	TargetPort int    `db:"Target_Port"`
	Phase      int    `db:"Phase"`
}

RestoreRedundancy data return from Exlpain Restore Redundancy

func DBExplainRestoreRedundancy

func DBExplainRestoreRedundancy(database string) ([]*RestoreRedundancy, error)

DBExplainRestoreRedundancy will run explain restore redundancy on specified DB

type StateChange

type StateChange struct {
	Target      interface{}
	Timeout     time.Duration
	NextRefresh StateNextRefreshFunc
	Refresh     StateRefreshFunc
}

func (StateChange) WaitForState

func (conf StateChange) WaitForState() error

type StateNextRefreshFunc

type StateNextRefreshFunc func(tries int) time.Duration

type StateRefreshFunc

type StateRefreshFunc func() (state interface{}, err error)

Jump to

Keyboard shortcuts

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