github.com/greenplum-db/gpbackup@v0.0.0-20240517212602-89daab1885b3/restore/global_variables.go (about) 1 package restore 2 3 import ( 4 "sync" 5 6 "github.com/greenplum-db/gp-common-go-libs/cluster" 7 "github.com/greenplum-db/gp-common-go-libs/dbconn" 8 "github.com/greenplum-db/gpbackup/filepath" 9 "github.com/greenplum-db/gpbackup/history" 10 "github.com/greenplum-db/gpbackup/options" 11 "github.com/greenplum-db/gpbackup/toc" 12 "github.com/greenplum-db/gpbackup/utils" 13 "github.com/spf13/pflag" 14 ) 15 16 /* 17 * Empty struct type used for value with 0 bytes 18 */ 19 type Empty struct{} 20 21 /* 22 * This file contains global variables and setter functions for those variables 23 * used in testing. 24 */ 25 26 /* 27 * Non-flag variables 28 */ 29 30 var ( 31 backupConfig *history.BackupConfig 32 connectionPool *dbconn.DBConn 33 globalCluster *cluster.Cluster 34 globalFPInfo filepath.FilePathInfo 35 globalTOC *toc.TOC 36 pluginConfig *utils.PluginConfig 37 restoreStartTime string 38 version string 39 wasTerminated bool 40 errorTablesMetadata map[string]Empty 41 errorTablesData map[string]Empty 42 opts *options.Options 43 /* 44 * Used for synchronizing DoCleanup. In DoInit() we increment the group 45 * and then wait for at least one DoCleanup to finish, either in DoTeardown 46 * or the signal handler. 47 */ 48 CleanupGroup *sync.WaitGroup 49 ) 50 51 func init() { 52 // Initialize global variables 53 errorTablesMetadata = make(map[string]Empty) 54 errorTablesData = make(map[string]Empty) 55 } 56 57 /* 58 * Command-line flags 59 */ 60 var cmdFlags *pflag.FlagSet 61 62 /* 63 * Setter functions 64 */ 65 66 func SetCmdFlags(flagSet *pflag.FlagSet) { 67 cmdFlags = flagSet 68 options.SetRestoreFlagDefaults(cmdFlags) 69 } 70 71 func SetBackupConfig(config *history.BackupConfig) { 72 backupConfig = config 73 } 74 75 func SetConnection(conn *dbconn.DBConn) { 76 connectionPool = conn 77 } 78 79 func SetCluster(cluster *cluster.Cluster) { 80 globalCluster = cluster 81 } 82 83 func SetFPInfo(fpInfo filepath.FilePathInfo) { 84 globalFPInfo = fpInfo 85 } 86 87 func SetPluginConfig(config *utils.PluginConfig) { 88 pluginConfig = config 89 } 90 91 func SetTOC(objToc *toc.TOC) { 92 globalTOC = objToc 93 } 94 95 // Util functions to enable ease of access to global flag values 96 97 func FlagChanged(flagName string) bool { 98 return cmdFlags.Changed(flagName) 99 } 100 101 func MustGetFlagString(flagName string) string { 102 return options.MustGetFlagString(cmdFlags, flagName) 103 } 104 105 func MustGetFlagInt(flagName string) int { 106 return options.MustGetFlagInt(cmdFlags, flagName) 107 } 108 109 func MustGetFlagBool(flagName string) bool { 110 return options.MustGetFlagBool(cmdFlags, flagName) 111 } 112 113 func MustGetFlagStringSlice(flagName string) []string { 114 return options.MustGetFlagStringSlice(cmdFlags, flagName) 115 } 116 117 func MustGetFlagStringArray(flagName string) []string { 118 return options.MustGetFlagStringArray(cmdFlags, flagName) 119 } 120 121 func GetVersion() string { 122 return version 123 } 124 125 func SetVersion(v string) { 126 version = v 127 }