Documentation
¶
Index ¶
- type Config
- type ConnInfo
- type ConnType
- type Connector
- type Executor
- type Manager
- func (m *Manager) ConnInfo(ctx context.Context) (counts []swoinfo.ConnCount, err error)
- func (m *Manager) DB() *sql.DB
- 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 ¶
This section is empty.
Types ¶
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 Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector is a driver.Connector 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).
func NewConnector ¶
NewConnector creates a new Connector pointing to the old and new DBs, respectively.
func (*Connector) Connect ¶
Connect returns a new connection to the database.
A shared advisory lock is acquired on the connection to the old DB, and then switchover_state is checked.
When `current_state` is `use_next_db`, the connection is closed and a connection to the new DB is returned instead. Future connections then skip the check and are returned directly from the new DB.
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) DB ¶
DB returns a sql.DB that will always return safe connections to be used during the switchover.
All application code/queries should use this DB.
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.