Documentation ¶
Index ¶
- func NewAppPGXPool(oldURL, nextURL string, maxOpen, maxIdle int) (*pgxpool.Pool, error)
- type Config
- type ConnInfo
- type ConnType
- type Executor
- type Manager
- func (m *Manager) ConnInfo(ctx context.Context) (counts []swoinfo.ConnCount, err error)
- func (m *Manager) Pool() *pgxpool.Pool
- func (m *Manager) Reset(ctx context.Context) error
- func (m *Manager) SetPauseResumer(app lifecycle.PauseResumer)
- func (m *Manager) StartExecute(ctx context.Context) error
- func (m *Manager) Status() Status
- type Node
- type Status
- type WithFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAppPGXPool ¶ added in v0.33.0
NewAppPGXPool returns a pgxpool.Pool that will use the old database until the switchover_state table indicates that the new database should be used.
Until the switchover is complete, the old database will be protected with a shared advisory lock (4369).
Types ¶
type Config ¶
type Config struct {
OldDBURL, NewDBURL string
CanExec bool
Logger *log.Logger
MaxOpen int
MaxIdle int
}
Config configures the current node for SWO.
type ConnInfo ¶
ConnInfo contains information about a connection to the DB for SWO.
This is stored as the `application_name` for a connection in Postgres in the format of "GoAlert <version> SWO:<type>:<id>" where id is a base64 encoded UUID that should match what ends up in a `switchover_log` hello message.
func ParseConnInfo ¶
ParseConnInfo parses a connection string into a ConnInfo.
type ConnType ¶
type ConnType byte
ConnType indicates a type of SWO connection.
const ( // ConnTypeMainMgr is the connection pool to the main/old DB used to coordinate the switchover. ConnTypeMainMgr ConnType = iota + 'A' // ConnTypeMainApp is the connection pool used by the GoAlert application to the main/old DB. // // Connections here are protected with a shared advisory lock. ConnTypeMainApp // ConnTypeNextMgr is the connection pool to the next/new DB used for applying changes during the switchover. ConnTypeNextMgr // ConnTypeNextApp is the connection pool used by the GoAlert application to the next/new DB, after the switchover is completed. ConnTypeNextApp )
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor is responsible for executing the switchover process.
func NewExecutor ¶
NewExecutor initializes a new Executor for the given Manager.
type Manager ¶
type Manager struct { Config MainDBInfo *swoinfo.DB NextDBInfo *swoinfo.DB // contains filtered or unexported fields }
A Manager is responsible for managing the switchover process.
func NewManager ¶
NewManager will create a new Manager with the given configuration.
func (*Manager) Pool ¶ added in v0.33.0
Pool returns a pgxpool.Pool that will always return safe connections to be used during the switchover.
All application code/queries should use this.
func (*Manager) SetPauseResumer ¶
func (m *Manager) SetPauseResumer(app lifecycle.PauseResumer)
SetPauseResumer allows setting the pause/resume functionality for the manager.
Pause is called during the switchover process to minimize the number of long-lived DB connections so that the final sync can be performed quickly.
After a switchover, or if it is aborted, Resume will be called.
func (*Manager) StartExecute ¶
StartExecute will trigger the switchover to begin.
type Node ¶
type Node struct { ID uuid.UUID // OldValid indicates that the old database config is valid. OldValid bool // NewValid indicates that the new database config is valid. NewValid bool // CanExec indicates the node is NOT in API-only mode and is capable of executing tasks. CanExec bool Status string }
Node contains information on a GoAlert instance in SWO mode.
type Status ¶
type Status struct { swogrp.Status MainDBID uuid.UUID NextDBID uuid.UUID MainDBVersion string NextDBVersion string }
Status represents the current status of the switchover process.
type WithFunc ¶
type WithFunc[V any] struct { // contains filtered or unexported fields }
WithFunc flattens a with-type func providing it's value with Begin() and ending with Cancel().
func NewWithFunc ¶
NewWithFunc creates a new WithFunc.
withFn must not return an error after useFn is called.