Documentation ¶
Index ¶
- Constants
- Variables
- func GetConnPropCapacity(connProps map[string]interface{}, defaultValue int) int
- func GetConnPropIdleTime(connProps map[string]interface{}, defaultValue time.Duration) time.Duration
- func GetConnPropMaxCapacity(connProps map[string]interface{}, defaultValue int) int
- func Init(options Options, version string) error
- func InitStoreOperate(options Options) error
- func JSONToYAML(j string) ([]byte, error)
- func NewConfigWatcher(tenant string, storeOperate StoreOperator, pathInfo *PathInfo) (*configWatcher, error)
- func Register(s StoreOperator) error
- func Validate(cfg *Configuration) error
- func WithCacheable(open bool) option
- func WithReader(open bool) option
- func WithWatcher(open bool) option
- func WithWriter(open bool) option
- type BootOptions
- type CacheConfigReaderTest
- type Center
- type CenterTest
- type ClusterEvent
- type Clusters
- type ClustersEvent
- type ColumnRule
- type ConfigItem
- type ConfigReader
- type ConfigWatcher
- type ConfigWatcherTest
- type ConfigWriter
- type Configuration
- type Data
- type DataRevision
- type DataSourceCluster
- type DataSourceType
- type Decoder
- type Event
- type EventCallback
- type EventType
- type Group
- type GroupEvent
- type Groups
- type GroupsEvent
- type Listener
- type MatchRule
- type Node
- type Nodes
- type NodesEvent
- type Options
- type ParametersMap
- type PathInfo
- type PathKey
- type Prop
- type ProtocolType
- type Registry
- type Rule
- type RuleAttribute
- type Rules
- type Sequence
- type ShadowRule
- type ShadowRuleEvent
- type ShadowTable
- type ShardingRule
- type ShardingRuleEvent
- type SocketAddress
- type Spec
- type StoreOperator
- type SubscribeResult
- type Table
- type Tenant
- type TenantOperator
- type Tenants
- type TenantsEvent
- type Topology
- type Trace
- type User
- type Users
- type UsersEvent
Constants ¶
const ( ConfigItemSpec = "spec" ConfigItemSysDB = "sys_db" ConfigItemUsers = "users" ConfigItemClusters = "clusters" ConfigItemShardingRule = "sharding_rule" ConfigItemNodes = "nodes" ConfigItemShadowRule = "shadow_rule" )
Variables ¶
var ErrorNoStoreOperate = errors.New("no store operate")
var ErrorNotImplement = errors.New("not implement")
Functions ¶
func GetConnPropCapacity ¶
GetConnPropCapacity parses the capacity of backend connection pool, return default value if failed.
func GetConnPropIdleTime ¶
func GetConnPropIdleTime(connProps map[string]interface{}, defaultValue time.Duration) time.Duration
GetConnPropIdleTime parses the idle time of backend connection pool, return default value if failed.
func GetConnPropMaxCapacity ¶
GetConnPropMaxCapacity parses the max capacity of backend connection pool, return default value if failed.
func InitStoreOperate ¶
func JSONToYAML ¶
func NewConfigWatcher ¶
func NewConfigWatcher(tenant string, storeOperate StoreOperator, pathInfo *PathInfo) (*configWatcher, error)
func WithCacheable ¶
func WithCacheable(open bool) option
WithCacheable set whether to enable the read cache mechanism
func WithReader ¶
func WithReader(open bool) option
WithReader Set whether to enable the read operation of the configuration center
func WithWatcher ¶
func WithWatcher(open bool) option
WithWatcher Set whether to enable the watch operation of the configuration center
func WithWriter ¶
func WithWriter(open bool) option
WithWriter Set whether to enable the write operation of the configuration center
Types ¶
type BootOptions ¶
type BootOptions struct { Spec `yaml:",inline"` Config *Options `yaml:"config" json:"config"` Listeners []*Listener `validate:"required,dive" yaml:"listeners" json:"listeners"` Registry *Registry `yaml:"registry" json:"registry"` Trace *Trace `yaml:"trace" json:"trace"` Supervisor *User `validate:"required,dive" yaml:"supervisor" json:"supervisor"` Logging *log.Config `validate:"required,dive" yaml:"logging" json:"logging"` }
func LoadBootOptions ¶
func LoadBootOptions(path string) (*BootOptions, error)
LoadBootOptions loads BootOptions from specified file path.
type CacheConfigReaderTest ¶
type CacheConfigReaderTest = cacheConfigReader
type Center ¶
type Center interface { io.Closer ConfigWriter ConfigReader ConfigWatcher // Tenant tenant info Tenant() string }
Center Configuration center for each tenant, tenant-level isolation
type CenterTest ¶
type CenterTest = center
type ClusterEvent ¶
type ClusterEvent struct { Name string Type DataSourceType SqlMaxLimit int Parameters ParametersMap GroupsEvent *GroupsEvent }
ClusterEvent cluster event
type Clusters ¶
type Clusters []*DataSourceCluster
func (Clusters) Diff ¶
func (c Clusters) Diff(old Clusters) *ClustersEvent
type ClustersEvent ¶
type ClustersEvent struct { AddClusters Clusters DeleteClusters Clusters UpdateClusters []*ClusterEvent }
ClustersEvent clusters event
func (ClustersEvent) Type ¶
func (e ClustersEvent) Type() EventType
type ColumnRule ¶
type ConfigReader ¶
type ConfigReader interface { io.Closer // LoadAll loads the full Tenant configuration, the first time it will be loaded remotely, // and then it will be directly assembled from the cache layer LoadAll(ctx context.Context) (*Tenant, error) // Load loads the full Tenant configuration, the first time it will be loaded remotely, // and then it will be directly assembled from the cache layer Load(ctx context.Context, item ConfigItem) (*Tenant, error) }
type ConfigWatcher ¶
type ConfigWatcher interface { io.Closer // Subscribe subscribes to all changes of an event by EventType Subscribe(ctx context.Context, et EventType, c EventCallback) (context.CancelFunc, error) }
type ConfigWatcherTest ¶
type ConfigWatcherTest configWatcher
type ConfigWriter ¶
type Configuration ¶
type Configuration struct { Spec `yaml:",inline"` Data *Data `validate:"required,structonly" yaml:"data" json:"data"` }
Configuration represents an Arana configuration.
func Load ¶
func Load(path string) (*Configuration, error)
Load loads the configuration from file path.
type Data ¶
type Data struct {
Tenants []*Tenant `validate:"required,dive" yaml:"tenants" json:"tenants"`
}
type DataRevision ¶
type DataRevision interface {
Revision() string
}
type DataSourceCluster ¶
type DataSourceCluster struct { Name string `yaml:"name" json:"name"` Type DataSourceType `yaml:"type" json:"type"` SqlMaxLimit int `default:"-1" yaml:"sql_max_limit" json:"sql_max_limit,omitempty"` Parameters ParametersMap `yaml:"parameters" json:"parameters"` Groups []*Group `yaml:"groups" json:"groups"` }
func (*DataSourceCluster) Diff ¶
func (d *DataSourceCluster) Diff(old *DataSourceCluster) *ClusterEvent
type DataSourceType ¶
type DataSourceType string
DataSourceType is the data source type
const ( DBMySQL DataSourceType = "mysql" DBPostgreSQL DataSourceType = "postgresql" )
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder decodes configuration.
func NewDecoder ¶
NewDecoder creates a Decoder from a reader.
type EventCallback ¶
type EventCallback func(e Event)
type EventType ¶
type EventType int32
const ( EventTypeTenants EventType EventTypeUsers EventTypeNodes EventTypeClusters EventTypeShardingRule EventTypeShadowRule )
type GroupEvent ¶
GroupEvent group event
type Groups ¶
type Groups []*Group
func (Groups) Diff ¶
func (g Groups) Diff(old Groups) *GroupsEvent
type GroupsEvent ¶
GroupsEvent groups event
type Listener ¶
type Listener struct { ProtocolType string `yaml:"protocol_type" json:"protocol_type"` SocketAddress *SocketAddress `yaml:"socket_address" json:"socket_address"` ServerVersion string `yaml:"server_version" json:"server_version"` }
type MatchRule ¶
type MatchRule struct { Operation []string `yaml:"operation" json:"operation"` MatchType string `yaml:"match_type" json:"match_type"` Attributes []*RuleAttribute `yaml:"attributes" json:"attributes"` }
type Node ¶
type Node struct { Name string `validate:"required" yaml:"name" json:"name"` Host string `validate:"required" yaml:"host" json:"host"` Port int `validate:"required" yaml:"port" json:"port"` Username string `validate:"required" yaml:"username" json:"username"` Password string `validate:"required" yaml:"password" json:"password"` Database string `validate:"required" yaml:"database" json:"database"` Parameters ParametersMap `yaml:"parameters" json:"parameters"` ConnProps map[string]interface{} `yaml:"conn_props" json:"conn_props,omitempty"` Weight string `default:"r10w10" yaml:"weight" json:"weight"` Labels map[string]string `yaml:"labels" json:"labels,omitempty"` }
type NodesEvent ¶
NodesEvent nodes event
func (NodesEvent) Type ¶
func (e NodesEvent) Type() EventType
type ParametersMap ¶
func (*ParametersMap) Camel ¶
func (pm *ParametersMap) Camel(name string) string
Camel underline to camel
func (*ParametersMap) LowerCaseFirstLetter ¶
func (pm *ParametersMap) LowerCaseFirstLetter(str string) string
LowerCaseFirstLetter lowercase letter
func (*ParametersMap) Merge ¶
func (pm *ParametersMap) Merge(parametersMap ParametersMap)
func (*ParametersMap) String ¶
func (pm *ParametersMap) String() string
type PathInfo ¶
type PathInfo struct { DefaultConfigSpecPath PathKey DefaultTenantBaseConfigPath PathKey DefaultConfigSysDBPath PathKey DefaultConfigDataNodesPath PathKey DefaultConfigDataUsersPath PathKey DefaultConfigDataSourceClustersPath PathKey DefaultConfigDataShardingRulePath PathKey DefaultConfigDataShadowRulePath PathKey ConfigKeyMapping map[PathKey]string ConfigEventMapping map[PathKey]EventType BuildEventMapping map[EventType]func(pre, cur *Tenant) Event ConfigValSupplier map[PathKey]func(cfg *Tenant) interface{} }
func NewPathInfo ¶
type ProtocolType ¶
type ProtocolType int32
ProtocolType protocol type enum
const ( Http ProtocolType = iota MySQL )
func (*ProtocolType) UnmarshalText ¶
func (t *ProtocolType) UnmarshalText(text []byte) error
type Rule ¶
type Rule struct { Columns []*ColumnRule `validate:"required" yaml:"columns" json:"columns"` Type string `validate:"required" yaml:"type" json:"type"` Expr string `validate:"required" yaml:"expr" json:"expr"` }
type RuleAttribute ¶
type ShadowRule ¶
type ShadowRule struct {
ShadowTables []*ShadowTable `yaml:"tables" json:"tables"`
}
func (*ShadowRule) Diff ¶
func (s *ShadowRule) Diff(old *ShadowRule) *ShadowRuleEvent
type ShadowRuleEvent ¶
type ShadowRuleEvent struct { AddTables []*ShadowTable UpdateTables []*ShadowTable DeleteTables []*ShadowTable }
ShadowRuleEvent shadow rule event
func (ShadowRuleEvent) Type ¶
func (e ShadowRuleEvent) Type() EventType
type ShadowTable ¶
type ShardingRule ¶
type ShardingRule struct {
Tables []*Table `yaml:"tables" json:"tables"`
}
func (*ShardingRule) Diff ¶
func (s *ShardingRule) Diff(old *ShardingRule) *ShardingRuleEvent
type ShardingRuleEvent ¶
ShardingRuleEvent sharding rule event
func (ShardingRuleEvent) Type ¶
func (e ShardingRuleEvent) Type() EventType
type SocketAddress ¶
type SocketAddress struct { Address string `default:"0.0.0.0" yaml:"address" json:"address"` Port int `default:"13306" yaml:"port" json:"port"` }
SocketAddress specify either a logical or physical address and port, which are used to tell server where to bind/listen, connect to upstream and find management servers
type Spec ¶
type Spec struct { Kind string `yaml:"kind" json:"kind,omitempty"` APIVersion string `yaml:"apiVersion" json:"apiVersion,omitempty"` LogPath string `yaml:"log_path" json:"log_path,omitempty"` SlowLogPath string `yaml:"slow_log_path" json:"slow_log_path,omitempty"` EnableLocalMathComputation bool `yaml:"enable_local_math_computation" json:"enable_local_math_computation,omitempty"` Metadata map[string]interface{} `yaml:"metadata" json:"metadata"` }
type StoreOperator ¶
type StoreOperator interface { io.Closer // Init plugin initialization Init(options map[string]interface{}) error // Save save a configuration data Save(key PathKey, val []byte) error // Get get a configuration Get(key PathKey) ([]byte, error) // Watch Monitor changes of the key Watch(key PathKey) (<-chan []byte, error) // Name plugin name Name() string }
StoreOperator config storage related plugins
func GetStoreOperate ¶
func GetStoreOperate() StoreOperator
type SubscribeResult ¶
type SubscribeResult struct { EventChan <-chan Event Cancel context.CancelFunc }
type Table ¶
type Table struct { Name string `validate:"required" yaml:"name" json:"name"` Sequence *Sequence `yaml:"sequence" json:"sequence"` DbRules []*Rule `yaml:"db_rules" json:"db_rules"` TblRules []*Rule `yaml:"tbl_rules" json:"tbl_rules"` Topology *Topology `validate:"required" yaml:"topology" json:"topology"` ShadowTopology *Topology `yaml:"shadow_topology" json:"shadow_topology"` Attributes map[string]string `yaml:"attributes" json:"attributes"` }
type Tenant ¶
type Tenant struct { Spec Name string `validate:"required" yaml:"name" json:"name"` Users []*User `validate:"required" yaml:"users" json:"users"` SysDB *Node `validate:"required" yaml:"sys_db" json:"sys_db"` DataSourceClusters []*DataSourceCluster `validate:"required,dive" yaml:"clusters" json:"clusters"` ShardingRule *ShardingRule `validate:"required,dive" yaml:"sharding_rule,omitempty" json:"sharding_rule,omitempty"` ShadowRule *ShadowRule `yaml:"shadow_rule,omitempty" json:"shadow_rule,omitempty"` Nodes map[string]*Node `validate:"required" yaml:"nodes" json:"nodes"` }
func NewEmptyTenant ¶
func NewEmptyTenant() *Tenant
type TenantOperator ¶
type TenantOperator interface { io.Closer // ListTenants lists all tenants. ListTenants() []string // CreateTenant creates tenant. CreateTenant(string) error // UpdateTenant update tenant. UpdateTenant(tenant string, newTenant string) error // RemoveTenant removes tenant. RemoveTenant(string) error // RemoveTenantUser removes a tenant user. RemoveTenantUser(tenant, username string) error // CreateTenantUser creates a user. CreateTenantUser(tenant, username, password string) error // UpdateTenantUser update user by username. UpdateTenantUser(tenant, newUsername, password, oldUsername string) error // UpsertNode creates a node, or updates a node. UpsertNode(tenant, node, name, host string, port int, username, password, database, weight string) error // RemoveNode removes a node. RemoveNode(tenant, name string) error // Subscribe subscribes tenants change Subscribe(ctx context.Context, c EventCallback) context.CancelFunc }
TenantOperator actions specific to tenant spaces
func LoadTenantOperator ¶
func LoadTenantOperator(cfg *BootOptions) (TenantOperator, error)
LoadTenantOperator loads tenant operator from boot option.
func LoadTenantOperatorFromPath ¶
func LoadTenantOperatorFromPath(path string) (TenantOperator, error)
LoadTenantOperatorFromPath loads tenant operator from specified file path.
func NewTenantOperator ¶
func NewTenantOperator(op StoreOperator) (TenantOperator, error)
NewTenantOperator create a tenant data operator
type Tenants ¶
type Tenants []string
func (Tenants) Diff ¶
func (t Tenants) Diff(old Tenants) *TenantsEvent
type TenantsEvent ¶
TenantsEvent tenants event
func (TenantsEvent) Type ¶
func (e TenantsEvent) Type() EventType
type Trace ¶
type Trace struct { Type string `default:"jaeger" yaml:"type" json:"type"` Address string `default:"http://localhost:14268/api/traces" yaml:"address" json:"address"` }
Trace Distributed tracing configuration, which is used to configure the collector type and address
type User ¶
type UsersEvent ¶
UsersEvent users event
func (UsersEvent) Type ¶
func (e UsersEvent) Type() EventType