Documentation ¶
Overview ¶
DBDeployer - The MySQL Sandbox Copyright © 2006-2019 Giuseppe Maxia
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
- Variables
- func AbsolutePath(value string) (string, error)
- func AddToCleanupStack(cf CleanupFunc, funcName, arg string)
- func AppendStrings(lines []string, filename string, termination string) error
- func Atoi(val string) int
- func BaseName(filename string) string
- func CheckFlavorSupport(flavor string) error
- func CheckOrigin(args []string)
- func CheckSandboxDir(sandboxHome string) error
- func CheckTarballOperatingSystem(basedir string) error
- func CondPrintf(format string, args ...interface{})
- func CondPrintln(args ...interface{})
- func CopyFile(source, destination string) error
- func DetectBinaryFlavor(basedir string) string
- func DirExists(filename string) bool
- func DirName(filename string) string
- func ErrCheckExitf(err error, exitCode int, format string, args ...interface{})
- func ExecExists(filename string) bool
- func Exit(exitCode int, messages ...string)
- func Exitf(exitCode int, format string, args ...interface{})
- func FileExists(filename string) bool
- func FindFreePort(basePort int, installedPorts []int, howMany int) (int, error)
- func FindInPath(filename string) string
- func GetAvailableVersions() ([]string, error)
- func GetInstalledPorts(sandboxHome string) ([]int, error)
- func GetVersionsFromDir(basedir string) ([]string, error)
- func GreaterOrEqualVersion(version string, comparedTo []int) (bool, error)
- func GreaterOrEqualVersionList(verList, comparedTo []int) (bool, error)
- func HasCapability(flavor, feature, version string) (bool, error)
- func Includes(mainString, contained string) bool
- func IntSliceToDottedString(val []int) string
- func IsATarball(fileName string) bool
- func IsEnvSet(envVar string) bool
- func IsIPV4(ip string) bool
- func IsVersion(version string) bool
- func LatestVersion(searchDir, pattern string) string
- func LogDirName() string
- func MakeCustomizedUuid(port, nodeNum int) (string, error)
- func Mkdir(dirName string)
- func RemoveTrailingSlash(s string) string
- func ReplaceEnvVar(name string, envVar string) string
- func ReplaceHomeVar(path string) string
- func ReplaceLiteralEnvVar(name string, envVar string) string
- func ReplaceLiteralHome(path string) string
- func Rmdir(dirName string)
- func RmdirAll(dirName string)
- func RunCleanupActions()
- func RunCmd(c string) (string, error)
- func RunCmdCtrl(c string, silent bool) (string, error)
- func RunCmdWithArgs(c string, args []string) (string, error)
- func SandboxInfoToFileNames(sbList []SandboxInfo) (fileNames []string)
- func SlurpAsBytes(filename string) ([]byte, error)
- func SlurpAsLines(filename string) ([]string, error)
- func SlurpAsString(filename string) (string, error)
- func SortVersions(versions []string) []string
- func SortVersionsSubset(versions []string, wanted string) (sorted []string)
- func StringToIntSlice(val string) (numberList []int, err error)
- func TemplateFill(tmpl string, data StringMap) string
- func TextToBool(value string) (result bool)
- func TrimmedLines(s string) string
- func VersionToList(version string) ([]int, error)
- func VersionToName(version string) string
- func VersionToPort(version string) (int, error)
- func Which(filename string) string
- func WriteSandboxDescription(destination string, sd SandboxDescription) error
- func WriteString(line string, filename string) error
- func WriteStrings(lines []string, filename string, termination string) error
- type Capabilities
- type Capability
- type CleanupFunc
- type CleanupRec
- type ConfigOptions
- type FeatureList
- type KeyValue
- type MinimumVersion
- type PortMap
- type SandboxDescription
- type SandboxInfo
- type SandboxUser
- type Stack
- type StringMap
Constants ¶
const ( // Tarball flavors MySQLFlavor = "mysql" PerconaServerFlavor = "percona" MariaDbFlavor = "mariadb" NDBFlavor = "ndb" TiDbFlavor = "tidb" // Feature names InstallDb = "installdb" DynVariables = "dynVars" SemiSynch = "semiSync" CrashSafe = "crashSafe" GTID = "GTID" EnhancedGTID = "enhancedGTID" Initialize = "initialize" CreateUser = "createUser" SuperReadOnly = "superReadOnly" MySQLX = "mysqlx" MySQLXDefault = "mysqlxDefault" MultiSource = "multiSource" GroupReplication = "groupReplication" SetPersist = "setPersist" Roles = "roles" NativeAuth = "nativeAuth" DataDict = "datadict" )
Variables ¶
var AllCapabilities = map[string]Capabilities{ MySQLFlavor: MySQLCapabilities, PerconaServerFlavor: PerconaCapabilities, MariaDbFlavor: MariadbCapabilities, TiDbFlavor: TiDBCapabilities, NDBFlavor: NDBCapabilities, }
var CommandLineArgs []string
var CompatibleVersion string = "1.19.0" // 2019-02-17
Compatible version is the version used to mark compatible archives (templates, configuration). It is usually major.minor.0, except when we are at version 0.x, when every revision may bring incompatibility
var MariadbCapabilities = Capabilities{ Flavor: MariaDbFlavor, Features: FeatureList{ InstallDb: { Description: "uses mysql_install_db", Since: globals.MinimumMySQLInstallDb, Until: nil, }, DynVariables: MySQLCapabilities.Features[DynVariables], SemiSynch: MySQLCapabilities.Features[SemiSynch], }, }
NOTE: We only list the capabilities for which dbdeployer needs to take action
var MySQLCapabilities = Capabilities{ Flavor: MySQLFlavor, Features: FeatureList{ InstallDb: { Description: "uses mysql_install_db", Since: globals.MinimumMySQLInstallDb, Until: globals.MaximumMySQLInstallDb, }, DynVariables: { Description: "dynamic variables", Since: globals.MinimumDynVariablesVersion, }, SemiSynch: { Description: "semi-synchronous replication", Since: globals.MinimumSemiSyncVersion, }, CrashSafe: { Description: "crash-safe replication", Since: globals.MinimumCrashSafeVersion, }, GTID: { Description: "Global transaction identifiers", Since: globals.MinimumGtidVersion, }, EnhancedGTID: { Description: "Enhanced Global transaction identifiers", Since: globals.MinimumEnhancedGtidVersion, }, Initialize: { Description: "mysqld --initialize as default", Since: globals.MinimumDefaultInitializeVersion, }, CreateUser: { Description: "Create user mandatory", Since: globals.MinimumCreateUserVersion, }, SuperReadOnly: { Description: "super-read-only support", Since: globals.MinimumSuperReadOnly, }, MySQLX: { Description: "MySQLX supported", Since: globals.MinimumMysqlxVersion, }, MySQLXDefault: { Description: "MySQLX enabled by default", Since: globals.MinimumMysqlxDefaultVersion, }, MultiSource: { Description: "multi-source replication", Since: globals.MinimumMultiSourceReplVersion, }, GroupReplication: { Description: "group replication", Since: globals.MinimumGroupReplVersion, }, SetPersist: { Description: "Set persist supported", Since: globals.MinimumPersistVersion, }, Roles: { Description: "Roles supported", Since: globals.MinimumRolesVersion, }, NativeAuth: { Description: "Native Authentication plugin", Since: globals.MinimumNativeAuthPluginVersion, }, DataDict: { Description: "data dictionary", Since: globals.MinimumDataDictionaryVersion, }, }, }
var NDBCapabilities = Capabilities{}
var PerconaCapabilities = Capabilities{ Flavor: PerconaServerFlavor, Features: MySQLCapabilities.Features, }
var TiDBCapabilities = Capabilities{}
var VersionDef string = "1.19.0" // 2019-02-17
Functions ¶
func AbsolutePath ¶
Returns the absolute path of a file
func AddToCleanupStack ¶
func AddToCleanupStack(cf CleanupFunc, funcName, arg string)
Adds an action to the list of clean-up operations to run before aborting the program
func AppendStrings ¶
append a string slice into an existing file
func CheckFlavorSupport ¶ added in v1.19.0
func CheckOrigin ¶
func CheckOrigin(args []string)
Checks the initial argument for a sandbox deployment
func CheckSandboxDir ¶
Creates a sandbox directory if it does not exist
func CheckTarballOperatingSystem ¶
Checks that the extracted tarball directory
contains one or more files expected for the current operating system. It prevents simple errors like : * using a Linux tarball on a Mac or vice-versa * using a source or test tarball instead of a binaries one.
func CondPrintf ¶
func CondPrintf(format string, args ...interface{})
func CondPrintln ¶
func CondPrintln(args ...interface{})
func DetectBinaryFlavor ¶ added in v1.19.0
Tries to detect the database flavor from files in the tarball directory
func ErrCheckExitf ¶
Checks the status of error variable and exit with custom message if it is not nil.
func FindFreePort ¶
Finds the a range of howMany free ports available, starting at basePort. installedPorts is a slice of ports already used by other sandboxes. Calls either findFreePortRange or findFreePortSingle, depending on the amount of ports requested. Returns the first port of the requested range
func GetAvailableVersions ¶
func GetInstalledPorts ¶
Collects a list of used ports from deployed sandboxes
func GetVersionsFromDir ¶
Returns the list of versions available for deployment
func GreaterOrEqualVersion ¶
Checks if a version string is greater or equal a given numeric version "5.6.33" >= []int{5,7,0} = false "5.7.21" >= []int{5,7,0} = true "10.1.21" >= []int{5,7,0} = false (!) Note: MariaDB versions are skipped. The function returns false for MariaDB 10+. So far (2018-02-19) this comparison holds, because MariaDB behaves like 5.5+ for the purposes of sandbox deployment
DEPRECATED as of 1.18.0 Use GreaterOrEqualVersionList and flavors instead
func GreaterOrEqualVersionList ¶ added in v1.19.0
func HasCapability ¶ added in v1.19.0
func IntSliceToDottedString ¶
Given an array of integers, returns a string containing the numbers separated by a dot. For example: an input of []int{1, 2, 3} returns "1.2.3"
func IsATarball ¶
Returns true if the file name has a recognized tarball extension for use with dbdeployer
func LatestVersion ¶
Returns the latest version among the ones found in a Sandbox binary directory
func MakeCustomizedUuid ¶
Creates a "human readable" and predictable UUID using some pre-defined elements. Used to replace the random UUID created by MySQL 5.6+, with the purpose of returning easy to read server identifiers that can be processed visually.
func RemoveTrailingSlash ¶
Removes a slash (if any) at the end of a given string
func ReplaceEnvVar ¶
Replaces the environment variable `envVar` with its value for example, if "$HOME" resolves to "/home/goofy" the string "$HOME/some/path" would become "/home/goofy/some/path"
func ReplaceHomeVar ¶
Given a path with the variable "$HOME" at the start, returns a string with the value of HOME expanded
func ReplaceLiteralEnvVar ¶
Replaces the literal value of an environment variable with its name for example, if "$HOME" resolves to "/home/goofy" the string "/home/goofy/some/path" would become "$HOME/some/path"
func ReplaceLiteralHome ¶
Given a path starting at the HOME directory returns a string where the literal value for $HOME is replaced by the string "$HOME"
func RmdirAll ¶
func RmdirAll(dirName string)
Removes a directory with its contents, and exits if an error occurs
func RunCmdCtrl ¶
Runs a command, with optional quiet output
func RunCmdWithArgs ¶
Runs a command with arguments
func SandboxInfoToFileNames ¶
func SandboxInfoToFileNames(sbList []SandboxInfo) (fileNames []string)
Returns a list of inner sandboxes
func SlurpAsBytes ¶
reads a file and returns its contents as a byte slice
func SlurpAsLines ¶
Reads a file and returns its lines as a string slice
func SlurpAsString ¶
Reads a file and returns its contents as a single string
func SortVersions ¶
func SortVersionsSubset ¶
Given a list of version strings (in the format x.x.x) this function returns an ordered list, taking into account the components of the versions, so that 5.6.2 sorts lower than 5.6.11 while a text sort would put 5.6.11 before 5.6.2 If wanted is not empty, it will be interpreted as a short version to match. For example, when wanted is "5.6", only the versions starting with '5.6' will be considered.
func StringToIntSlice ¶
Given a string containing comma-separated integers, returns an array of integers Example: an input of "1,2,3" returns []int{1, 2, 3}
func TemplateFill ¶
TemplateFill passed template string is formatted using its operands and returns the resulting string. Spaces are added between operands when neither is a string. Based on code from https://play.golang.org/p/COHKlB2RML
func TextToBool ¶
Returns true if the input value is either of "true", "yes", "1"
func TrimmedLines ¶
Given a multi-line string, this function removes leading spaces from every line. It also removes the first line, if it is empty
func VersionToList ¶
Gets three integers for a version string Converts "1.2.3" into []int{1, 2, 3}
func VersionToName ¶
Converts a version string into a name. Replaces dots with underscores. "1.2.3" -> "1_2_3"
func VersionToPort ¶
Converts a version string into a port number e.g. "5.6.33" -> 5633
func Which ¶
Returns the full path of an executable, or an empty string if the executable is not found
func WriteSandboxDescription ¶
func WriteSandboxDescription(destination string, sd SandboxDescription) error
Writes the description of a sandbox in the appropriate directory
func WriteString ¶
append a string into an existing file
Types ¶
type Capabilities ¶ added in v1.19.0
type Capabilities struct { Flavor string `json:"flavor"` Features FeatureList `json:"features"` }
type Capability ¶ added in v1.19.0
type Capability struct { Description string `json:"description"` Since MinimumVersion `json:"since"` Until MinimumVersion `json:"until"` }
type CleanupFunc ¶
type CleanupFunc func(target string)
type CleanupRec ¶
type CleanupRec struct {
// contains filtered or unexported fields
}
type ConfigOptions ¶
func ParseConfigFile ¶
func ParseConfigFile(filename string) (ConfigOptions, error)
Reads a MySQL configuration file and returns its structured contents
type FeatureList ¶ added in v1.19.0
type FeatureList map[string]Capability
type MinimumVersion ¶ added in v1.19.0
type MinimumVersion []int
type SandboxDescription ¶
type SandboxDescription struct { Basedir string `json:"basedir"` ClientBasedir string `json:"client_basedir,omitempty"` SBType string `json:"type"` // single multi master-slave group Version string `json:"version"` Flavor string `json:"flavor,omitempty"` Port []int `json:"port"` Nodes int `json:"nodes"` NodeNum int `json:"node_num"` DbDeployerVersion string `json:"dbdeployer-version"` Timestamp string `json:"timestamp"` CommandLine string `json:"command-line"` LogFile string `json:"log-file,omitempty"` }
func ReadSandboxDescription ¶
func ReadSandboxDescription(sandboxDirectory string) (SandboxDescription, error)
Reads sandbox description from a given directory
type SandboxInfo ¶
func GetInstalledSandboxes ¶
func GetInstalledSandboxes(sandboxHome string) (installedSandboxes []SandboxInfo, err error)
Gets a list of installed sandboxes from the $SANDBOX_HOME directory
type SandboxUser ¶
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
The stack is implemented using a double-linked list from Go standard library
func (*Stack) Bottom ¶
func (stack *Stack) Bottom() interface{}
Bottom() returns the object stored as .Value in the bottom list element The object is NOT removed from the list
func (*Stack) Pop ¶
func (stack *Stack) Pop() interface{}
Pop() returns the object stored as .Value in the top list element Client calls will need to cast the object to the expected type. The object is removed from the list e.g.:
type MyType struct { ... } var lastOne MyType lastOne = stack.Pop().(MyType)