Documentation ¶
Overview ¶
Package datasource defines datasource interface, and implements the interface by ClusterDataSource, NodeDataSource, and ActualDataSource. The ClusterDataSource have auto change target datasource capabilities, NodeDatasource have read/write separation and failure retry capabilities, ActualDataSource is an actual datasource which contains actual dsn.
Index ¶
Constants ¶
const ( LoadBalanceTypeRandom = "RANDOM" LoadBalanceTypeRoundRobin = "ROUND_ROBIN" )
const DsnFmt = "%s:%s@%s"
DsnFmt mysql dsn Example: username:password@protocol(address)/dbname?param=value, see details https://github.com/go-sql-driver/mysql#dsn-data-source-name
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActualDataSource ¶
type ActualDataSource struct { Available bool Dsn string Name string RetryTimes int LastRetryTime int64 // latest retry timestamp, ms }
ActualDataSource an actual datasource which contains actual dsn.
func NewActualDataSource ¶
func NewActualDataSource(name string, datasource *config.DataSourceConfiguration) *ActualDataSource
NewActualDataSource create an actual datasource through dsn
type ClusterDataSource ¶
type ClusterDataSource struct { RouterConfiguration *config.RouterConfiguration DataSources map[string]*NodeDataSource Active string Region string // contains filtered or unexported fields }
ClusterDataSource which have auto change target datasource capabilities.
func NewClusterDataSource ¶
func NewClusterDataSource(clusterConfiguration *config.ClusterConfiguration) (*ClusterDataSource, error)
NewClusterDataSource create a clusterDataSource by yaml clusterConfiguration and remote etcd clusterConfiguration, and listen remote activeKey, when remote activeKey changes, change the clusterDataSource's active node.
func (*ClusterDataSource) OnChanged ¶
func (cd *ClusterDataSource) OnChanged(configuration *config.RouterConfiguration)
OnChanged implements RouterConfigurationListener interface, when remote routerConfiguration active changes, change the clusterDataSource's active node.
type DataSource ¶
type DataSource interface {
// contains filtered or unexported methods
}
DataSource interface
type LoadBalanceAlgorithm ¶
type LoadBalanceAlgorithm interface { // GetActualDataSource Select the data source. GetActualDataSource(int64, []*ActualDataSource) *ActualDataSource }
LoadBalanceAlgorithm Read/write separation load balance algorithm interface.
func AlgorithmLoader ¶
func AlgorithmLoader(loadBalanceType string) LoadBalanceAlgorithm
AlgorithmLoader load LoadBalanceAlgorithm by loadBalanceType.
type NodeDataSource ¶
type NodeDataSource struct { Region string Name string MasterDataSource *ActualDataSource SlavesDatasource []*ActualDataSource LoadBalanceAlgorithm LoadBalanceAlgorithm }
NodeDataSource have read/write separation and failure retry capabilities.
func NewNodeDataSource ¶
func NewNodeDataSource(nodeName, loadBalanceType, masterName string, slavesName []string, dataSourceConfigurationMap map[string]*config.DataSourceConfiguration) *NodeDataSource
@param nodeName: node datasource name @param loadBalanceType: random or round-robin @param masterName: master datasource name @param slavesName: salves datasources name
type RandomLoadBalanceAlgorithm ¶
type RandomLoadBalanceAlgorithm struct { }
RandomLoadBalanceAlgorithm get actualDataSource from salves randomly.
func (*RandomLoadBalanceAlgorithm) GetActualDataSource ¶
func (ra *RandomLoadBalanceAlgorithm) GetActualDataSource(requestId int64, slavesDataSource []*ActualDataSource) *ActualDataSource
GetActualDataSource randomly
type RoundRobinLoadBalanceAlgorithm ¶
type RoundRobinLoadBalanceAlgorithm struct {
// contains filtered or unexported fields
}
RoundRobinLoadBalanceAlgorithm get actualDataSource from salves in order.
func (*RoundRobinLoadBalanceAlgorithm) GetActualDataSource ¶
func (ro *RoundRobinLoadBalanceAlgorithm) GetActualDataSource( requestId int64, slavesDataSource []*ActualDataSource) *ActualDataSource
GetActualDataSource by round-robin algorithm