cluster

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultProxyCheckInterval = 5 * time.Second

	DefaultSleepInterval                         = 5 * time.Second
	DefaultRequestTimeout                        = 10 * time.Second
	DefaultConvergenceTimeout                    = 30 * time.Second
	DefaultInitTimeout                           = 5 * time.Minute
	DefaultSyncTimeout                           = 30 * time.Minute
	DefaultFailInterval                          = 20 * time.Second
	DefaultDeadKeeperRemovalInterval             = 48 * time.Hour
	DefaultMaxStandbys               uint16      = 20
	DefaultMaxStandbysPerSender      uint16      = 3
	DefaultMaxStandbyLag                         = 1024 * 1204
	DefaultSynchronousReplication                = false
	DefaultMaxSynchronousStandbys    uint16      = 1
	DefaultMinSynchronousStandbys    uint16      = 1
	DefaultUsePgrewind                           = false
	DefaultMergePGParameter                      = true
	DefaultRole                      ClusterRole = ClusterRoleMaster
)
View Source
const (
	NoGeneration      int64 = 0
	InitialGeneration int64 = 1
)
View Source
const (
	CurrentCDFormatVersion uint64 = 1
)

Variables

This section is empty.

Functions

func BoolP

func BoolP(b bool) *bool

func Uint16P added in v0.5.0

func Uint16P(u uint16) *uint16

func Uint32P added in v0.6.0

func Uint32P(u uint32) *uint32

Types

type ArchiveRecoverySettings added in v0.5.0

type ArchiveRecoverySettings struct {
	// value for restore_command
	RestoreCommand string `json:"restoreCommand,omitempty"`
}

ArchiveRecoverySettings defines the archive recovery settings in the recovery.conf file (https://www.postgresql.org/docs/9.6/static/archive-recovery-settings.html )

type Cluster added in v0.5.0

type Cluster struct {
	UID        string    `json:"uid,omitempty"`
	Generation int64     `json:"generation,omitempty"`
	ChangeTime time.Time `json:"changeTime,omitempty"`

	Spec *ClusterSpec `json:"spec,omitempty"`

	Status ClusterStatus `json:"status,omitempty"`
}

func NewCluster added in v0.5.0

func NewCluster(uid string, cs *ClusterSpec) *Cluster

func (*Cluster) DeepCopy added in v0.5.0

func (c *Cluster) DeepCopy() *Cluster

func (*Cluster) DefSpec added in v0.5.0

func (c *Cluster) DefSpec() *ClusterSpec

DefSpec returns a new ClusterSpec with unspecified values populated with their defaults

func (*Cluster) UpdateSpec added in v0.5.0

func (c *Cluster) UpdateSpec(ns *ClusterSpec) error

type ClusterData

type ClusterData struct {
	// ClusterData format version. Used to detect incompatible
	// version and do upgrade. Needs to be bumped when a non
	// backward compatible change is done to the other struct
	// members.
	FormatVersion uint64
	Cluster       *Cluster
	Keepers       Keepers
	DBs           DBs
	Proxy         *Proxy
}

for simplicity keep all the changes to the various components atomic (using an unique key)

func NewClusterData added in v0.5.0

func NewClusterData(c *Cluster) *ClusterData

func (*ClusterData) DeepCopy added in v0.5.0

func (c *ClusterData) DeepCopy() *ClusterData

func (*ClusterData) FindDB added in v0.5.0

func (cd *ClusterData) FindDB(keeper *Keeper) *DB

type ClusterInitMode added in v0.5.0

type ClusterInitMode string
const (
	// Initialize a cluster starting from a freshly initialized database cluster. Valid only when cluster role is master.
	ClusterInitModeNew ClusterInitMode = "new"
	// Initialize a cluster doing a point in time recovery on a keeper.
	ClusterInitModePITR ClusterInitMode = "pitr"
	// Initialize a cluster with an user specified already populated db cluster.
	ClusterInitModeExisting ClusterInitMode = "existing"
)

func ClusterInitModeP added in v0.5.0

func ClusterInitModeP(s ClusterInitMode) *ClusterInitMode

type ClusterPhase added in v0.5.0

type ClusterPhase string
const (
	ClusterPhaseInitializing ClusterPhase = "initializing"
	ClusterPhaseNormal       ClusterPhase = "normal"
)

type ClusterRole added in v0.5.0

type ClusterRole string
const (
	ClusterRoleMaster  ClusterRole = "master"
	ClusterRoleStandby ClusterRole = "standby"
)

func ClusterRoleP added in v0.6.0

func ClusterRoleP(s ClusterRole) *ClusterRole

type ClusterSpec added in v0.5.0

type ClusterSpec struct {
	// Interval to wait before next check
	SleepInterval *Duration `json:"sleepInterval,omitempty"`
	// Time after which any request (keepers checks from sentinel etc...) will fail.
	RequestTimeout *Duration `json:"requestTimeout,omitempty"`
	// Interval to wait for a db to be converged to the required state when
	// no long operation are expected.
	ConvergenceTimeout *Duration `json:"convergenceTimeout,omitempty"`
	// Interval to wait for a db to be initialized (doing a initdb)
	InitTimeout *Duration `json:"initTimeout,omitempty"`
	// Interval to wait for a db to be synced with a master
	SyncTimeout *Duration `json:"syncTimeout,omitempty"`
	// Interval after the first fail to declare a keeper or a db as not healthy.
	FailInterval *Duration `json:"failInterval,omitempty"`
	// Interval after which a dead keeper will be removed from the cluster data
	DeadKeeperRemovalInterval *Duration `json:"deadKeeperRemovalInterval,omitempty"`
	// Max number of standbys. This needs to be greater enough to cover both
	// standby managed by stolon and additional standbys configured by the
	// user. Its value affect different postgres parameters like
	// max_replication_slots and max_wal_senders. Setting this to a number
	// lower than the sum of stolon managed standbys and user managed
	// standbys will have unpredicatable effects due to problems creating
	// replication slots or replication problems due to exhausted wal
	// senders.
	MaxStandbys *uint16 `json:"maxStandbys,omitempty"`
	// Max number of standbys for every sender. A sender can be a master or
	// another standby (if/when implementing cascading replication).
	MaxStandbysPerSender *uint16 `json:"maxStandbysPerSender,omitempty"`
	// Max lag in bytes that an asynchronous standy can have to be elected in
	// place of a failed master
	MaxStandbyLag *uint32 `json:"maxStandbyLage,omitempty"`
	// Use Synchronous replication between master and its standbys
	SynchronousReplication *bool `json:"synchronousReplication,omitempty"`
	// MinSynchronousStandbys is the mininum number if synchronous standbys
	// to be configured when SynchronousReplication is true
	MinSynchronousStandbys *uint16 `json:"minSynchronousStandbys,omitempty"`
	// MaxSynchronousStandbys is the maximum number if synchronous standbys
	// to be configured when SynchronousReplication is true
	MaxSynchronousStandbys *uint16 `json:"maxSynchronousStandbys,omitempty"`
	// Whether to use pg_rewind
	UsePgrewind *bool `json:"usePgrewind,omitempty"`
	// InitMode defines the cluster initialization mode. Current modes are: new, existing, pitr
	InitMode *ClusterInitMode `json:"initMode,omitempty"`
	// Whether to merge pgParameters of the initialized db cluster, useful
	// the retain initdb generated parameters when InitMode is new, retain
	// current parameters when initMode is existing or pitr.
	MergePgParameters *bool `json:"mergePgParameters,omitempty"`
	// Role defines the cluster operating role (master or standby of an external database)
	Role *ClusterRole `json:"role,omitempty"`
	// Point in time recovery init configuration used when InitMode is "pitr"
	PITRConfig *PITRConfig `json:"pitrConfig,omitempty"`
	// Existing init configuration used when InitMode is "existing"
	ExistingConfig *ExistingConfig `json:"existingConfig,omitempty"`
	// Standby setting when role is standby
	StandbySettings *StandbySettings `json:"standbySettings,omitempty"`
	// Map of postgres parameters
	PGParameters PGParameters `json:"pgParameters,omitempty"`
}

func (*ClusterSpec) DeepCopy added in v0.5.0

func (c *ClusterSpec) DeepCopy() *ClusterSpec

func (*ClusterSpec) Validate added in v0.5.0

func (os *ClusterSpec) Validate() error

Validate validates a cluster spec.

func (*ClusterSpec) WithDefaults added in v0.5.0

func (os *ClusterSpec) WithDefaults() *ClusterSpec

WithDefaults returns a new ClusterSpec with unspecified values populated with their defaults

type ClusterStatus added in v0.5.0

type ClusterStatus struct {
	CurrentGeneration int64        `json:"currentGeneration,omitempty"`
	Phase             ClusterPhase `json:"phase,omitempty"`
	// Master DB UID
	Master string `json:"master,omitempty"`
}

type DB added in v0.5.0

type DB struct {
	UID        string    `json:"uid,omitempty"`
	Generation int64     `json:"generation,omitempty"`
	ChangeTime time.Time `json:"changeTime,omitempty"`

	Spec *DBSpec `json:"spec,omitempty"`

	Status DBStatus `json:"status,omitempty"`
}

type DBInitMode added in v0.5.0

type DBInitMode string
const (
	DBInitModeNone DBInitMode = "none"
	// Use existing db cluster data
	DBInitModeExisting DBInitMode = "existing"
	// Initialize a db starting from a freshly initialized database cluster
	DBInitModeNew DBInitMode = "new"
	// Initialize a db doing a point in time recovery
	DBInitModePITR DBInitMode = "pitr"
	// Initialize a db doing a resync to a target database cluster
	DBInitModeResync DBInitMode = "resync"
)

type DBSpec added in v0.5.0

type DBSpec struct {
	// The KeeperUID this db is assigned to
	KeeperUID string `json:"keeperUID,omitempty"`
	// Time after which any request (keepers checks from sentinel etc...) will fail.
	RequestTimeout Duration `json:"requestTimeout,omitempty"`
	// See ClusterSpec MaxStandbys description
	MaxStandbys uint16 `json:"maxStandbys,omitempty"`
	// Use Synchronous replication between master and its standbys
	SynchronousReplication bool `json:"synchronousReplication,omitempty"`
	// Whether to use pg_rewind
	UsePgrewind bool `json:"usePgrewind,omitempty"`
	// InitMode defines the db initialization mode. Current modes are: none, new
	InitMode DBInitMode `json:"initMode,omitempty"`
	// Point in time recovery init configuration used when InitMode is "pitr"
	PITRConfig *PITRConfig `json:"pitrConfig,omitempty"`
	// Map of postgres parameters
	PGParameters PGParameters `json:"pgParameters,omitempty"`
	// DB Role (master or standby)
	Role common.Role `json:"role,omitempty"`
	// FollowConfig when Role is "standby"
	FollowConfig *FollowConfig `json:"followConfig,omitempty"`
	// Followers DB UIDs
	Followers []string `json:"followers"`
	// Whether to include previous postgresql.conf
	IncludeConfig bool `json:"includePreviousConfig,omitempty"`
	// SynchronousStandbys are the standbys to be configured as synchronous
	SynchronousStandbys []string `json:"synchronousStandbys"`
}

type DBStatus added in v0.5.0

type DBStatus struct {
	Healthy bool `json:"healthy,omitempty"`

	CurrentGeneration int64 `json:"currentGeneration,omitempty"`

	ListenAddress string `json:"listenAddress,omitempty"`
	Port          string `json:"port,omitempty"`

	SystemID         string                   `json:"systemdID,omitempty"`
	TimelineID       uint64                   `json:"timelineID,omitempty"`
	XLogPos          uint64                   `json:"xLogPos,omitempty"`
	TimelinesHistory PostgresTimelinesHistory `json:"timelinesHistory,omitempty"`

	PGParameters        PGParameters `json:"pgParameters,omitempty"`
	SynchronousStandbys []string     `json:"synchronousStandbys"`
}

type DBs added in v0.5.0

type DBs map[string]*DB

type Duration

type Duration struct {
	time.Duration
}

Duration is needed to be able to marshal/unmarshal json strings with time unit (eg. 3s, 100ms) instead of ugly times in nanoseconds.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

type ExistingConfig added in v0.5.0

type ExistingConfig struct {
	KeeperUID string `json:"keeperUID,omitempty"`
}

type FollowConfig added in v0.5.0

type FollowConfig struct {
	Type FollowType `json:"type,omitempty"`
	// Keeper ID to follow when Type is "internal"
	DBUID string `json:"dbuid,omitempty"`
	// Standby settings when Type is "external"
	StandbySettings *StandbySettings `json:"standbySettings,omitempty"`
}

type FollowType added in v0.5.0

type FollowType string
const (
	// Follow an db managed by a keeper in our cluster
	FollowTypeInternal FollowType = "internal"
	// Follow an external db
	FollowTypeExternal FollowType = "external"
)

type Keeper

type Keeper struct {
	// Keeper ID
	UID        string    `json:"uid,omitempty"`
	Generation int64     `json:"generation,omitempty"`
	ChangeTime time.Time `json:"changeTime,omitempty"`

	Spec *KeeperSpec `json:"spec,omitempty"`

	Status KeeperStatus `json:"status,omitempty"`
}

func NewKeeperFromKeeperInfo added in v0.5.0

func NewKeeperFromKeeperInfo(ki *KeeperInfo) *Keeper

type KeeperInfo

type KeeperInfo struct {
	// An unique id for this info, used to know when this the keeper info
	// has been updated
	InfoUID string `json:"infoUID,omitempty"`

	UID        string `json:"uid,omitempty"`
	ClusterUID string `json:"clusterUID,omitempty"`
	BootUUID   string `json:"bootUUID,omitempty"`

	PostgresState *PostgresState `json:"postgresState,omitempty"`
}

func (*KeeperInfo) DeepCopy added in v0.5.0

func (k *KeeperInfo) DeepCopy() *KeeperInfo

type KeeperSpec added in v0.5.0

type KeeperSpec struct{}

type KeeperStatus added in v0.5.0

type KeeperStatus struct {
	Healthy         bool      `json:"healthy,omitempty"`
	LastHealthyTime time.Time `json:"lastHealthyTime,omitempty"`

	BootUUID string `json:"bootUUID,omitempty"`
}

type Keepers added in v0.5.0

type Keepers map[string]*Keeper

func (Keepers) SortedKeys added in v0.5.0

func (kss Keepers) SortedKeys() []string

type KeepersInfo

type KeepersInfo map[string]*KeeperInfo

func (KeepersInfo) DeepCopy added in v0.5.0

func (k KeepersInfo) DeepCopy() KeepersInfo

type PGParameters added in v0.5.0

type PGParameters map[string]string

type PITRConfig added in v0.5.0

type PITRConfig struct {
	// DataRestoreCommand defines the command to execute for restoring the db
	// cluster data). %d is replaced with the full path to the db cluster
	// datadir. Use %% to embed an actual % character.
	DataRestoreCommand      string                   `json:"dataRestoreCommand,omitempty"`
	ArchiveRecoverySettings *ArchiveRecoverySettings `json:"archiveRecoverySettings,omitempty"`
	RecoveryTargetSettings  *RecoveryTargetSettings  `json:"recoveryTargetSettings,omitempty"`
}

type PostgresState

type PostgresState struct {
	UID        string `json:"uid,omitempty"`
	Generation int64  `json:"generation,omitempty"`

	ListenAddress string `json:"listenAddress,omitempty"`
	Port          string `json:"port,omitempty"`

	Healthy             bool                     `json:"healthy,omitempty"`
	SystemID            string                   `json:"systemID,omitempty"`
	TimelineID          uint64                   `json:"timelineID,omitempty"`
	XLogPos             uint64                   `json:"xLogPos,omitempty"`
	TimelinesHistory    PostgresTimelinesHistory `json:"timelinesHistory,omitempty"`
	PGParameters        common.Parameters        `json:"pgParameters,omitempty"`
	SynchronousStandbys []string                 `json:"synchronousStandbys"`
}

func (*PostgresState) DeepCopy added in v0.5.0

func (p *PostgresState) DeepCopy() *PostgresState

type PostgresTimelineHistory added in v0.4.0

type PostgresTimelineHistory struct {
	TimelineID  uint64 `json:"timelineID,omitempty"`
	SwitchPoint uint64 `json:"switchPoint,omitempty"`
	Reason      string `json:"reason,omitempty"`
}

type PostgresTimelinesHistory added in v0.4.0

type PostgresTimelinesHistory []*PostgresTimelineHistory

func (PostgresTimelinesHistory) GetTimelineHistory added in v0.4.0

func (tlsh PostgresTimelinesHistory) GetTimelineHistory(id uint64) *PostgresTimelineHistory

type ProxiesInfo

type ProxiesInfo []*ProxyInfo

func (ProxiesInfo) Len

func (p ProxiesInfo) Len() int

func (ProxiesInfo) Less

func (p ProxiesInfo) Less(i, j int) bool

func (ProxiesInfo) Swap

func (p ProxiesInfo) Swap(i, j int)

type Proxy added in v0.5.0

type Proxy struct {
	UID        string    `json:"uid,omitempty"`
	Generation int64     `json:"generation,omitempty"`
	ChangeTime time.Time `json:"changeTime,omitempty"`

	Spec ProxySpec `json:"spec,omitempty"`

	Status ProxyStatus `json:"status,omitempty"`
}

type ProxyInfo

type ProxyInfo struct {
	UID             string
	ProxyUID        string
	ProxyGeneration int64
}

type ProxySpec added in v0.5.0

type ProxySpec struct {
	MasterDBUID string `json:"masterDbUid,omitempty"`
}

type ProxyStatus added in v0.5.0

type ProxyStatus struct {
}

type RecoveryTargetSettings added in v0.5.0

type RecoveryTargetSettings struct {
}

RecoveryTargetSettings defines the recovery target settings in the recovery.conf file (https://www.postgresql.org/docs/9.6/static/recovery-target-settings.html )

type SentinelInfo

type SentinelInfo struct {
	UID string
}

type SentinelsInfo

type SentinelsInfo []*SentinelInfo

func (SentinelsInfo) Len

func (s SentinelsInfo) Len() int

func (SentinelsInfo) Less

func (s SentinelsInfo) Less(i, j int) bool

func (SentinelsInfo) Swap

func (s SentinelsInfo) Swap(i, j int)

type StandbySettings added in v0.5.0

type StandbySettings struct {
	PrimaryConninfo       string `json:"primaryConninfo,omitempty"`
	PrimarySlotName       string `json:"primarySlotName,omitempty"`
	RecoveryMinApplyDelay string `json:"recoveryMinApplyDelay,omitempty"`
}

StandbySettings defines the standby settings in the recovery.conf file (https://www.postgresql.org/docs/9.6/static/standby-settings.html )

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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