config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppName = "redisGunYu"

	RedisRoleMasterStr = "master"
	RedisRoleSlaveStr  = "slave"
	RedisRoleAllStr    = "all"

	TypeDecode  = "decode"
	TypeRestore = "restore"
	TypeDump    = "dump"
	TypeSync    = "sync"
	TypeRump    = "rump"

	CheckpointKey        = "redis-gunyu-checkpoint"
	CheckpointKeyHashKey = "redis-gunyu-checkpoint-hash"
)

Variables

View Source
var (
	StartTime   string
	Version     = "1"
	RDBPipeSize = 1024
)
View Source
var (
	ErrInvalidConfig = errors.New("invalid configuration")
)

Functions

func FlagsParseToStruct added in v0.1.3

func FlagsParseToStruct(prefix string, obj interface{})

func FlagsSetToStruct added in v0.1.3

func FlagsSetToStruct(obj interface{})

func GetAddressesFromRedisConfigSlice

func GetAddressesFromRedisConfigSlice(rcfg []RedisConfig) []string

func GetLogLevel

func GetLogLevel() zapcore.Level

func InitConfig

func InitConfig(path string) error

func LoadFlags

func LoadFlags() error

func LogModuleName

func LogModuleName(prefix string) string

func SetLogLevel

func SetLogLevel(l zapcore.Level)

Types

type AofCmdFlags

type AofCmdFlags struct {
	Action string
	Path   string
	Offset int64
	Size   int64
}

type ChannelConfig

type ChannelConfig struct {
	Storer                  *StorerConfig
	VerifyCrc               bool
	StaleCheckpointDuration time.Duration `yaml:"staleCheckpointDuration"`
}

func (*ChannelConfig) Clone

func (cc *ChannelConfig) Clone() *ChannelConfig

type ClusterConfig

type ClusterConfig struct {
	GroupName          string        `yaml:"groupName"`
	MetaEtcd           *EtcdConfig   `yaml:"metaEtcd"`
	LeaseTimeout       time.Duration `yaml:"leaseTimeout"`
	LeaseRenewInterval time.Duration `yaml:"leaseRenewInterval"`
}

type Config

type Config struct {
	Input   *InputConfig
	Output  *OutputConfig
	Channel *ChannelConfig
	Filter  FilterConfig
	Cluster *ClusterConfig
	Log     *LogConfig   `yaml:"log"`
	Server  ServerConfig `yaml:"server"`
}

func Get

func Get() *Config

func (*Config) GetLog

func (c *Config) GetLog() *LogConfig

type DiffCmdFlags

type DiffCmdFlags struct {
	DiffMode string
	A        string
	B        string
	Parallel int
}

type EtcdConfig

type EtcdConfig struct {
	// Endpoints is a list of URLs.
	Endpoints SliceString `yaml:"endpoints"`

	// AutoSyncInterval is the interval to update endpoints with its latest members.
	// 0 disables auto-sync. By default auto-sync is disabled.
	AutoSyncInterval time.Duration `json:"auto-sync-interval"`

	// DialTimeout is the timeout for failing to establish a connection.
	DialTimeout time.Duration `json:"dial-timeout"`

	// DialKeepAliveTime is the time after which client pings the server to see if
	// transport is alive.
	DialKeepAliveTime time.Duration `json:"dial-keep-alive-time"`

	// DialKeepAliveTimeout is the time that the client waits for a response for the
	// keep-alive probe. If the response is not received in this time, the connection is closed.
	DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"`

	// Username is a user name for authentication.
	Username string `json:"username"`

	// Password is a password for authentication.
	Password string `json:"password"`

	// RejectOldCluster when set will refuse to create a client against an outdated cluster.
	RejectOldCluster bool `json:"reject-old-cluster"`

	Ttl int
}

type FilterConfig

type FilterConfig struct {
	DbBlacklist  SliceInt         `yaml:"dbBlacklist"`
	CmdBlacklist SliceString      `yaml:"commandBlacklist"`
	KeyFilter    *FilterKeyConfig `yaml:"keyFilter"`
}

type FilterKeyConfig

type FilterKeyConfig struct {
	PrefixKeyWhitelist SliceString `yaml:"prefixKeyWhitelist"`
	PrefixKeyBlacklist SliceString `yaml:"prefixKeyBlacklist"`
}

type FlagParser added in v0.1.3

type FlagParser interface {
	FlagParse(prefix string)
	FlagSet()
}

type Flags

type Flags struct {
	ConfigPath string
	Cmd        string
	RdbCmd     RdbCmdFlags
	DiffCmd    DiffCmdFlags
	AofCmd     AofCmdFlags
}

func GetFlag

func GetFlag() *Flags

type FlushPolicy

type FlushPolicy struct {
	Duration   time.Duration
	EveryWrite bool
	DirtySize  int64
	Auto       bool
}

type InputConfig

type InputConfig struct {
	Redis       *RedisConfig
	RdbParallel int `yaml:"rdbParallel"`

	Mode             InputMode       `yaml:"mode"`
	SyncFrom         SelNodeStrategy `yaml:"syncFrom"`
	SyncDelayTestKey string          `yaml:"syncDelayTestKey"`
	// contains filtered or unexported fields
}

func (*InputConfig) RdbLimiter

func (ic *InputConfig) RdbLimiter() chan struct{}

type InputMode

type InputMode int
const (
	InputModeDynamic InputMode = 0
	InputModeStatic  InputMode = 1
	InputModeAuto    InputMode = 3
)

func (*InputMode) Set added in v0.1.3

func (rt *InputMode) Set(val string) error

func (InputMode) String

func (rt InputMode) String() string

func (*InputMode) UnmarshalYAML

func (rt *InputMode) UnmarshalYAML(value *yaml.Node) error

type LogConfig

type LogConfig struct {
	LevelStr string `yaml:"level"`

	StacktraceLevelStr string `yaml:"StacktraceLevel"`

	Handler    LogHandlerConfig `yaml:"handler"`
	Caller     *bool            `yaml:"withCaller" default:"true"`
	Func       *bool            `yaml:"withFunc"`
	ModuleName *bool            `yaml:"withModuleName" default:"true"`
	// contains filtered or unexported fields
}

type LogHandlerConfig

type LogHandlerConfig struct {
	File   *LogHandlerFileConfig
	StdOut bool `yaml:"stdout"`
}

type LogHandlerFileConfig

type LogHandlerFileConfig struct {
	FileName   string `yaml:"fileName"`
	MaxSize    int    `yaml:"maxSize"` // unit is megabyte
	MaxBackups int    `yaml:"maxBackups"`
	MaxAge     int    `yaml:"maxAge"`
}

type OutputConfig

type OutputConfig struct {
	Redis                  *RedisConfig
	ResumeFromBreakPoint   *bool         `yaml:"resumeFromBreakPoint" default:"true"`
	ReplaceHashTag         bool          `yaml:"replaceHashTag"`
	KeyExists              string        `yaml:"keyExists"` // replace|ignore|error
	KeyExistsLog           bool          `yaml:"keyExistsLog"`
	FunctionExists         string        `yaml:"functionExists"`
	MaxProtoBulkLen        int           `yaml:"maxProtoBulkLen"` // proto-max-bulk-len, default value of redis is 512MiB
	TargetDbCfg            *int          `yaml:"targetDb" default:"-1"`
	TargetDb               int           `yaml:"-"`
	TargetDbMap            map[int]int   `yaml:"targetDbMap"`
	BatchCmdCount          uint          `yaml:"batchCmdCount"`
	BatchTicker            time.Duration `yaml:"batchTicker"`
	BatchBufferSize        uint64        `yaml:"batchBufferSize"`
	KeepaliveTicker        time.Duration `yaml:"keepaliveTicker"`
	ReplayRdbParallel      int           `yaml:"replayRdbParallel"`
	ReplayRdbEnableRestore *bool         `yaml:"replayRdbEnableRestore" default:"true"`
	UpdateCheckpointTicker time.Duration `yaml:"updateCheckpointTicker"`
	ReplayTransaction      *bool         `yaml:"replayTransaction" default:"true"`
	Stats                  OutputStats   `yaml:"stats"`
}

type OutputStats added in v0.1.5

type OutputStats struct {
	DisableLog  bool          `yaml:"disableLog"`
	LogInterval time.Duration `yaml:"logInterval"`
}

type RdbCmdFlags

type RdbCmdFlags struct {
	RdbAction string
	RdbPath   string
	ToCmd     bool
}

type RedisClusterOptions

type RedisClusterOptions struct {
	HandleMoveErr bool `yaml:"handleMoveErr" default:"true"`
	HandleAskErr  bool `yaml:"handleAskErr" default:"true"`
}

func (*RedisClusterOptions) Clone

type RedisClusterShard

type RedisClusterShard struct {
	Slots  RedisSlots // sorted
	Master RedisNode
	Slaves []RedisNode
	// contains filtered or unexported fields
}

func (*RedisClusterShard) AllAddresses

func (rcs *RedisClusterShard) AllAddresses() []string

func (*RedisClusterShard) Clone

func (rcs *RedisClusterShard) Clone() *RedisClusterShard

func (*RedisClusterShard) CompareTypology

func (rcs *RedisClusterShard) CompareTypology(shard *RedisClusterShard) bool

func (*RedisClusterShard) Get

type RedisConfig

type RedisConfig struct {
	Addresses SliceString

	UserName  string    `yaml:"userName"`
	Password  string    `yaml:"password"`
	TlsEnable bool      `yaml:"tlsEnable"`
	Type      RedisType // for new redis client
	Otype     RedisType // original type
	Version   string

	ClusterOptions *RedisClusterOptions `yaml:"clusterOptions"`

	KeepAlive int           `yaml:"keepAlive"` // Maximum keep alive connecion in each node
	AliveTime time.Duration `yaml:"aliveTime"` // Keep alive timeout
	// contains filtered or unexported fields
}

func (*RedisConfig) Address

func (rc *RedisConfig) Address() string

func (*RedisConfig) Clone

func (rc *RedisConfig) Clone() *RedisConfig

func (*RedisConfig) FindNode

func (rc *RedisConfig) FindNode(addr string) *RedisNode

func (*RedisConfig) GetAllSlots

func (rc *RedisConfig) GetAllSlots() *RedisSlots

func (*RedisConfig) GetClusterOptions

func (rc *RedisConfig) GetClusterOptions() *RedisClusterOptions

func (*RedisConfig) GetClusterShard

func (rc *RedisConfig) GetClusterShard(addr string) *RedisClusterShard

func (*RedisConfig) GetClusterShards

func (rc *RedisConfig) GetClusterShards() []*RedisClusterShard

func (*RedisConfig) GetSlots

func (rc *RedisConfig) GetSlots(address string) *RedisSlots

func (*RedisConfig) Index

func (rc *RedisConfig) Index(i int) RedisConfig

func (*RedisConfig) IsCluster

func (rc *RedisConfig) IsCluster() bool

func (*RedisConfig) IsMigrating

func (rc *RedisConfig) IsMigrating() bool

func (*RedisConfig) IsStanalone

func (rc *RedisConfig) IsStanalone() bool

func (*RedisConfig) SelNodeByAddress

func (rc *RedisConfig) SelNodeByAddress(addr string) *RedisConfig

func (*RedisConfig) SelNodes

func (rc *RedisConfig) SelNodes(selAllShards bool, sel SelNodeStrategy) []RedisConfig

func (*RedisConfig) SetClusterShards

func (rc *RedisConfig) SetClusterShards(sds []*RedisClusterShard)

func (*RedisConfig) SetMigrating

func (rc *RedisConfig) SetMigrating(m bool)

func (*RedisConfig) SetSlots

func (rc *RedisConfig) SetSlots(slots map[string]*RedisSlots, sortedSlots *RedisSlots)

type RedisNode

type RedisNode struct {
	Id         string
	Ip         string
	Port       int
	TlsPort    int
	Endpoint   string
	Address    string
	HostName   string
	Role       RedisRole
	ReplOffset int64
	Health     string
}

func (*RedisNode) AddressEqual

func (rn *RedisNode) AddressEqual(b *RedisNode) bool

func (*RedisNode) IsHealth

func (rn *RedisNode) IsHealth() bool

type RedisRole

type RedisRole int
const (
	RedisRoleAll    RedisRole = 1
	RedisRoleMaster RedisRole = 2
	RedisRoleSlave  RedisRole = 4
)

func (*RedisRole) Parse

func (rr *RedisRole) Parse(str string)

func (RedisRole) String

func (m RedisRole) String() string

func (*RedisRole) UnmarshalYAML

func (m *RedisRole) UnmarshalYAML(value *yaml.Node) error

type RedisSlotRange

type RedisSlotRange struct {
	Left  int
	Right int
}

type RedisSlots

type RedisSlots struct {
	Ranges []RedisSlotRange
}

func (*RedisSlots) Clone

func (rs *RedisSlots) Clone() *RedisSlots

func (*RedisSlots) Equal

func (rs *RedisSlots) Equal(b *RedisSlots) bool

func (*RedisSlots) Len

func (rs *RedisSlots) Len() int

func (*RedisSlots) Less

func (rs *RedisSlots) Less(i, j int) bool

func (*RedisSlots) Swap

func (rs *RedisSlots) Swap(i, j int)

type RedisType

type RedisType int
const (
	RedisTypeUnknown    RedisType = 0
	RedisTypeStandalone RedisType = 1
	RedisTypeSentinel   RedisType = 2
	RedisTypeCluster    RedisType = 3
)

func (*RedisType) Set added in v0.1.3

func (rt *RedisType) Set(val string) error

func (RedisType) String

func (rt RedisType) String() string

func (*RedisType) UnmarshalYAML

func (rt *RedisType) UnmarshalYAML(value *yaml.Node) error

type SelNodeStrategy

type SelNodeStrategy int
const (
	SelNodeStrategySlave       SelNodeStrategy = 1 // 0001
	SelNodeStrategyPreferSlave SelNodeStrategy = 3 // 0011
	SelNodeStrategyMaster      SelNodeStrategy = 4 // 0100
)

func (*SelNodeStrategy) Set added in v0.1.3

func (rt *SelNodeStrategy) Set(val string) error

func (SelNodeStrategy) String

func (rt SelNodeStrategy) String() string

func (*SelNodeStrategy) UnmarshalYAML

func (rt *SelNodeStrategy) UnmarshalYAML(value *yaml.Node) error

type ServerConfig

type ServerConfig struct {
	Listen          string
	ListenPort      int    `yaml:"-"`
	ListenPeer      string `yaml:"listenPeer"` // Used to communicate with peers. if it's empty, use Listen field
	MetricRoutePath string `yaml:"metricRoutePath"`

	CheckRedisTypologyTicker time.Duration `yaml:"checkRedisTypologyTicker"` // seconds
	GracefullStopTimeout     time.Duration `yaml:"gracefullStopTimeout"`
}

type SliceInt added in v0.1.3

type SliceInt []int

func (*SliceInt) Set added in v0.1.3

func (ss *SliceInt) Set(val string) error

for flag

func (*SliceInt) String added in v0.1.3

func (ss *SliceInt) String() string

for flag

func (*SliceInt) UnmarshalYAML added in v0.1.3

func (ss *SliceInt) UnmarshalYAML(value *yaml.Node) error

type SliceString added in v0.1.3

type SliceString []string

func (*SliceString) Set added in v0.1.3

func (ss *SliceString) Set(val string) error

for flag

func (*SliceString) String added in v0.1.3

func (ss *SliceString) String() string

for flag

func (*SliceString) UnmarshalYAML added in v0.1.3

func (ss *SliceString) UnmarshalYAML(value *yaml.Node) error

type StorerConfig

type StorerConfig struct {
	DirPath string      `yaml:"dirPath"`
	MaxSize int64       `yaml:"maxSize"` // -1 is unlimited, default is 50GiB
	LogSize int64       `yaml:"logSize"` // default is 100MiB
	Flush   FlushPolicy `yaml:"flushPolicy"`
}

Jump to

Keyboard shortcuts

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