postgresutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPostgresPort define the default Postgres Port
	DefaultPostgresPort = 5432
	// PostgresPrimaryRole Postgres role primary
	PostgresPrimaryRole = "Primary"
	// PostgresStandbyRole Postgres role standby
	PostgresStandbyRole = "Standby"
)
View Source
const (

	// ErrNotFound cannot find a node to connect to
	ErrNotFound = "unable to find a node to connect"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin struct {
	// contains filtered or unexported fields
}

Admin wraps redis cluster admin logic

func (*Admin) Close

func (a *Admin) Close()

Close used to close all possible resources instanciate by the Admin

func (*Admin) ConfigureAsyncMode

func (a *Admin) ConfigureAsyncMode(ctx context.Context, addr string) error

func (*Admin) ConfigureStandby

func (a *Admin) ConfigureStandby(ctx context.Context, addr, nodeName, sourceHost, sourcePort, replicationUser, replicationPwd string) error

func (*Admin) ConfigureSyncMode

func (a *Admin) ConfigureSyncMode(ctx context.Context, addr, standbyList string) error

func (*Admin) Connections

func (a *Admin) Connections() IAdminConnections

Connections returns the connection map of all clients

func (*Admin) GetReplicationStatus

func (a *Admin) GetReplicationStatus(ctx context.Context) *ReplicationInfo

GetReplicationStatus return the Nodes infos for all nodes

type AdminConnections

type AdminConnections struct {
	// contains filtered or unexported fields
}

AdminConnections connection map for mysql replication cluster currently the admin connection is not threadSafe since it is only use in the Events thread.

func (*AdminConnections) Add

func (cnx *AdminConnections) Add(addr string) error

Add connect to the given address and register the client connection to the map

func (*AdminConnections) AddAll

func (cnx *AdminConnections) AddAll(addrs []string)

AddAll connect to the given list of addresses and register them in the map fail silently

func (*AdminConnections) Get

func (cnx *AdminConnections) Get(addr string) (IClient, error)

Get returns a client connection for the given adress, connects if the connection is not in the map yet

func (*AdminConnections) GetAll

func (cnx *AdminConnections) GetAll() map[string]IClient

GetAll returns a map of all clients per address

func (*AdminConnections) GetSelected

func (cnx *AdminConnections) GetSelected(addrs []string) map[string]IClient

GetSelected returns a map of clients based on the input addresses

func (*AdminConnections) Reconnect

func (cnx *AdminConnections) Reconnect(addr string) error

Reconnect force a reconnection on the given address is the adress is not part of the map, act like Add

func (*AdminConnections) Remove

func (cnx *AdminConnections) Remove(addr string)

Remove disconnect and remove the client connection from the map

func (*AdminConnections) ReplaceAll

func (cnx *AdminConnections) ReplaceAll(addrs []string)

ReplaceAll clear the pool and re-populate it with new connections fail silently

func (*AdminConnections) Reset

func (cnx *AdminConnections) Reset()

Reset close all connections and clear the connection map

type AdminOptions

type AdminOptions struct {
	ConnectionTimeout int
	Username          string
	Password          string
}

AdminOptions optional options for redis admin

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client structure representing a client connection to pgsql

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*Client) Query

func (c *Client) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)

func (*Client) QueryRow

func (c *Client) QueryRow(ctx context.Context, input interface{}, query string, args ...any) error

type IAdmin

type IAdmin interface {
	// Connections returns the connection map of all clients
	Connections() IAdminConnections

	// Close the admin connections
	Close()

	// GetReplicationStatus return the Nodes infos for all nodes
	GetReplicationStatus(ctx context.Context) *ReplicationInfo

	// ConfigureStandby set postgres standby primary connect info
	ConfigureStandby(ctx context.Context, addr, nodeName, sourceHost, sourcePort, replicationUser, replicationPwd string) error

	// ConfigureSyncMode set postgres replication to synchronous
	ConfigureSyncMode(ctx context.Context, addr, standbyList string) error

	// ConfigureAsyncMode set postgres replication to asynchronous
	ConfigureAsyncMode(ctx context.Context, addr string) error
}

IAdmin mysql admin interface

func NewAdmin

func NewAdmin(addrs []string, options *AdminOptions, log logr.Logger) IAdmin

NewAdmin returns new AdminInterface instance at the same time it connects to all Redis Nodes thanks to the addrs list

type IAdminConnections

type IAdminConnections interface {
	// AddAll connect to the given list of addresses and
	// register them in the map
	// fail silently
	AddAll(addrs []string)

	// Add connect to the given address and
	// register the client connection to the pool
	Add(addr string) error

	// Reconnect force a reconnection on the given address
	// if the adress is not part of the map, act like Add
	Reconnect(addr string) error

	// Remove disconnect and remove the client connection from the map
	Remove(addr string)

	// ReplaceAll clear the map and re-populate it with new connections
	// fail silently
	ReplaceAll(addrs []string)

	// Reset close all connections and clear the connection map
	Reset()

	// Get returns a client connection for the given address,
	// connects if the connection is not in the map yet
	Get(addr string) (IClient, error)

	// GetAll returns a map of all clients per address
	GetAll() map[string]IClient

	//GetSelected returns a map of clients based on the input addresses
	GetSelected(addrs []string) map[string]IClient
}

IAdminConnections interface representing the map of admin connections to mysql nodes

func NewAdminConnections

func NewAdminConnections(addrs []string, options *AdminOptions, log logr.Logger) IAdminConnections

NewAdminConnections returns and instance of AdminConnectionsInterface

type IClient

type IClient interface {
	// Close closes the connection.
	Close() error

	// Exec calls the given query like
	Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
	Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(ctx context.Context, input interface{}, query string, args ...any) error
}

IClient pgsql client interface

func NewClient

func NewClient(addr, username, password string, timeout int) (IClient, error)

NewClient build a client connection and connect to a pgsql

type Node

type Node struct {
	Host            string
	Port            int
	Role            string
	ReplicationStat []string
	DataDir         string
	ReplicationMode string
	WalDiff         int
}

func NewDefaultNode

func NewDefaultNode() *Node

NewDefaultNode builds and returns new defaultNode instance

func (*Node) GetRole

GetRole return the Postgres Replication Node GetRole

func (*Node) HostPort

func (n *Node) HostPort() string

HostPort returns join Host Port string

type Nodes

type Nodes []*Node

Nodes represent a Node slice

type ReplicationInfo

type ReplicationInfo struct {
	Nodes map[string]*Node
}

func NewReplicationInfo

func NewReplicationInfo() *ReplicationInfo

Jump to

Keyboard shortcuts

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