driver_infrastructure

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 21 Imported by: 8

Documentation

Index

Constants

View Source
const (
	AURORA_MYSQL_DIALECT               string = "aurora-mysql"
	RDS_MYSQL_DIALECT                  string = "rds-mysql"
	MYSQL_DIALECT                      string = "mysql"
	RDS_MYSQL_MULTI_AZ_CLUSTER_DIALECT string = "rds-multi-az-mysql-cluster"
	AURORA_PG_DIALECT                  string = "aurora-pg"
	RDS_PG_DIALECT                     string = "rds-pg"
	PG_DIALECT                         string = "pg"
	RDS_PG_MULTI_AZ_CLUSTER_DIALECT    string = "rds-multi-az-pg-cluster"
)
View Source
const (
	AWS_PGX_DRIVER_CODE   string = "awssql-pgx"
	AWS_MYSQL_DRIVER_CODE string = "awssql-mysql"
)
View Source
const (
	SELECTOR_HIGHEST_WEIGHT  = "highestWeight"
	SELECTOR_RANDOM          = "random"
	SELECTOR_WEIGHTED_RANDOM = "weightedRandom"
)

Variables

View Source
var (
	// Example host weight pair patterns: "host0:3,host1:02,host2:1", "host.com:50000".
	HOST_WEIGHT_PAIR_PATTERN  = regexp.MustCompile("(?i)^((?P<host>[^:/?#]*):(?P<weight>0*[1-9][0-9]*))")
	HOST_PATTERN_GROUP        = "host"
	HOST_WEIGHT_PATTERN_GROUP = "weight"
)
View Source
var DEFAULT_TOPOLOGY_QUERY_TIMEOUT_MS = 5000
View Source
var ENDPOINT_CACHE_EXPIRATION = time.Hour * 24
View Source
var FallbackTopologyRefreshTimeoutMs = 1100
View Source
var KnownDialectsByCode = map[string]DatabaseDialect{
	MYSQL_DIALECT:                      &MySQLDatabaseDialect{},
	PG_DIALECT:                         &PgDatabaseDialect{},
	RDS_MYSQL_DIALECT:                  &RdsMySQLDatabaseDialect{},
	RDS_PG_DIALECT:                     &RdsPgDatabaseDialect{},
	AURORA_MYSQL_DIALECT:               &AuroraMySQLDatabaseDialect{},
	AURORA_PG_DIALECT:                  &AuroraPgDatabaseDialect{},
	RDS_MYSQL_MULTI_AZ_CLUSTER_DIALECT: &RdsMultiAzDbClusterMySQLDialect{},
	RDS_PG_MULTI_AZ_CLUSTER_DIALECT:    &RdsMultiAzDbClusterPgDialect{},
}
View Source
var MONITOR_EXPIRATION_NANOS = time.Minute
View Source
var TOPOLOGY_CACHE_EXPIRATION_NANO = time.Minute * 5
View Source
var TopologyCache = utils.NewCache[[]*host_info_util.HostInfo]()

Functions

func ClearAllRdsHostListProviderCaches

func ClearAllRdsHostListProviderCaches()

func ClearCaches

func ClearCaches()

This cleans up all long standing caches. To be called at the end of program, not each time a Conn is closed.

func ClearResetSessionStateOnCloseFunc

func ClearResetSessionStateOnCloseFunc()

func ClearTransferSessionStateOnCloseFunc

func ClearTransferSessionStateOnCloseFunc()

func GetHostWeightMapFromString

func GetHostWeightMapFromString(hostWeightMapString string) (map[string]int, error)

func GetResetSessionStateOnCloseFunc

func GetResetSessionStateOnCloseFunc() func(sessionState SessionState, conn driver.Conn) bool

func GetTransferSessionStateOnCloseFunc

func GetTransferSessionStateOnCloseFunc() func(sessionState SessionState, conn driver.Conn) bool

func MonitoringRdsHostListProviderClearCaches

func MonitoringRdsHostListProviderClearCaches()

func ResetCustomConnectionProvider

func ResetCustomConnectionProvider()

func SetCustomConnectionProvider

func SetCustomConnectionProvider(connProvider ConnectionProvider)

func SetResetSessionStateOnCloseFunc

func SetResetSessionStateOnCloseFunc(function func(sessionState SessionState, conn driver.Conn) bool)

func SetTransferSessionStateOnCloseFunc

func SetTransferSessionStateOnCloseFunc(function func(sessionState SessionState, conn driver.Conn) bool)

Types

type AuroraLimitlessDialect

type AuroraLimitlessDialect interface {
	GetLimitlessRouterEndpointQuery() string
	DatabaseDialect
}

type AuroraMySQLDatabaseDialect

type AuroraMySQLDatabaseDialect struct {
	MySQLTopologyAwareDatabaseDialect
}

func (*AuroraMySQLDatabaseDialect) GetDialectUpdateCandidates

func (m *AuroraMySQLDatabaseDialect) GetDialectUpdateCandidates() []string

func (*AuroraMySQLDatabaseDialect) GetHostListProvider

func (m *AuroraMySQLDatabaseDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*AuroraMySQLDatabaseDialect) GetHostName

func (m *AuroraMySQLDatabaseDialect) GetHostName(conn driver.Conn) string

func (*AuroraMySQLDatabaseDialect) GetTopology

func (*AuroraMySQLDatabaseDialect) GetWriterHostName

func (m *AuroraMySQLDatabaseDialect) GetWriterHostName(conn driver.Conn) (string, error)

func (*AuroraMySQLDatabaseDialect) IsDialect

func (m *AuroraMySQLDatabaseDialect) IsDialect(conn driver.Conn) bool

type AuroraPgDatabaseDialect

type AuroraPgDatabaseDialect struct {
	PgTopologyAwareDatabaseDialect
}

func (*AuroraPgDatabaseDialect) GetDialectUpdateCandidates

func (m *AuroraPgDatabaseDialect) GetDialectUpdateCandidates() []string

func (*AuroraPgDatabaseDialect) GetHostListProvider

func (m *AuroraPgDatabaseDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*AuroraPgDatabaseDialect) GetHostName

func (m *AuroraPgDatabaseDialect) GetHostName(conn driver.Conn) string

func (*AuroraPgDatabaseDialect) GetLimitlessRouterEndpointQuery

func (m *AuroraPgDatabaseDialect) GetLimitlessRouterEndpointQuery() string

func (*AuroraPgDatabaseDialect) GetTopology

func (m *AuroraPgDatabaseDialect) GetTopology(conn driver.Conn, provider HostListProvider) ([]*host_info_util.HostInfo, error)

func (*AuroraPgDatabaseDialect) GetWriterHostName

func (m *AuroraPgDatabaseDialect) GetWriterHostName(conn driver.Conn) (string, error)

func (*AuroraPgDatabaseDialect) IsDialect

func (m *AuroraPgDatabaseDialect) IsDialect(conn driver.Conn) bool

type BlockingHostListProvider

type BlockingHostListProvider interface {
	HostListProvider
	ForceRefreshHostListWithTimeout(shouldVerifyWriter bool, timeoutMs int) ([]*host_info_util.HostInfo, error)
}

type CanReleaseResources

type CanReleaseResources interface {
	ReleaseResources()
}

type ClusterTopologyMonitor

type ClusterTopologyMonitor interface {
	SetClusterId(clusterId string)
	ForceRefreshVerifyWriter(writerImportant bool, timeoutMs int) ([]*host_info_util.HostInfo, error)
	ForceRefreshUsingConn(conn driver.Conn, timeoutMs int) ([]*host_info_util.HostInfo, error)
	Close()
	Start(wg *sync.WaitGroup)
}

type ClusterTopologyMonitorImpl

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

func NewClusterTopologyMonitorImpl

func NewClusterTopologyMonitorImpl(
	hostListProvider *MonitoringRdsHostListProvider,
	dialect TopologyAwareDialect,
	clusterId string,
	highRefreshRateNano time.Duration,
	refreshRateNano time.Duration,
	topologyCacheExpirationNano time.Duration,
	props map[string]string,
	initialHostInfo *host_info_util.HostInfo,
	clusterInstanceTemplate *host_info_util.HostInfo,
	pluginService PluginService) *ClusterTopologyMonitorImpl

func (*ClusterTopologyMonitorImpl) Close

func (c *ClusterTopologyMonitorImpl) Close()

func (*ClusterTopologyMonitorImpl) ForceRefreshUsingConn

func (c *ClusterTopologyMonitorImpl) ForceRefreshUsingConn(conn driver.Conn, timeoutMs int) ([]*host_info_util.HostInfo, error)

func (*ClusterTopologyMonitorImpl) ForceRefreshVerifyWriter

func (c *ClusterTopologyMonitorImpl) ForceRefreshVerifyWriter(shouldVerify bool, timeoutMs int) ([]*host_info_util.HostInfo, error)

func (*ClusterTopologyMonitorImpl) Run

func (*ClusterTopologyMonitorImpl) SetClusterId

func (c *ClusterTopologyMonitorImpl) SetClusterId(clusterId string)

func (*ClusterTopologyMonitorImpl) Start

type ConnectFunc

type ConnectFunc func(props map[string]string) (driver.Conn, error)

type ConnectionContainer

type ConnectionContainer struct {
	Conn driver.Conn
}

type ConnectionPlugin

type ConnectionPlugin interface {
	GetSubscribedMethods() []string
	Execute(
		connInvokedOn driver.Conn,
		methodName string,
		executeFunc ExecuteFunc,
		methodArgs ...any) (wrappedReturnValue any, wrappedReturnValue2 any, wrappedOk bool, wrappedErr error)
	Connect(hostInfo *host_info_util.HostInfo, props map[string]string, isInitialConnection bool, connectFunc ConnectFunc) (driver.Conn, error)
	ForceConnect(hostInfo *host_info_util.HostInfo, props map[string]string, isInitialConnection bool, connectFunc ConnectFunc) (driver.Conn, error)
	AcceptsStrategy(strategy string) bool
	GetHostInfoByStrategy(role host_info_util.HostRole, strategy string, hosts []*host_info_util.HostInfo) (*host_info_util.HostInfo, error)
	GetHostSelectorStrategy(strategy string) (HostSelector, error)
	NotifyConnectionChanged(changes map[HostChangeOptions]bool) OldConnectionSuggestedAction
	NotifyHostListChanged(changes map[string]map[HostChangeOptions]bool)
	InitHostProvider(initialUrl string, props map[string]string, hostListProviderService HostListProviderService, initHostProviderFunc func() error) error
}

type ConnectionPluginFactory

type ConnectionPluginFactory interface {
	GetInstance(pluginService PluginService, props map[string]string) (ConnectionPlugin, error)
	ClearCaches()
}

type ConnectionProvider

type ConnectionProvider interface {
	AcceptsUrl(hostInfo host_info_util.HostInfo, props map[string]string) bool
	AcceptsStrategy(strategy string) bool
	GetHostInfoByStrategy(hosts []*host_info_util.HostInfo, role host_info_util.HostRole, strategy string, props map[string]string) (*host_info_util.HostInfo, error)
	GetHostSelectorStrategy(strategy string) (HostSelector, error)
	Connect(hostInfo *host_info_util.HostInfo, props map[string]string, pluginService PluginService) (driver.Conn, error)
}

type ConnectionProviderManager

type ConnectionProviderManager struct {
	DefaultProvider   ConnectionProvider
	EffectiveProvider ConnectionProvider
}

func (*ConnectionProviderManager) AcceptsStrategy

func (connProviderManager *ConnectionProviderManager) AcceptsStrategy(strategy string) bool

func (*ConnectionProviderManager) GetConnectionProvider

func (connProviderManager *ConnectionProviderManager) GetConnectionProvider(
	hostInfo host_info_util.HostInfo,
	props map[string]string) ConnectionProvider

func (*ConnectionProviderManager) GetDefaultProvider

func (connProviderManager *ConnectionProviderManager) GetDefaultProvider() ConnectionProvider

func (*ConnectionProviderManager) GetHostInfoByStrategy

func (connProviderManager *ConnectionProviderManager) GetHostInfoByStrategy(
	hosts []*host_info_util.HostInfo,
	role host_info_util.HostRole,
	strategy string,
	props map[string]string) (*host_info_util.HostInfo, error)

func (*ConnectionProviderManager) GetHostSelectorStrategy

func (connProviderManager *ConnectionProviderManager) GetHostSelectorStrategy(strategy string) (HostSelector, error)

type DatabaseDialect

type DatabaseDialect interface {
	GetDefaultPort() int
	GetHostAliasQuery() string
	GetServerVersionQuery() string
	GetDialectUpdateCandidates() []string
	IsDialect(conn driver.Conn) bool
	GetHostListProvider(props map[string]string, initialDsn string, hostListProviderService HostListProviderService, pluginService PluginService) HostListProvider
	DoesStatementSetAutoCommit(statement string) (bool, bool)
	DoesStatementSetReadOnly(statement string) (bool, bool)
	DoesStatementSetCatalog(statement string) (string, bool)
	DoesStatementSetSchema(statement string) (string, bool)
	DoesStatementSetTransactionIsolation(statement string) (TransactionIsolationLevel, bool)
	GetSetAutoCommitQuery(autoCommit bool) (string, error)
	GetSetReadOnlyQuery(readOnly bool) (string, error)
	GetSetCatalogQuery(catalog string) (string, error)
	GetSetSchemaQuery(schema string) (string, error)
	GetSetTransactionIsolationQuery(level TransactionIsolationLevel) (string, error)
}

type DatabaseEngine

type DatabaseEngine string
const (
	MYSQL DatabaseEngine = "mysql"
	PG    DatabaseEngine = "pg"
)

type DialectCode

type DialectCode string

type DialectManager

type DialectManager struct {
	FindRegisteredDriver func(dialectCode string) bool
	// contains filtered or unexported fields
}

func (*DialectManager) GetDialect

func (d *DialectManager) GetDialect(dsn string, props map[string]string) (DatabaseDialect, error)

func (*DialectManager) GetDialectForUpdate

func (d *DialectManager) GetDialectForUpdate(conn driver.Conn, originalHost string, newHost string) DatabaseDialect

type DialectProvider

type DialectProvider interface {
	GetDialect(dsn string, props map[string]string) (DatabaseDialect, error)
	GetDialectForUpdate(conn driver.Conn, originalHost string, newHost string) DatabaseDialect
}

type DriverConnectionProvider

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

func NewDriverConnectionProvider

func NewDriverConnectionProvider(targetDriver driver.Driver) *DriverConnectionProvider

func (DriverConnectionProvider) AcceptsStrategy

func (d DriverConnectionProvider) AcceptsStrategy(strategy string) bool

func (DriverConnectionProvider) AcceptsUrl

func (d DriverConnectionProvider) AcceptsUrl(hostInfo host_info_util.HostInfo, props map[string]string) bool

func (DriverConnectionProvider) Connect

func (d DriverConnectionProvider) Connect(hostInfo *host_info_util.HostInfo, props map[string]string, pluginService PluginService) (driver.Conn, error)

func (DriverConnectionProvider) GetHostInfoByStrategy

func (d DriverConnectionProvider) GetHostInfoByStrategy(
	hosts []*host_info_util.HostInfo,
	role host_info_util.HostRole,
	strategy string,
	props map[string]string) (*host_info_util.HostInfo, error)

func (DriverConnectionProvider) GetHostSelectorStrategy

func (d DriverConnectionProvider) GetHostSelectorStrategy(strategy string) (HostSelector, error)

type DriverDialect

type DriverDialect interface {
	IsDialect(driver driver.Driver) bool
	GetAllowedOnConnectionMethodNames() []string
	PrepareDsn(properties map[string]string, info *host_info_util.HostInfo) string
	IsNetworkError(err error) bool
	IsLoginError(err error) bool
	IsClosed(conn driver.Conn) bool
	IsDriverRegistered(drivers map[string]driver.Driver) bool
	RegisterDriver()
}

type DsnHostListProvider

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

func NewDsnHostListProvider

func NewDsnHostListProvider(props map[string]string, dsn string, hostListProviderService HostListProviderService) *DsnHostListProvider

func (*DsnHostListProvider) CreateHost

func (c *DsnHostListProvider) CreateHost(hostName string, hostRole host_info_util.HostRole, lag float64, cpu float64, lastUpdateTime time.Time) *host_info_util.HostInfo

func (*DsnHostListProvider) ForceRefresh

func (c *DsnHostListProvider) ForceRefresh(conn driver.Conn) ([]*host_info_util.HostInfo, error)

func (*DsnHostListProvider) GetClusterId

func (c *DsnHostListProvider) GetClusterId() (clusterId string, err error)

func (*DsnHostListProvider) GetHostRole

func (c *DsnHostListProvider) GetHostRole(conn driver.Conn) host_info_util.HostRole

func (*DsnHostListProvider) IdentifyConnection

func (c *DsnHostListProvider) IdentifyConnection(conn driver.Conn) (*host_info_util.HostInfo, error)

func (*DsnHostListProvider) IsStaticHostListProvider

func (c *DsnHostListProvider) IsStaticHostListProvider() bool

func (*DsnHostListProvider) Refresh

type ExecuteFunc

type ExecuteFunc func() (any, any, bool, error)

type HighestWeightHostSelector

type HighestWeightHostSelector struct{}

func (*HighestWeightHostSelector) GetHost

type HostChangeOptions

type HostChangeOptions int
const (
	HOSTNAME                  HostChangeOptions = 0
	WENT_UP                   HostChangeOptions = 3
	WENT_DOWN                 HostChangeOptions = 4
	CONNECTION_OBJECT_CHANGED HostChangeOptions = 5
	INITIAL_CONNECTION        HostChangeOptions = 6
	HOST_ADDED                HostChangeOptions = 7
	HOST_CHANGED              HostChangeOptions = 8
	HOST_DELETED              HostChangeOptions = 9
)

type HostListProvider

type HostListProvider interface {
	Refresh(conn driver.Conn) ([]*host_info_util.HostInfo, error)
	ForceRefresh(conn driver.Conn) ([]*host_info_util.HostInfo, error)
	GetHostRole(conn driver.Conn) host_info_util.HostRole
	IdentifyConnection(conn driver.Conn) (*host_info_util.HostInfo, error)
	GetClusterId() (string, error)
	IsStaticHostListProvider() bool
	CreateHost(hostName string, role host_info_util.HostRole, lag float64, cpu float64, lastUpdateTime time.Time) *host_info_util.HostInfo
}

type HostListProviderService

type HostListProviderService interface {
	IsStaticHostListProvider() bool
	CreateHostListProvider(props map[string]string, dsn string) HostListProvider
	GetHostListProvider() HostListProvider
	SetHostListProvider(hostListProvider HostListProvider)
	SetInitialConnectionHostInfo(info *host_info_util.HostInfo)
	GetDialect() DatabaseDialect
	GetCurrentConnection() driver.Conn
}

type HostMonitoringRoutine

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

func (*HostMonitoringRoutine) Init

func (h *HostMonitoringRoutine) Init()

type HostSelector

type HostSelector interface {
	GetHost(hosts []*host_info_util.HostInfo, role host_info_util.HostRole, props map[string]string) (*host_info_util.HostInfo, error)
}

type MonitoringRdsHostListProvider

type MonitoringRdsHostListProvider struct {
	*RdsHostListProvider
	// contains filtered or unexported fields
}

func NewMonitoringRdsHostListProvider

func NewMonitoringRdsHostListProvider(
	hostListProviderService HostListProviderService,
	databaseDialect TopologyAwareDialect,
	properties map[string]string,
	originalDsn string,
	pluginService PluginService) *MonitoringRdsHostListProvider

func (*MonitoringRdsHostListProvider) ForceRefreshHostListWithTimeout

func (m *MonitoringRdsHostListProvider) ForceRefreshHostListWithTimeout(shouldVerifyWriter bool, timeoutMs int) ([]*host_info_util.HostInfo, error)

type MySQLDatabaseDialect

type MySQLDatabaseDialect struct {
}

func (*MySQLDatabaseDialect) DoesStatementSetAutoCommit

func (m *MySQLDatabaseDialect) DoesStatementSetAutoCommit(statement string) (bool, bool)

func (*MySQLDatabaseDialect) DoesStatementSetCatalog

func (m *MySQLDatabaseDialect) DoesStatementSetCatalog(statement string) (string, bool)

func (*MySQLDatabaseDialect) DoesStatementSetReadOnly

func (m *MySQLDatabaseDialect) DoesStatementSetReadOnly(statement string) (bool, bool)

func (*MySQLDatabaseDialect) DoesStatementSetSchema

func (m *MySQLDatabaseDialect) DoesStatementSetSchema(statement string) (string, bool)

func (*MySQLDatabaseDialect) DoesStatementSetTransactionIsolation

func (m *MySQLDatabaseDialect) DoesStatementSetTransactionIsolation(statement string) (TransactionIsolationLevel, bool)

func (*MySQLDatabaseDialect) GetDefaultPort

func (m *MySQLDatabaseDialect) GetDefaultPort() int

func (*MySQLDatabaseDialect) GetDialectUpdateCandidates

func (m *MySQLDatabaseDialect) GetDialectUpdateCandidates() []string

func (*MySQLDatabaseDialect) GetHostAliasQuery

func (m *MySQLDatabaseDialect) GetHostAliasQuery() string

func (*MySQLDatabaseDialect) GetHostListProvider

func (m *MySQLDatabaseDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*MySQLDatabaseDialect) GetServerVersionQuery

func (m *MySQLDatabaseDialect) GetServerVersionQuery() string

func (*MySQLDatabaseDialect) GetSetAutoCommitQuery

func (m *MySQLDatabaseDialect) GetSetAutoCommitQuery(autoCommit bool) (string, error)

func (*MySQLDatabaseDialect) GetSetCatalogQuery

func (m *MySQLDatabaseDialect) GetSetCatalogQuery(catalog string) (string, error)

func (*MySQLDatabaseDialect) GetSetReadOnlyQuery

func (m *MySQLDatabaseDialect) GetSetReadOnlyQuery(readOnly bool) (string, error)

func (*MySQLDatabaseDialect) GetSetSchemaQuery

func (m *MySQLDatabaseDialect) GetSetSchemaQuery(schema string) (string, error)

func (*MySQLDatabaseDialect) GetSetTransactionIsolationQuery

func (m *MySQLDatabaseDialect) GetSetTransactionIsolationQuery(level TransactionIsolationLevel) (string, error)

func (*MySQLDatabaseDialect) IsDialect

func (m *MySQLDatabaseDialect) IsDialect(conn driver.Conn) bool

type MySQLTopologyAwareDatabaseDialect

type MySQLTopologyAwareDatabaseDialect struct {
	MySQLDatabaseDialect
}

func (*MySQLTopologyAwareDatabaseDialect) GetHostListProvider

func (m *MySQLTopologyAwareDatabaseDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*MySQLTopologyAwareDatabaseDialect) GetHostName

func (m *MySQLTopologyAwareDatabaseDialect) GetHostName(conn driver.Conn) string

func (*MySQLTopologyAwareDatabaseDialect) GetHostRole

func (*MySQLTopologyAwareDatabaseDialect) GetTopology

func (*MySQLTopologyAwareDatabaseDialect) GetWriterHostName

func (m *MySQLTopologyAwareDatabaseDialect) GetWriterHostName(conn driver.Conn) (string, error)

type NumberRange

type NumberRange struct {
	Start int
	End   int
}

func (NumberRange) IsInNumberRange

func (nr NumberRange) IsInNumberRange(n int) bool

type OldConnectionSuggestedAction

type OldConnectionSuggestedAction string
const (
	NO_OPINION OldConnectionSuggestedAction = "no_opinion"
	DISPOSE    OldConnectionSuggestedAction = "dispose"
	PRESERVE   OldConnectionSuggestedAction = "preserve"
)

type PgDatabaseDialect

type PgDatabaseDialect struct {
}

func (*PgDatabaseDialect) DoesStatementSetAutoCommit

func (p *PgDatabaseDialect) DoesStatementSetAutoCommit(statement string) (bool, bool)

func (*PgDatabaseDialect) DoesStatementSetCatalog

func (p *PgDatabaseDialect) DoesStatementSetCatalog(statement string) (string, bool)

func (*PgDatabaseDialect) DoesStatementSetReadOnly

func (p *PgDatabaseDialect) DoesStatementSetReadOnly(statement string) (bool, bool)

func (*PgDatabaseDialect) DoesStatementSetSchema

func (p *PgDatabaseDialect) DoesStatementSetSchema(statement string) (string, bool)

func (*PgDatabaseDialect) DoesStatementSetTransactionIsolation

func (p *PgDatabaseDialect) DoesStatementSetTransactionIsolation(statement string) (TransactionIsolationLevel, bool)

func (*PgDatabaseDialect) GetDefaultPort

func (p *PgDatabaseDialect) GetDefaultPort() int

func (*PgDatabaseDialect) GetDialectUpdateCandidates

func (p *PgDatabaseDialect) GetDialectUpdateCandidates() []string

func (*PgDatabaseDialect) GetHostAliasQuery

func (p *PgDatabaseDialect) GetHostAliasQuery() string

func (*PgDatabaseDialect) GetHostListProvider

func (p *PgDatabaseDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*PgDatabaseDialect) GetServerVersionQuery

func (p *PgDatabaseDialect) GetServerVersionQuery() string

func (*PgDatabaseDialect) GetSetAutoCommitQuery

func (p *PgDatabaseDialect) GetSetAutoCommitQuery(autoCommit bool) (string, error)

func (*PgDatabaseDialect) GetSetCatalogQuery

func (p *PgDatabaseDialect) GetSetCatalogQuery(catalog string) (string, error)

func (*PgDatabaseDialect) GetSetReadOnlyQuery

func (p *PgDatabaseDialect) GetSetReadOnlyQuery(readOnly bool) (string, error)

func (*PgDatabaseDialect) GetSetSchemaQuery

func (p *PgDatabaseDialect) GetSetSchemaQuery(schema string) (string, error)

func (*PgDatabaseDialect) GetSetTransactionIsolationQuery

func (p *PgDatabaseDialect) GetSetTransactionIsolationQuery(level TransactionIsolationLevel) (string, error)

func (*PgDatabaseDialect) IsDialect

func (p *PgDatabaseDialect) IsDialect(conn driver.Conn) bool

type PgTopologyAwareDatabaseDialect

type PgTopologyAwareDatabaseDialect struct {
	PgDatabaseDialect
}

func (*PgTopologyAwareDatabaseDialect) GetHostListProvider

func (m *PgTopologyAwareDatabaseDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*PgTopologyAwareDatabaseDialect) GetHostName

func (m *PgTopologyAwareDatabaseDialect) GetHostName(conn driver.Conn) string

func (*PgTopologyAwareDatabaseDialect) GetHostRole

func (*PgTopologyAwareDatabaseDialect) GetTopology

func (*PgTopologyAwareDatabaseDialect) GetWriterHostName

func (m *PgTopologyAwareDatabaseDialect) GetWriterHostName(conn driver.Conn) (string, error)

type PluginConnectFunc

type PluginConnectFunc func(plugin ConnectionPlugin, props map[string]string, targetFunc func(props map[string]string) (driver.Conn, error)) (driver.Conn, error)

type PluginExecFunc

type PluginExecFunc func(plugin ConnectionPlugin, targetFunc func() (any, any, bool, error)) (any, any, bool, error)

type PluginManager

type PluginManager interface {
	Init(pluginService PluginService, plugins []ConnectionPlugin) error
	InitHostProvider(initialUrl string, props map[string]string, hostListProviderService HostListProviderService) error
	Connect(hostInfo *host_info_util.HostInfo, props map[string]string, isInitialConnection bool, pluginToSkip ConnectionPlugin) (driver.Conn, error)
	ForceConnect(hostInfo *host_info_util.HostInfo, props map[string]string, isInitialConnection bool) (driver.Conn, error)
	Execute(connInvokedOn driver.Conn, name string, methodFunc ExecuteFunc, methodArgs ...any) (
		wrappedReturnValue any,
		wrappedReturnValue2 any,
		wrappedOk bool,
		wrappedErr error)
	AcceptsStrategy(strategy string) bool
	NotifyHostListChanged(changes map[string]map[HostChangeOptions]bool)
	NotifyConnectionChanged(
		changes map[HostChangeOptions]bool, skipNotificationForThisPlugin ConnectionPlugin) map[OldConnectionSuggestedAction]bool
	NotifySubscribedPlugins(methodName string, pluginFunc PluginExecFunc, skipNotificationForThisPlugin ConnectionPlugin) error
	GetHostInfoByStrategy(role host_info_util.HostRole, strategy string, hosts []*host_info_util.HostInfo) (*host_info_util.HostInfo, error)
	GetHostSelectorStrategy(strategy string) (hostSelector HostSelector, err error)
	GetDefaultConnectionProvider() ConnectionProvider
	GetEffectiveConnectionProvider() ConnectionProvider
	GetConnectionProviderManager() ConnectionProviderManager
	GetTelemetryContext() context.Context
	GetTelemetryFactory() telemetry.TelemetryFactory
	SetTelemetryContext(ctx context.Context)
	ReleaseResources()
}

type PluginManagerProvider

type PluginManagerProvider func(
	targetDriver driver.Driver,
	props map[string]string,
	connProviderManager ConnectionProviderManager,
	telemetryFactory telemetry.TelemetryFactory) PluginManager

type PluginService

type PluginService interface {
	GetCurrentConnection() driver.Conn
	GetCurrentConnectionRef() *driver.Conn
	SetCurrentConnection(conn driver.Conn, hostInfo *host_info_util.HostInfo, skipNotificationForThisPlugin ConnectionPlugin) error
	GetInitialConnectionHostInfo() *host_info_util.HostInfo
	GetCurrentHostInfo() (*host_info_util.HostInfo, error)
	GetHosts() []*host_info_util.HostInfo
	AcceptsStrategy(strategy string) bool
	GetHostInfoByStrategy(role host_info_util.HostRole, strategy string, hosts []*host_info_util.HostInfo) (*host_info_util.HostInfo, error)
	GetHostSelectorStrategy(strategy string) (hostSelector HostSelector, err error)
	GetHostRole(driver.Conn) host_info_util.HostRole
	SetAvailability(hostAliases map[string]bool, availability host_info_util.HostAvailability)
	IsInTransaction() bool
	SetInTransaction(inTransaction bool)
	GetCurrentTx() driver.Tx
	SetCurrentTx(driver.Tx)
	CreateHostListProvider(props map[string]string, dsn string) HostListProvider
	SetHostListProvider(hostListProvider HostListProvider)
	SetInitialConnectionHostInfo(info *host_info_util.HostInfo)
	IsStaticHostListProvider() bool
	GetHostListProvider() HostListProvider
	RefreshHostList(conn driver.Conn) error
	ForceRefreshHostList(conn driver.Conn) error
	ForceRefreshHostListWithTimeout(shouldVerifyWriter bool, timeoutMs int) (bool, error)
	GetUpdatedHostListWithTimeout(shouldVerifyWriter bool, timeoutMs int) ([]*host_info_util.HostInfo, error)
	Connect(hostInfo *host_info_util.HostInfo, props map[string]string, pluginToSkip ConnectionPlugin) (driver.Conn, error)
	ForceConnect(hostInfo *host_info_util.HostInfo, props map[string]string) (driver.Conn, error)
	GetDialect() DatabaseDialect
	SetDialect(dialect DatabaseDialect)
	UpdateDialect(conn driver.Conn)
	GetTargetDriverDialect() DriverDialect
	IdentifyConnection(conn driver.Conn) (*host_info_util.HostInfo, error)
	FillAliases(conn driver.Conn, hostInfo *host_info_util.HostInfo)
	GetConnectionProvider() ConnectionProvider
	GetProperties() map[string]string
	IsNetworkError(err error) bool
	IsLoginError(err error) bool
	GetTelemetryContext() context.Context
	GetTelemetryFactory() telemetry.TelemetryFactory
	SetTelemetryContext(ctx context.Context)
	UpdateState(sql string, methodArgs ...any)
}

type PluginServiceProvider

type PluginServiceProvider func(
	pluginManager PluginManager,
	driverDialect DriverDialect,
	props map[string]string,
	dsn string) (PluginService, error)

type RandomHostSelector

type RandomHostSelector struct{}

func (*RandomHostSelector) GetHost

type RdsHostListProvider

type RdsHostListProvider struct {
	IsPrimaryClusterId bool
	// contains filtered or unexported fields
}

func NewRdsHostListProvider

func NewRdsHostListProvider(
	hostListProviderService HostListProviderService,
	databaseDialect TopologyAwareDialect,
	properties map[string]string,
	originalDsn string,
	queryForTopologyFunc func(conn driver.Conn) ([]*host_info_util.HostInfo, error),
	clusterIdChangedFunc func(oldClusterId string)) *RdsHostListProvider

func (*RdsHostListProvider) CreateHost

func (r *RdsHostListProvider) CreateHost(host string, hostRole host_info_util.HostRole, lag float64, cpu float64, lastUpdateTime time.Time) *host_info_util.HostInfo

func (*RdsHostListProvider) ForceRefresh

func (r *RdsHostListProvider) ForceRefresh(conn driver.Conn) ([]*host_info_util.HostInfo, error)

func (*RdsHostListProvider) GetClusterId

func (r *RdsHostListProvider) GetClusterId() (string, error)

func (*RdsHostListProvider) GetHostRole

func (r *RdsHostListProvider) GetHostRole(conn driver.Conn) host_info_util.HostRole

func (*RdsHostListProvider) IdentifyConnection

func (r *RdsHostListProvider) IdentifyConnection(conn driver.Conn) (*host_info_util.HostInfo, error)

func (*RdsHostListProvider) IsStaticHostListProvider

func (r *RdsHostListProvider) IsStaticHostListProvider() bool

func (*RdsHostListProvider) Refresh

type RdsMultiAzDbClusterMySQLDialect

type RdsMultiAzDbClusterMySQLDialect struct {
	MySQLTopologyAwareDatabaseDialect
}

func (*RdsMultiAzDbClusterMySQLDialect) GetDialectUpdateCandidates

func (r *RdsMultiAzDbClusterMySQLDialect) GetDialectUpdateCandidates() []string

func (*RdsMultiAzDbClusterMySQLDialect) GetHostListProvider

func (r *RdsMultiAzDbClusterMySQLDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*RdsMultiAzDbClusterMySQLDialect) GetHostName

func (r *RdsMultiAzDbClusterMySQLDialect) GetHostName(conn driver.Conn) string

func (*RdsMultiAzDbClusterMySQLDialect) GetTopology

func (*RdsMultiAzDbClusterMySQLDialect) GetWriterHostName

func (r *RdsMultiAzDbClusterMySQLDialect) GetWriterHostName(conn driver.Conn) (string, error)

func (*RdsMultiAzDbClusterMySQLDialect) IsDialect

func (r *RdsMultiAzDbClusterMySQLDialect) IsDialect(conn driver.Conn) bool

type RdsMultiAzDbClusterPgDialect

type RdsMultiAzDbClusterPgDialect struct {
	PgTopologyAwareDatabaseDialect
}

func (*RdsMultiAzDbClusterPgDialect) GetDialectUpdateCandidates

func (r *RdsMultiAzDbClusterPgDialect) GetDialectUpdateCandidates() []string

func (*RdsMultiAzDbClusterPgDialect) GetHostListProvider

func (r *RdsMultiAzDbClusterPgDialect) GetHostListProvider(
	props map[string]string,
	initialDsn string,
	hostListProviderService HostListProviderService,
	pluginService PluginService) HostListProvider

func (*RdsMultiAzDbClusterPgDialect) GetHostName

func (r *RdsMultiAzDbClusterPgDialect) GetHostName(conn driver.Conn) string

func (*RdsMultiAzDbClusterPgDialect) GetTopology

func (*RdsMultiAzDbClusterPgDialect) GetWriterHostName

func (r *RdsMultiAzDbClusterPgDialect) GetWriterHostName(conn driver.Conn) (string, error)

func (*RdsMultiAzDbClusterPgDialect) IsDialect

func (r *RdsMultiAzDbClusterPgDialect) IsDialect(conn driver.Conn) bool

type RdsMySQLDatabaseDialect

type RdsMySQLDatabaseDialect struct {
	MySQLDatabaseDialect
}

func (*RdsMySQLDatabaseDialect) GetDialectUpdateCandidates

func (m *RdsMySQLDatabaseDialect) GetDialectUpdateCandidates() []string

func (*RdsMySQLDatabaseDialect) IsDialect

func (m *RdsMySQLDatabaseDialect) IsDialect(conn driver.Conn) bool

type RdsPgDatabaseDialect

type RdsPgDatabaseDialect struct {
	PgDatabaseDialect
}

func (*RdsPgDatabaseDialect) GetDialectUpdateCandidates

func (m *RdsPgDatabaseDialect) GetDialectUpdateCandidates() []string

func (*RdsPgDatabaseDialect) IsDialect

func (m *RdsPgDatabaseDialect) IsDialect(conn driver.Conn) bool

type SessionState

type SessionState struct {
	AutoCommit           SessionStateField[bool]
	ReadOnly             SessionStateField[bool]
	Catalog              SessionStateField[string]
	Schema               SessionStateField[string]
	TransactionIsolation SessionStateField[TransactionIsolationLevel]
}

func (*SessionState) Copy

func (ssf *SessionState) Copy() *SessionState

func (*SessionState) ToString

func (ssf *SessionState) ToString() string

type SessionStateField

type SessionStateField[T comparable] struct {
	// contains filtered or unexported fields
}

func (*SessionStateField[T]) CanRestorePristine

func (ssf *SessionStateField[T]) CanRestorePristine() bool

func (*SessionStateField[T]) GetPristineValue

func (ssf *SessionStateField[T]) GetPristineValue() *T

func (*SessionStateField[T]) GetValue

func (ssf *SessionStateField[T]) GetValue() *T

func (*SessionStateField[T]) Reset

func (ssf *SessionStateField[T]) Reset()

func (*SessionStateField[T]) ResetPristineValue

func (ssf *SessionStateField[T]) ResetPristineValue()

func (*SessionStateField[T]) ResetValue

func (ssf *SessionStateField[T]) ResetValue()

func (*SessionStateField[T]) SetPristineValue

func (ssf *SessionStateField[T]) SetPristineValue(value T)

func (*SessionStateField[T]) SetValue

func (ssf *SessionStateField[T]) SetValue(value T)

type SessionStateService

type SessionStateService interface {
	GetAutoCommit() *bool
	SetAutoCommit(bool)
	SetupPristineAutoCommit()
	SetupPristineAutoCommitWithVal(bool)

	GetReadOnly() *bool
	SetReadOnly(bool)
	SetupPristineReadOnly()
	SetupPristineReadOnlyWithVal(bool)

	GetCatalog() *string
	SetCatalog(string)
	SetupPristineCatalog()
	SetupPristineCatalogWithVal(string)

	GetSchema() *string
	SetSchema(string)
	SetupPristineSchema()
	SetupPristineSchemaWithVal(string)

	GetTransactionIsolation() *TransactionIsolationLevel
	SetTransactionIsolation(level TransactionIsolationLevel)
	SetupPristineTransactionIsolation()
	SetupPristineTransactionIsolationWithVal(TransactionIsolationLevel)

	Begin() error
	Complete()
	Reset()

	ApplyCurrentSessionState(conn driver.Conn) error
	ApplyPristineSessionState(conn driver.Conn) error
}

type SessionStateServiceImpl

type SessionStateServiceImpl struct {
	SessionState *SessionState
	// contains filtered or unexported fields
}

func NewSessionStateServiceImpl

func NewSessionStateServiceImpl(pluginService PluginService, props map[string]string) *SessionStateServiceImpl

func (*SessionStateServiceImpl) ApplyCurrentSessionState

func (sss *SessionStateServiceImpl) ApplyCurrentSessionState(newConn driver.Conn) error

func (*SessionStateServiceImpl) ApplyPristineSessionState

func (sss *SessionStateServiceImpl) ApplyPristineSessionState(conn driver.Conn) error

func (*SessionStateServiceImpl) Begin

func (sss *SessionStateServiceImpl) Begin() error

func (*SessionStateServiceImpl) Complete

func (sss *SessionStateServiceImpl) Complete()

func (*SessionStateServiceImpl) GetAutoCommit

func (sss *SessionStateServiceImpl) GetAutoCommit() *bool

func (*SessionStateServiceImpl) GetCatalog

func (sss *SessionStateServiceImpl) GetCatalog() *string

func (*SessionStateServiceImpl) GetReadOnly

func (sss *SessionStateServiceImpl) GetReadOnly() *bool

func (*SessionStateServiceImpl) GetSchema

func (sss *SessionStateServiceImpl) GetSchema() *string

func (*SessionStateServiceImpl) GetTransactionIsolation

func (sss *SessionStateServiceImpl) GetTransactionIsolation() *TransactionIsolationLevel

func (*SessionStateServiceImpl) Reset

func (sss *SessionStateServiceImpl) Reset()

func (*SessionStateServiceImpl) SetAutoCommit

func (sss *SessionStateServiceImpl) SetAutoCommit(val bool)

func (*SessionStateServiceImpl) SetCatalog

func (sss *SessionStateServiceImpl) SetCatalog(val string)

func (*SessionStateServiceImpl) SetReadOnly

func (sss *SessionStateServiceImpl) SetReadOnly(val bool)

func (*SessionStateServiceImpl) SetSchema

func (sss *SessionStateServiceImpl) SetSchema(val string)

func (*SessionStateServiceImpl) SetTransactionIsolation

func (sss *SessionStateServiceImpl) SetTransactionIsolation(val TransactionIsolationLevel)

func (*SessionStateServiceImpl) SetupPristineAutoCommit

func (sss *SessionStateServiceImpl) SetupPristineAutoCommit()

func (*SessionStateServiceImpl) SetupPristineAutoCommitWithVal

func (sss *SessionStateServiceImpl) SetupPristineAutoCommitWithVal(val bool)

func (*SessionStateServiceImpl) SetupPristineCatalog

func (sss *SessionStateServiceImpl) SetupPristineCatalog()

func (*SessionStateServiceImpl) SetupPristineCatalogWithVal

func (sss *SessionStateServiceImpl) SetupPristineCatalogWithVal(val string)

func (*SessionStateServiceImpl) SetupPristineReadOnly

func (sss *SessionStateServiceImpl) SetupPristineReadOnly()

func (*SessionStateServiceImpl) SetupPristineReadOnlyWithVal

func (sss *SessionStateServiceImpl) SetupPristineReadOnlyWithVal(val bool)

func (*SessionStateServiceImpl) SetupPristineSchema

func (sss *SessionStateServiceImpl) SetupPristineSchema()

func (*SessionStateServiceImpl) SetupPristineSchemaWithVal

func (sss *SessionStateServiceImpl) SetupPristineSchemaWithVal(val string)

func (*SessionStateServiceImpl) SetupPristineTransactionIsolation

func (sss *SessionStateServiceImpl) SetupPristineTransactionIsolation()

func (*SessionStateServiceImpl) SetupPristineTransactionIsolationWithVal

func (sss *SessionStateServiceImpl) SetupPristineTransactionIsolationWithVal(val TransactionIsolationLevel)

type TopologyAwareDialect

type TopologyAwareDialect interface {
	GetTopology(conn driver.Conn, provider HostListProvider) ([]*host_info_util.HostInfo, error)
	GetHostRole(conn driver.Conn) host_info_util.HostRole
	GetHostName(conn driver.Conn) string
	GetWriterHostName(conn driver.Conn) (string, error)
	DatabaseDialect
}

type TransactionIsolationLevel

type TransactionIsolationLevel int
const (
	TRANSACTION_READ_UNCOMMITTED TransactionIsolationLevel = 0
	TRANSACTION_READ_COMMITTED   TransactionIsolationLevel = 1
	TRANSACTION_REPEATABLE_READ  TransactionIsolationLevel = 2
	TRANSACTION_SERIALIZABLE     TransactionIsolationLevel = 3
)

type WeightedHostSelector

type WeightedHostSelector interface {
	SetHostWeights(hostWeightMap map[string]int)
	ClearHostWeights()
	HostSelector
}

type WeightedRandomHostSelector

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

func (*WeightedRandomHostSelector) ClearHostWeights

func (r *WeightedRandomHostSelector) ClearHostWeights()

func (*WeightedRandomHostSelector) GetHost

func (*WeightedRandomHostSelector) SetHostWeights

func (r *WeightedRandomHostSelector) SetHostWeights(hostWeightMap map[string]int)

func (*WeightedRandomHostSelector) SetRandomNumberFunc

func (r *WeightedRandomHostSelector) SetRandomNumberFunc(f func(int) int)

Jump to

Keyboard shortcuts

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