config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	APIPort = 8008
)

Functions

func DetectConfigFormat

func DetectConfigFormat(filepath string, data []byte) (common.FileType, error)

DetectConfigFormat picks YAML or JSON from the file extension, or by inspecting content.

func MarshalConfig

func MarshalConfig(conf *Config, format common.FileType) ([]byte, error)

MarshalConfig encodes config to YAML or JSON bytes.

func WriteConfig

func WriteConfig(filepath string, conf *Config) error

Types

type AuthenticationConfig

type AuthenticationConfig struct {
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
}

func DefaultAuthenticationConfig

func DefaultAuthenticationConfig() *AuthenticationConfig

type BackupConfig

type BackupConfig struct {
	// MUST: set in init
	SSHHost                 string `yaml:"ssh-host" json:"ssh-host"`
	SSHUser                 string `yaml:"ssh-user" json:"ssh-user"`
	SSHPasswd               string `yaml:"ssh-passwd" json:"ssh-passwd"`
	SSHPort                 int    `yaml:"ssh-port" json:"ssh-port"`
	BackupDir               string `yaml:"backupdir" json:"backupdir"`
	XtrabackupBinDir        string `yaml:"xtrabackup-bindir" json:"xtrabackup-bindir"`
	BackupIOPSLimits        int    `yaml:"backup-iops-limits" json:"backup-iops-limits"`
	UseMemory               string `yaml:"backup-use-memory" json:"backup-use-memory"`
	Parallel                int    `yaml:"backup-parallel" json:"backup-parallel"`
	MysqldMonitorInterval   int    `yaml:"mysqld-monitor-interval" json:"mysqld-monitor-interval"`
	MaxAllowedLocalTrxCount int    `yaml:"max-allowed-local-trx-count" json:"max-allowed-local-trx-count"`

	// mysql admin
	Admin string `yaml:"admin" json:"admin"`

	// mysql passwd
	Passwd string `yaml:"passwd" json:"passwd"`

	// mysql host
	Host string `yaml:"host" json:"host"`

	// mysql port
	Port int `yaml:"port" json:"port"`

	// mysql basedir
	Basedir string `yaml:"basedir" json:"basedir"`

	// mysql default file
	DefaultsFile string `yaml:"defaults-file" json:"defaults-file"`
}

func DefaultBackupConfig

func DefaultBackupConfig() *BackupConfig

type BootstrapConfig

type BootstrapConfig struct {
	BootstrapPostgresql *BootstrapPostgresqlConfig `yaml:"postgresql" json:"postgresql"`
	BootstrapMysql      *BootstrapMysqlConfig      `yaml:"mysql" json:"mysql"`
}

func DefaultBootstrapConfig

func DefaultBootstrapConfig() *BootstrapConfig

type BootstrapMysqlConfig

type BootstrapMysqlConfig struct {
}

func DefaultBootstrapMysqlConfig

func DefaultBootstrapMysqlConfig() *BootstrapMysqlConfig

type BootstrapPostgresqlConfig

type BootstrapPostgresqlConfig struct {
	DcsConf  *DcsConfig                       `yaml:"dcs" json:"dcs"`
	InitDB   *InitDBConfig                    `yaml:"initdb" json:"initdb"`
	PgHba    []string                         `yaml:"pg_hba" json:"pg_hba"`
	PostInit string                           `yaml:"post_init" json:"post_init"`
	Users    []BootstrapPostgresqlUsersConfig `yaml:"users" json:"users"`
}

func DefaultBootstrapPostgresqlConfig

func DefaultBootstrapPostgresqlConfig() *BootstrapPostgresqlConfig

type BootstrapPostgresqlUsersConfig

type BootstrapPostgresqlUsersConfig struct {
	Username string   `yaml:"username" json:"username"`
	Password string   `yaml:"password" json:"password"`
	Options  []string `yaml:"options" json:"options"`
}

type Config

type Config struct {
	Scope     string `yaml:"scope" json:"scope"`
	NameSpace string `yaml:"namespace" json:"namespace"`
	Name      string `yaml:"name" json:"name"`

	// connection string(format ip:port)
	Endpoint string `yaml:"endpoint" json:"endpoint"`

	// HTTP APIs address.
	PeerAddress string `yaml:"peer-address,omitempty" json:"peer-address,omitempty"`

	RestAPI      *RestAPIConfig      `yaml:"restapi" json:"restapi"`
	Ctl          *CtlConfig          `yaml:"ctl" json:"ctl"`
	Election     *ElectionConfig     `yaml:"election" json:"election"` // deprecated: use coordination
	Coordination *CoordinationConfig `yaml:"coordination" json:"coordination"`
	Bootstrap    *BootstrapConfig    `yaml:"bootstrap" json:"bootstrap"`
	Database     *DatabaseConfig     `yaml:"database" json:"database"`
	Watchdog     *WatchdogConfig     `yaml:"watchdog" json:"watchdog"`
	Tags         *TagsConfig         `yaml:"tags" json:"tags"`
	HA           *HAConfig           `yaml:"ha" json:"ha"`
	Log          *LogConfig          `yaml:"log" json:"log"`
}

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig(filepath string) (*Config, error)

func ParseConfig

func ParseConfig(data []byte, format common.FileType) (*Config, error)

ParseConfig unmarshals config bytes in YAML or JSON format onto defaults.

func (*Config) EffectiveCoordination added in v0.2.0

func (c *Config) EffectiveCoordination() *CoordinationConfig

EffectiveCoordination returns the active coordination settings (coordination.* or election.*).

func (*Config) EffectivePrimaryHooks added in v0.2.0

func (c *Config) EffectivePrimaryHooks() PrimaryHooksConfig

EffectivePrimaryHooks returns primary accessibility hooks, preferring ha.primary_hooks and falling back to legacy election.raft leader-start/stop-command.

func (*Config) Normalize added in v0.2.0

func (c *Config) Normalize() error

Normalize merges coordination and election blocks and fills defaults after parse.

func (*Config) Validate added in v0.2.0

func (c *Config) Validate() error

Validate checks semantic constraints. See docs/config-design.md.

type CoordinationConfig added in v0.2.0

type CoordinationConfig struct {
	Provider string      `yaml:"provider" json:"provider"`
	Raft     *RaftConfig `yaml:"raft" json:"raft"`
	Etcd     *EtcdConfig `yaml:"etcd" json:"etcd"`
}

CoordinationConfig is the target name for election/coordination settings. Prefer this block in new configs; election is kept as a deprecated alias.

func DefaultCoordinationConfig added in v0.2.0

func DefaultCoordinationConfig() *CoordinationConfig

type CtlConfig

type CtlConfig struct {
	Insecure bool   `yaml:"insecure" json:"insecure"`
	Certfile string `yaml:"certfile" json:"certfile"`
	Cacert   string `yaml:"cacert" json:"cacert"`
}

func DefaultCtlConfig

func DefaultCtlConfig() *CtlConfig

type DatabaseConfig

type DatabaseConfig struct {
	Type       string            `yaml:"type" json:"type"`
	Postgresql *PostgresqlConfig `yaml:"postgresql" json:"postgresql"`
	Mysql      *MysqlConfig      `yaml:"mysql" json:"mysql"`
}

func DefaultDatabaseConfig

func DefaultDatabaseConfig() *DatabaseConfig

type DcsConfig

type DcsConfig struct {
	TTL                  int                   `yaml:"ttl" json:"ttl"`
	LoopWait             int                   `yaml:"loop_wait" json:"loop_wait"`
	RetryTimeout         int                   `yaml:"retry_timeout" json:"retry_timeout"`
	MaximumLagOnFailover int                   `yaml:"maximum_lag_on_failover" json:"maximum_lag_on_failover"`
	MasterStartTimeout   int                   `yaml:"master_start_timeout" json:"master_start_timeout"`
	SynchronousMode      bool                  `yaml:"synchronous_mode" json:"synchronous_mode"`
	StandbyCluster       *StandbyClusterConfig `yaml:"standby_cluster" json:"standby_cluster"`
	UsePGRewind          bool                  `yaml:"use_pg_rewind" json:"use_pg_rewind"`
	UseSlots             bool                  `yaml:"use_slots" json:"use_slots"`
	Parameters           map[string]string     `yaml:"parameters" json:"parameters"`
	/*
	   wal_level: hot_standby
	   hot_standby: "on"
	   max_connections: 100
	   max_worker_processes: 8
	   wal_keep_segments: 8
	   max_wal_senders: 10
	   max_replication_slots: 10
	   max_prepared_transactions: 0
	   max_locks_per_transaction: 64
	   wal_log_hints: "on"
	   track_commit_timestamp: "off"
	   archive_mode: "on"
	   archive_timeout: 1800s
	   archive_command: mkdir -p ../wal_archive && test ! -f ../wal_archive/%f && cp %p ../wal_archive/%f
	*/
	RecoveryConf *RecoveryConfConfig `yaml:"recovery_conf" json:"recovery_conf"`
}

func DefaultDcsConfig

func DefaultDcsConfig() *DcsConfig

type ElectionConfig

type ElectionConfig struct {
	Algo string      `yaml:"algorithm" json:"algorithm"`
	Raft *RaftConfig `yaml:"raft" json:"raft"`
	Etcd *EtcdConfig `yaml:"etcd" json:"etcd"`
}

func DefaultElectionConfig

func DefaultElectionConfig() *ElectionConfig

type EtcdConfig

type EtcdConfig struct {
	Host       string   `yaml:"host" json:"host"`
	Hosts      []string `yaml:"hosts" json:"hosts"`
	UseProxies bool     `yaml:"use_proxies" json:"use_proxies"`
	// TTL is the DCS leader lease TTL in seconds (Patroni-style).
	TTL int `yaml:"ttl" json:"ttl"`
	// LoopWait is the DCS reconcile loop interval in seconds (Patroni-style).
	LoopWait int `yaml:"loop_wait" json:"loop_wait"`
	// RetryTimeout is the DCS operation retry window in seconds (Patroni-style).
	RetryTimeout int `yaml:"retry_timeout" json:"retry_timeout"`
}

func DefaultEtcdConfig

func DefaultEtcdConfig() *EtcdConfig

type HAConfig added in v0.2.0

type HAConfig struct {
	// ReconcileInterval is seconds between reconcile ticks; 0 uses ha.DefaultReconcileInterval.
	ReconcileInterval int `yaml:"reconcile_interval" json:"reconcile_interval"`
	// DelegateDBApply lets Reconciler own demote and promotion (semi-sync + MGR).
	DelegateDBApply bool `yaml:"delegate_db_apply" json:"delegate_db_apply"`
	// PrimaryHooks run when this node becomes/stops serving as the writable primary (VIP, LB, …).
	PrimaryHooks *PrimaryHooksConfig `yaml:"primary_hooks" json:"primary_hooks"`
}

HAConfig controls the L3 reconcile loop (see internal/ha, docs/architecture.md).

func DefaultHAConfig added in v0.2.0

func DefaultHAConfig() *HAConfig

type InitDBConfig

type InitDBConfig struct {
	Encoding      string `yaml:"encoding" json:"encoding"`
	DataChecksums bool   `yaml:"data_checksums,omitempty" json:"data_checksums,omitempty"`
}

func DefaultInitDBConfig

func DefaultInitDBConfig() *InitDBConfig

type LogConfig

type LogConfig struct {
	Level string `yaml:"level" json:"level"`
}

func DefaultLogConfig

func DefaultLogConfig() *LogConfig

type MysqlConfig

type MysqlConfig struct {
	// mysql admin user
	Admin string `yaml:"admin" json:"admin"`

	// mysql admin passwd
	Passwd string `yaml:"passwd" json:"passwd"`

	// mysql localhost
	Host string `yaml:"host" json:"host"`

	// mysql local port
	Port int `yaml:"port" json:"port"`

	// mysql basedir
	Basedir string `yaml:"basedir" json:"basedir"`

	// mysql version
	Version string `yaml:"version" json:"version"`

	// mysql default file path
	DefaultsFile string `yaml:"defaults-file" json:"defaults-file"`

	// replication mode, semi-sync or group-replication
	ReplMode model.MysqlReplMode `yaml:"replication-mode" json:"replication-mode"`

	// ping mysql interval(ms)
	PingTimeout int `yaml:"ping-timeout" json:"ping-timeout"`

	// admit defeat count for ping mysql
	AdmitDefeatPingCnt int `yaml:"admit-defeat-ping-count" json:"admit-defeat-ping-count"`

	// max-open-conns limits NeoHA admin connections to MySQL (0 = default 2).
	MaxOpenConns int `yaml:"max-open-conns" json:"max-open-conns"`

	// max-idle-conns keeps idle admin connections in the pool (0 = same as max-open-conns).
	MaxIdleConns int `yaml:"max-idle-conns" json:"max-idle-conns"`

	// When true, MysqlDead caused by Error 1040 triggers automatic leader failover.
	FailoverOnTooManyConnections bool `yaml:"failover-on-too-many-connections" json:"failover-on-too-many-connections"`

	// rpl_semi_sync_master_timeout for 2 nodes
	SemiSyncTimeoutForTwoNodes uint64 `yaml:"semi-sync-timeout-for-two-nodes" json:"semi-sync-timeout-for-two-nodes"`

	// master system variables configure(separated by ;)
	MasterSysVars string `yaml:"master-sysvars" json:"master-sysvars"`

	// slave system variables configure(separated by ;)
	SlaveSysVars string `yaml:"slave-sysvars" json:"slave-sysvars"`

	// If true, the mysql monitor will disabled, default is false.
	MonitorDisabled bool `yaml:"monitor-disabled" json:"monitor-disabled"`

	// mysql intranet ip, other replicas Master_Host
	ReplHost string `yaml:"repl-host" json:"repl-host"`

	// mysql replication user
	ReplUser string `yaml:"repl-user" json:"repl-user"`

	// mysql replication user pwd
	ReplPasswd string `yaml:"repl-passwd" json:"repl-passwd"`

	// replication Gtid Purged
	ReplGtidPurged string `yaml:"repl-gtid-purged" json:"repl-gtid-purged"`

	Backup *BackupConfig `yaml:"backup" json:"backup"`
}

func DefaultMysqlConfig

func DefaultMysqlConfig() *MysqlConfig

type PGAuthConfig

type PGAuthConfig struct {
	Repl      *PGAuthReplConfig      `yaml:"replication" json:"replication"`
	SuperUser *PGAuthSuperUserConfig `yaml:"superuser" json:"superuser"`
	Rewind    *PGAuthRewindConfig    `yaml:"rewind" json:"rewind"`
}

func DefaultPGAuthConfig

func DefaultPGAuthConfig() *PGAuthConfig

type PGAuthReplConfig

type PGAuthReplConfig struct {
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
}

func DefaultPGAuthReplConfig

func DefaultPGAuthReplConfig() *PGAuthReplConfig

type PGAuthRewindConfig

type PGAuthRewindConfig struct {
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
}

func DefaultPGAuthRewindConfig

func DefaultPGAuthRewindConfig() *PGAuthRewindConfig

type PGAuthSuperUserConfig

type PGAuthSuperUserConfig struct {
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
}

func DefaultPGAuthSuperUserConfig

func DefaultPGAuthSuperUserConfig() *PGAuthSuperUserConfig

type PostgresqlConfig

type PostgresqlConfig struct {
	Version        string            `yaml:"version" json:"version"`
	Listen         string            `yaml:"listen" json:"listen"`
	ConnectAddress string            `yaml:"connect_address" json:"connect_address"`
	DataDir        string            `yaml:"data_dir" json:"data_dir"`
	BinDir         string            `yaml:"bin_dir" json:"bin_dir"`
	ConfigDir      string            `yaml:"config_dir" json:"config_dir"`
	PGPass         string            `yaml:"pgpass" json:"pgpass"`
	Auth           *PGAuthConfig     `yaml:"authentication" json:"authentication"`
	Krbsrvname     string            `yaml:"krbsrvname" json:"krbsrvname"`
	Parameters     map[string]string `yaml:"parameters" json:"parameters"`
	PrePromote     string            `yaml:"pre_promote" json:"pre_promote"`
	// UseSlots enables primary_slot_name in recovery settings.
	UseSlots bool `yaml:"use_slots" json:"use_slots"`
	// PrimarySlotName is the physical replication slot on the primary for this replica.
	PrimarySlotName string `yaml:"primary_slot_name" json:"primary_slot_name"`
	// MaximumLagOnFailover max replay lag in bytes before promote is allowed (0 = no limit).
	MaximumLagOnFailover int64 `yaml:"maximum_lag_on_failover" json:"maximum_lag_on_failover"`
	// UsePGRewind runs pg_rewind when rejoining as replica after timeline fork (requires data_dir + bin_dir).
	UsePGRewind bool `yaml:"use_pg_rewind" json:"use_pg_rewind"`
	// SynchronousMode requires a synchronous replica before commits (exact semantics TBD).
	SynchronousMode bool `yaml:"synchronous_mode" json:"synchronous_mode"`
	// SynchronousModeStrict enforces synchronous_mode even when no sync replica is available (TBD).
	SynchronousModeStrict bool `yaml:"synchronous_mode_strict" json:"synchronous_mode_strict"`
}

func DefaultPostgresqlConfig

func DefaultPostgresqlConfig() *PostgresqlConfig

type PrimaryHooksConfig added in v0.2.0

type PrimaryHooksConfig struct {
	OnPrimaryStart string `yaml:"on_primary_start" json:"on_primary_start"`
	OnPrimaryStop  string `yaml:"on_primary_stop" json:"on_primary_stop"`
}

PrimaryHooksConfig configures shell hooks after the DB is promoted/demoted. Prefer this over election.raft leader-start/stop-command (legacy alias).

func DefaultPrimaryHooksConfig added in v0.2.0

func DefaultPrimaryHooksConfig() *PrimaryHooksConfig

type RaftConfig

type RaftConfig struct {
	// raft meta datadir
	MetaDatadir string `yaml:"meta-datadir" json:"meta-datadir"`

	// leader heartbeat interval(ms)
	HeartbeatTimeout int `yaml:"heartbeat-timeout" json:"heartbeat-timeout"`

	// admit defeat count for hearbeat
	AdmitDefeatHtCnt int `yaml:"admit-defeat-hearbeat-count" json:"admit-defeat-hearbeat-count"`

	// election timeout(ms)
	ElectionTimeout int `yaml:"election-timeout" json:"election-timeout"`

	// purge binlog interval (ms)
	PurgeBinlogInterval int `yaml:"purge-binlog-interval" json:"purge-binlog-interval"`

	// Super IDLE can't change to FOLLOWER.
	SuperIDLE bool `yaml:"super-idle" json:"super-idle"`

	// MUST: set in init
	// the shell command when leader start
	LeaderStartCommand string `yaml:"leader-start-command" json:"leader-start-command"`

	// MUST: set in init
	// the shell command when leader stop
	LeaderStopCommand string `yaml:"leader-stop-command" json:"leader-stop-command"`

	// if true, neoha binlog-purge will be skipped, default is false.
	PurgeBinlogDisabled bool `yaml:"purge-binlog-disabled" json:"purge-binlog-disabled"`

	// rpc client request tiemout(ms)
	RequestTimeout int `yaml:"requesttimeout" json:"requesttimeout"`

	// candicate wait timeout(ms) for 2 nodes.
	CandidateWaitFor2Nodes int `yaml:"candidate-wait-for-2nodes" json:"candidate-wait-for-2nodes"`
}

func DefaultRaftConfig

func DefaultRaftConfig() *RaftConfig

type RecoveryConfConfig

type RecoveryConfConfig struct {
	RestoreCommand string `yaml:"restore_command" json:"restore_command"`
}

func DefaultRecoveryConfConfig

func DefaultRecoveryConfConfig() *RecoveryConfConfig

type RestAPIConfig

type RestAPIConfig struct {
	EnableAPIs     bool                  `yaml:"enable-apis" json:"enable-apis"`         // true or fase
	Listen         string                `yaml:"listen" json:"listen"`                   // ip:port
	ConnectAddress string                `yaml:"connect_address" json:"connect_address"` // ip:port
	Certfile       string                `yaml:"certfile" json:"certfile"`
	Keyfile        string                `yaml:"keyfile" json:"keyfile"`
	Authentication *AuthenticationConfig `yaml:"authentication" json:"authentication"`
}

func DefaultRestAPIConfig

func DefaultRestAPIConfig() *RestAPIConfig

type StandbyClusterConfig

type StandbyClusterConfig struct {
	Host            string `yaml:"host" json:"host"`
	Port            int    `yaml:"port" json:"port"`
	PrimarySlotName string `yaml:"primary_slot_name" json:"primary_slot_name"`
}

func DefaultStandbyClusterConfig

func DefaultStandbyClusterConfig() *StandbyClusterConfig

type TagsConfig

type TagsConfig struct {
	Nofailover    bool `yaml:"nofailover" json:"nofailover"`
	Noloadbalance bool `yaml:"noloadbalance" json:"noloadbalance"`
	Clonefrom     bool `yaml:"clonefrom" json:"clonefrom"`
	Nosync        bool `yaml:"nosync" json:"nosync"`
}

func DefaultTagsConfig

func DefaultTagsConfig() *TagsConfig

type WatchdogConfig

type WatchdogConfig struct {
	Mode         string `yaml:"mode" json:"mode"`
	Device       string `yaml:"device" json:"device"`
	SafetyMargin int    `yaml:"safety_margin" json:"safety_margin"`
}

func DefaultWatchdogConfig

func DefaultWatchdogConfig() *WatchdogConfig

Jump to

Keyboard shortcuts

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