cluster

package
v1.0.17 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConstructSSHCommand

func ConstructSSHCommand(useLocal bool, host string, cmd string) []string

func LogFatalClusterError

func LogFatalClusterError(errMessage string, scope Scope, numErrors int)

Types

type Cluster

type Cluster struct {
	ContentIDs []int
	Hostnames  []string
	Segments   []SegConfig
	ByContent  map[int][]*SegConfig
	ByHost     map[string][]*SegConfig
	Executor
}

* A Cluster object stores information about the cluster in three ways: * - Segments is basically equivalent to gp_segment_configuration, a plain * list of segment information, and is ordered by content id. * - ByContent is a map of content id to the single corresponding segment. * - ByHost is a map of hostname to all of the segments on that host. * The maps are only stored for efficient lookup; Segments is the "source of * truth" for the cluster. The maps actually hold pointers to the SegConfigs * in Segments, so modifying Segments will modify the maps as well.

func NewCluster

func NewCluster(segConfigs []SegConfig) *Cluster

func (*Cluster) CheckClusterError

func (cluster *Cluster) CheckClusterError(remoteOutput *RemoteOutput, finalErrMsg string, messageFunc interface{}, noFatal ...bool)

func (*Cluster) GenerateAndExecuteCommand

func (cluster *Cluster) GenerateAndExecuteCommand(verboseMsg string, scope Scope, generator interface{}) *RemoteOutput

* GenerateAndExecuteCommand and CheckClusterError are generic wrapper functions * to simplify execution of... * 1. shell commands directly on remote hosts via ssh. * - e.g. running an ls on all hosts * 2. shell commands on coordinator to push to remote hosts. * - e.g. running multiple scps on coordinator to push a file to all segments

func (*Cluster) GenerateCommandList added in v1.0.4

func (cluster *Cluster) GenerateCommandList(scope Scope, generator interface{}) []ShellCommand

* Because cluster commands can be executed either per-segment or per-host, the * "generator" argument to this function can accept one of two types: * - func(int) []string, which takes a content id, for per-segment commands * - func(string) []string, which takes a hostname, for per-host commands * The function uses a type switch to identify the right one, and panics if * an invalid function type is passed in via programmer error. * This method makes it easier for the user to pass in whichever function fits * the kind of command they're generating, as opposed to having to pass in both * content and hostname regardless of scope or using some sort of helper struct.

func (*Cluster) GenerateSSHCommandList added in v1.0.4

func (cluster *Cluster) GenerateSSHCommandList(scope Scope, generator interface{}) []ShellCommand

* This function essentially wraps GenerateCommandList such that commands to be * executed on other hosts are sent through SSH and local commands use Bash.

func (*Cluster) GetContentsForHost added in v1.0.4

func (cluster *Cluster) GetContentsForHost(hostname string) []int

func (*Cluster) GetDbidForContent

func (cluster *Cluster) GetDbidForContent(contentID int, role ...string) int

func (*Cluster) GetDbidsForHost added in v1.0.4

func (cluster *Cluster) GetDbidsForHost(hostname string) []int

func (*Cluster) GetDirForContent

func (cluster *Cluster) GetDirForContent(contentID int, role ...string) string

func (*Cluster) GetDirsForHost added in v1.0.4

func (cluster *Cluster) GetDirsForHost(hostname string) []string

func (*Cluster) GetHostForContent

func (cluster *Cluster) GetHostForContent(contentID int, role ...string) string

func (*Cluster) GetPortForContent

func (cluster *Cluster) GetPortForContent(contentID int, role ...string) int

func (*Cluster) GetPortsForHost added in v1.0.4

func (cluster *Cluster) GetPortsForHost(hostname string) []int

type Executor

type Executor interface {
	ExecuteLocalCommand(commandStr string) (string, error)
	ExecuteClusterCommand(scope Scope, commandList []ShellCommand) *RemoteOutput
}

type GPDBExecutor

type GPDBExecutor struct{}

This type only exists to allow us to mock Execute[...]Command functions for testing

func (*GPDBExecutor) ExecuteClusterCommand

func (executor *GPDBExecutor) ExecuteClusterCommand(scope Scope, commandList []ShellCommand) *RemoteOutput

* This function just executes all of the commands passed to it in parallel; it * doesn't care about the scope of the command except to pass that on to the * RemoteOutput after execution. * TODO: Add batching to prevent bottlenecks when executing in a huge cluster.

func (*GPDBExecutor) ExecuteLocalCommand

func (executor *GPDBExecutor) ExecuteLocalCommand(commandStr string) (string, error)

type RemoteOutput

type RemoteOutput struct {
	Scope          Scope
	NumErrors      int
	Commands       []ShellCommand
	FailedCommands []*ShellCommand
}

* A RemoteOutput is used to make it easier to identify the success or failure * of a cluster command and to display the results to the user.

func NewRemoteOutput added in v1.0.4

func NewRemoteOutput(scope Scope, numErrors int, commands []ShellCommand) *RemoteOutput

type Scope added in v1.0.4

type Scope uint8
const (
	ON_SEGMENTS         Scope = 0
	ON_HOSTS            Scope = 1
	EXCLUDE_COORDINATOR Scope = 0
	INCLUDE_COORDINATOR Scope = 1 << 1
	EXCLUDE_MASTER      Scope = 0
	INCLUDE_MASTER      Scope = 1 << 1
	ON_REMOTE           Scope = 0
	ON_LOCAL            Scope = 1 << 2
	EXCLUDE_MIRRORS     Scope = 0
	INCLUDE_MIRRORS     Scope = 1 << 3
)

type SegConfig

type SegConfig struct {
	DbID          int
	ContentID     int
	Role          string
	PreferredRole string
	Mode          string
	Status        string
	Port          int
	Hostname      string
	Address       string
	DataDir       string
}

func GetSegmentConfiguration

func GetSegmentConfiguration(connection *dbconn.DBConn, getMirrors ...bool) ([]SegConfig, error)

* This function accepts up to two booleans: * By default, it retrieves only primary and coordinator information. * If the first boolean is set to true, it also retrieves mirror and standby information. * If the second is set to true, it retrieves only mirror and standby information, regardless of the value of the first boolean.

func GetSegmentConfigurationFromFile added in v1.0.15

func GetSegmentConfigurationFromFile(coordinatorDataDir string) ([]SegConfig, error)

func MustGetSegmentConfiguration

func MustGetSegmentConfiguration(connection *dbconn.DBConn, getMirrors ...bool) []SegConfig

type ShellCommand added in v1.0.4

type ShellCommand struct {
	Scope         Scope
	Content       int
	Host          string
	Command       *exec.Cmd
	CommandString string
	Stdout        string
	Stderr        string
	Error         error
	Completed     bool
}

* A ShellCommand stores a command to be executed (in both executable and * display form), as well as the results of the command execution and the * necessary information to determine how the command will be or was executed. * * It is assumed that before a caller references Content or Host for a given * command, they will check Scope to ensure that that field is meaningful for * that command. GenerateCommandList sets Host to "" for per-segment commands * and Content to -2 for per-host commands, just to be safe.

func NewShellCommand added in v1.0.4

func NewShellCommand(scope Scope, content int, host string, command []string) ShellCommand

Jump to

Keyboard shortcuts

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