cluster

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ComponentDBMSMaster = "dbms-master"
	ComponentDBMSWorker = "dbms-worker"
)
View Source
const (
	// DefaultDeployUser is the cluster deploy default user
	DefaultDeployUser = "dbms"
	// metadata
	// MetaFileName is the file name of the cluster topology file, eg. {clusterName}/
	MetaFileName = "meta.yaml"
	// CacheDirName is the directory to save cluster cache file .eg. {clusterName}/{CacheDirName}
	CacheDirName = "cache"
	// PatchDirName is the directory to store patch file, eg. {clusterName}/{PatchDirName}/dbms-hotfix.tar.gz
	PatchDirName = "patch"
	// SshDirName is the directory to store cluster ssh file, eg. {clusterName}/{SshDirName}
	SshDirName = "ssh"
	// AuditDirName is the directory to store cluster operation audit log, eg. {clusterName}/{AuditDirName}
	AuditDirName = "audit"
	// LockDirName is the directory to store cluster operation lock
	LockDirName      = "lock"
	ScaleOutLockName = "scale-out.yaml"

	// InstantClientDir is the directory to store the oracle instance client
	InstantClientDir = "instantclient"

	// cluster
	// BinDirName is the directory to save bin files
	BinDirName = "bin"
	// BackupDirName is the directory to save backup files
	BackupDirName = "backup"
	// ScriptDirName is the directory to save script files
	ScriptDirName = "script"
	// ConfDirName is the directory to save script files
	ConfDirName = "conf"
	// DataDirName is the directory to save script files
	DataDirName = "data"
	// LogDirName is the directory to save script files
	LogDirName = "log"
)

Variables

This section is empty.

Functions

func CheckCommandArgsAndMayPrintHelp

func CheckCommandArgsAndMayPrintHelp(cmd *cobra.Command, args []string, minArgs int) (shouldContinue bool, err error)

CheckCommandArgsAndMayPrintHelp checks whether user passes enough number of arguments. If insufficient number of arguments are passed, an error with proper suggestion will be raised. When no argument is passed, command help will be printed and no error will be raised.

func CurrentUser

func CurrentUser() string

CurrentUser returns current login user

func ExpandRelativeDir

func ExpandRelativeDir(topo *Topology)

ExpandRelativeDir fill DeployDir, DataDir and LogDir to absolute path

func FillHostArchOrOS

func FillHostArchOrOS(s any, hostArchOrOS map[string]string, fullType FullHostType) error

FillHostArchOrOS fills the topology with the given host->arch

func FillTopologyDataDir

func FillTopologyDataDir(globalDeployDir, globalDataDir, instDataDir string) string

FillTopologyDataDir fill topology data dir

func FillTopologyDeployDir

func FillTopologyDeployDir(globalDeployDir, instDeployDir, compRole string, compPort int) string

FillTopologyDeployDir fill topology deploy dir

func FillTopologyLogDir

func FillTopologyLogDir(globalDeployDir, globalLogDir, instLogDir string) string

FillTopologyLogDir fill topology log dir

func FmtVer

func FmtVer(ver string) (string, error)

FmtVer converts a version string to SemVer format, if the string is not a valid SemVer and fails to parse and convert it, an error is raised.

func PortStarted

func PortStarted(ctx context.Context, e executor.Executor, os string, port int, timeout uint64) error

PortStarted wait until a port is being listened

func PortStopped

func PortStopped(ctx context.Context, e executor.Executor, os string, port int, timeout uint64) error

PortStopped wait until a port is being released

func ReadYamlFile

func ReadYamlFile(file string) ([]byte, error)

ReadYamlFile read yaml content from file`

func UserHome

func UserHome() string

UserHome returns home directory of current user

func ValidateClusterNameOrError

func ValidateClusterNameOrError(n string) error

ValidateClusterNameOrError validates a cluster name and returns error if the name is invalid.

Types

type BaseInstance

type BaseInstance struct {
	InstanceTopology
	Host       string
	ManageHost string
	ListenHost string
	Port       int
	SSHPort    int
	PeerPort   int
	NumaNode   string

	Patched   bool
	DeployDir string
	DataDir   string
	LogDir    string
	OSVersion string
	OSArch    string

	StatusFn func(ctx context.Context, tlsCfg *tls.Config, pdHosts ...string) (string, error)

	Config    map[string]any
	Component Component
}

BaseInstance implements some method of Instance interface

func (*BaseInstance) Arch

func (b *BaseInstance) Arch() string

Arch implement Instance interface

func (*BaseInstance) ComponentName

func (b *BaseInstance) ComponentName() string

ComponentName implement Instance interface

func (*BaseInstance) ComponentRole

func (b *BaseInstance) ComponentRole() string

ComponentRole implement Instance interface

func (*BaseInstance) GetInstanceConfig

func (b *BaseInstance) GetInstanceConfig() map[string]any

GetInstanceConfig implement Instance interface

func (*BaseInstance) InitSystemdConfig

func (b *BaseInstance) InitSystemdConfig(ctx context.Context, e executor.Executor, opt *GlobalOptions, user, cacheDir string) error

InitSystemdConfig init the service configuration.

func (*BaseInstance) InstanceDataDir

func (b *BaseInstance) InstanceDataDir() string

InstanceDataDir implement Instance interface

func (*BaseInstance) InstanceDeployDir

func (b *BaseInstance) InstanceDeployDir() string

InstanceDeployDir implement Instance interface

func (*BaseInstance) InstanceHost

func (b *BaseInstance) InstanceHost() string

InstanceHost implement Instance interface

func (*BaseInstance) InstanceListenHost

func (b *BaseInstance) InstanceListenHost() string

InstanceListenHost implement Instance interface

func (*BaseInstance) InstanceLogDir

func (b *BaseInstance) InstanceLogDir() string

InstanceLogDir implement Instance interface

func (*BaseInstance) InstanceManageHost

func (b *BaseInstance) InstanceManageHost() string

InstanceManageHost implement Instance interface

func (*BaseInstance) InstanceName

func (b *BaseInstance) InstanceName() string

InstanceName implement Instance interface

func (*BaseInstance) InstanceNumaNode

func (b *BaseInstance) InstanceNumaNode() string

InstanceNumaNode implement Instance interface

func (*BaseInstance) InstancePeerPort

func (b *BaseInstance) InstancePeerPort() int

InstancePeerPort implement Instance interface

func (*BaseInstance) InstancePort

func (b *BaseInstance) InstancePort() int

InstancePort implement Instance interface

func (*BaseInstance) InstanceSshPort

func (b *BaseInstance) InstanceSshPort() int

InstanceSshPort implement Instance interface

func (*BaseInstance) IsPatched

func (b *BaseInstance) IsPatched() bool

IsPatched implement Instance interface

func (*BaseInstance) MergeServerConfig

func (b *BaseInstance) MergeServerConfig(ctx context.Context, e executor.Executor, globalCfg, instanceCfg map[string]any, cacheDir string) error

MergeServerConfig merges the server configuration and overwrite the global configuration

func (*BaseInstance) OS

func (b *BaseInstance) OS() string

OS implement Instance interface

func (*BaseInstance) ServiceName

func (b *BaseInstance) ServiceName() string

ServiceName implement Instance interface

func (*BaseInstance) ServiceReady

func (b *BaseInstance) ServiceReady(ctx context.Context, e executor.Executor, timeout uint64) error

ServiceReady implement Instance interface

func (*BaseInstance) SetPatched

func (b *BaseInstance) SetPatched(patch bool)

SetPatched implement Instance interface

func (*BaseInstance) Status

func (b *BaseInstance) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error)

Status implement Instance interface

func (*BaseInstance) UsedDir

func (b *BaseInstance) UsedDir() []string

UsedDir implement Instance interface

func (*BaseInstance) UsedPort

func (b *BaseInstance) UsedPort() []int

UsedPort implement Instance interface

type Component

type Component interface {
	ComponentName() string
	ComponentRole() string
	Instances() []Instance
}

Component represents a component of the cluster.

type DBMSMasterComponent

type DBMSMasterComponent struct {
	Topology *Topology
}

func (*DBMSMasterComponent) ComponentName

func (m *DBMSMasterComponent) ComponentName() string

func (*DBMSMasterComponent) ComponentRole

func (m *DBMSMasterComponent) ComponentRole() string

func (*DBMSMasterComponent) Instances

func (m *DBMSMasterComponent) Instances() []Instance

type DBMSWorkerComponent

type DBMSWorkerComponent struct {
	Topology *Topology
}

func (*DBMSWorkerComponent) ComponentName

func (m *DBMSWorkerComponent) ComponentName() string

func (*DBMSWorkerComponent) ComponentRole

func (m *DBMSWorkerComponent) ComponentRole() string

func (*DBMSWorkerComponent) Instances

func (m *DBMSWorkerComponent) Instances() []Instance

type FullHostType

type FullHostType string

FullHostType is the type of fullhost operations

const (
	// FullArchType cpu-arch type
	FullArchType FullHostType = "Arch"
	// FullOSType kernel-name
	FullOSType FullHostType = "OS"
)

type GlobalOptions

type GlobalOptions struct {
	User        string      `yaml:"user,omitempty" default:"dbms"`
	Group       string      `yaml:"group,omitempty"`
	SSHPort     int         `yaml:"ssh_port,omitempty" default:"22" validate:"ssh_port:editable"`
	SSHType     string      `yaml:"ssh_type,omitempty" default:"builtin"`
	ListenHost  string      `yaml:"listen_host,omitempty" validate:"listen_host:editable"`
	DeployDir   string      `yaml:"deploy_dir,omitempty" default:"deploy"`
	DataDir     string      `yaml:"data_dir,omitempty" default:"data"`
	LogDir      string      `yaml:"log_dir,omitempty"`
	OS          string      `yaml:"os,omitempty" default:"linux"`
	Arch        string      `yaml:"arch,omitempty"`
	SystemdMode SystemdMode `yaml:"systemd_mode,omitempty" default:"system"`
}

type IMetadata

type IMetadata interface {
	SetUser(user string)
	SetVersion(version string)
	SetTopology(topo *Topology)
	GetTopology() *Topology
	GetUser() string
	GetVersion() string
	GenMetadata() *Metadata
	ScaleOutTopology(topo *Topology)
}

type Instance

type Instance interface {
	InstanceName() string
	InstanceManageHost() string
	InstanceHost() string
	InstancePort() int
	InstancePeerPort() int
	InstanceSshPort() int
	InstanceDeployDir() string
	InstanceDataDir() string
	InstanceLogDir() string
	InstanceListenHost() string
	InstanceNumaNode() string
	OS() string
	Arch() string
	GetInstanceConfig() map[string]any
	UsedPort() []int
	UsedDir() []string
	ComponentName() string
	ComponentRole() string
	ServiceName() string
	ServiceReady(ctx context.Context, e executor.Executor, timeout uint64) error
	InstanceInitConfig(ctx context.Context, e executor.Executor, deployUser string, cacheDir string) error
	InstanceScaleConfig(ctx context.Context, e executor.Executor, topo *Topology, deployUser, cacheDir string) error
	Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error)
	IsPatched() bool
	SetPatched(patch bool)
}

Instance represents the instance.

type InstanceTopology

type InstanceTopology interface {
	InstanceRole() string
	InstanceName() string
}

InstanceTopology represents a instance topology, used to reflect get component instance topology and update instance topology

type MasterInstance

type MasterInstance struct {
	BaseInstance
	// contains filtered or unexported fields
}

MasterInstance represent the dbms-master instance

func (*MasterInstance) InstanceInitConfig

func (m *MasterInstance) InstanceInitConfig(ctx context.Context, e executor.Executor, deployUser string, cacheDir string) error

InstanceInitConfig implements Instance interface

func (*MasterInstance) InstanceScaleConfig

func (m *MasterInstance) InstanceScaleConfig(ctx context.Context, e executor.Executor, topo *Topology, deployUser, cacheDir string) error

InstanceScaleConfig implements Instance interface

type MasterOptions

type MasterOptions struct {
	Host             string         `yaml:"host"`
	ManageHost       string         `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	SSHPort          int            `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`
	Patched          bool           `yaml:"patched,omitempty"`
	Port             int            `yaml:"port,omitempty" default:"8261"`
	PeerPort         int            `yaml:"peer_port,omitempty" default:"8291"`
	DeployDir        string         `yaml:"deploy_dir,omitempty"`
	DataDir          string         `yaml:"data_dir,omitempty"`
	LogDir           string         `yaml:"log_dir,omitempty"`
	InstanceNumaNode string         `yaml:"numa_node,omitempty" validate:"numa_node:editable"`
	Config           map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
	Arch             string         `yaml:"arch,omitempty"`
	OS               string         `yaml:"os,omitempty"`
}

MasterOptions represents the Master topology specification in topology.yaml

func (*MasterOptions) InstanceName

func (s *MasterOptions) InstanceName() string

func (*MasterOptions) InstanceRole

func (s *MasterOptions) InstanceRole() string

func (*MasterOptions) Status

func (s *MasterOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error)

Status queries current status of the instance

type Metadata

type Metadata struct {
	User     string    `yaml:"user"`
	Version  string    `yaml:"version"`
	Topology *Topology `yaml:"topology"`
}

func ParseMetadataYaml

func ParseMetadataYaml(file string) (*Metadata, error)

ParseMetadataYaml read yaml content from `file` and unmarshal it to `out`

func (*Metadata) GenMetadata

func (m *Metadata) GenMetadata() *Metadata

func (*Metadata) GetTopology

func (m *Metadata) GetTopology() *Topology

func (*Metadata) GetUser

func (m *Metadata) GetUser() string

func (*Metadata) GetVersion

func (m *Metadata) GetVersion() string

func (*Metadata) ScaleOutTopology

func (m *Metadata) ScaleOutTopology(topo *Topology)

func (*Metadata) SetTopology

func (m *Metadata) SetTopology(topo *Topology)

func (*Metadata) SetUser

func (m *Metadata) SetUser(user string)

func (*Metadata) SetVersion

func (m *Metadata) SetVersion(version string)

type ServerConfig

type ServerConfig struct {
	Master map[string]any `yaml:"master"`
	Worker map[string]any `yaml:"worker"`
}

type SystemdMode

type SystemdMode string

SystemdMode is the mode used by systemctl

const (
	// SystemMode system mode
	SystemMode SystemdMode = "system"
	// UserMode user mode
	UserMode SystemdMode = "user"
)

type Topology

type Topology struct {
	GlobalOptions *GlobalOptions   `yaml:"global,omitempty" validate:"global:editable"`
	ServerConfigs *ServerConfig    `yaml:"server_configs,omitempty" validate:"server_configs:ignore"`
	MasterServers []*MasterOptions `yaml:"master_servers"`
	WorkerServers []*WorkerOptions `yaml:"worker_servers"`
}

func ParseTopologyYaml

func ParseTopologyYaml(file string) (*Topology, error)

ParseTopologyYaml read yaml content from `file` and unmarshal it to `out` ignoreGlobal ignore global variables in file, only ignoreGlobal with a index of 0 is effective

func (*Topology) ComponentsByStartOrder

func (t *Topology) ComponentsByStartOrder() (comps []Component)

ComponentsByStartOrder return component in the order need to start.

func (*Topology) ComponentsByStopOrder

func (t *Topology) ComponentsByStopOrder() (comps []Component)

ComponentsByStopOrder return component in the order need to stop.

func (*Topology) ComponentsByUpdateOrder

func (t *Topology) ComponentsByUpdateOrder() (comps []Component)

ComponentsByUpdateOrder return component in the order need to be updated.

func (*Topology) CountDir

func (t *Topology) CountDir(targetHost, dirPrefix string) int

CountDir counts for dir paths used by any instance in the cluster with the same prefix, useful to find potential path conflicts

func (*Topology) FillHostArchOrOS

func (t *Topology) FillHostArchOrOS(hostArch map[string]string, fullType FullHostType) error

FillHostArchOrOS fills the topology with the given host->arch

func (*Topology) IterComponent

func (t *Topology) IterComponent(fn func(c Component))

IterComponent iterates all components in component starting order

func (*Topology) IterInstance

func (t *Topology) IterInstance(fn func(inst Instance), concurrency ...int)

IterInstance iterates all instances in component starting order

func (*Topology) String

func (t *Topology) String() string

type WorkerInstance

type WorkerInstance struct {
	BaseInstance
	// contains filtered or unexported fields
}

WorkerInstance represent the dbms-worker instance

func (*WorkerInstance) InstanceInitConfig

func (w *WorkerInstance) InstanceInitConfig(ctx context.Context, e executor.Executor, deployUser string, cacheDir string) error

InstanceInitConfig implements Instance interface

func (*WorkerInstance) InstanceScaleConfig

func (w *WorkerInstance) InstanceScaleConfig(ctx context.Context, e executor.Executor, topo *Topology, deployUser, cacheDir string) error

InstanceScaleConfig implements Instance interface

type WorkerOptions

type WorkerOptions struct {
	Host             string         `yaml:"host"`
	ManageHost       string         `yaml:"manage_host,omitempty" validate:"manage_host:editable"`
	SSHPort          int            `yaml:"ssh_port,omitempty" validate:"ssh_port:editable"`
	Patched          bool           `yaml:"patched,omitempty"`
	Port             int            `yaml:"port,omitempty" default:"8262"`
	DeployDir        string         `yaml:"deploy_dir,omitempty"`
	LogDir           string         `yaml:"log_dir,omitempty"`
	InstanceNumaNode string         `yaml:"numa_node,omitempty" validate:"numa_node:editable"`
	Config           map[string]any `yaml:"config,omitempty" validate:"config:ignore"`
	Arch             string         `yaml:"arch,omitempty"`
	OS               string         `yaml:"os,omitempty"`
}

WorkerOptions represents the Master topology specification in topology.yaml

func (*WorkerOptions) InstanceName

func (w *WorkerOptions) InstanceName() string

func (*WorkerOptions) InstanceRole

func (w *WorkerOptions) InstanceRole() string

func (*WorkerOptions) Status

func (w *WorkerOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error)

Status queries current status of the instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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