config

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

README

配置中心

Root

ARANA_ROOT=/arana

Tenants

# 路径 Key
${ARANA_ROOT}/v1/tenants/<tenant>
/arana/v1/tenants/arana

# 存储内容
- name: arana
  users:
    - username: root
      password: "123456"
    - username: arana
      password: "123456"

Nodes

# 路径 Key
${ARANA_ROOT}/v1/tenants/<tenant>/nodes/<node>
/arana/v1/tenants/arana/nodes/node0
/arana/v1/tenants/arana/nodes/node1

# 存储内容
- name: node0
  host: arana-mysql
  port: 3306
  username: root
  password: "123456"
  database: employees_0000
  weight: r10w10
  parameters:

Data Source Clusters

# 路径 Key
${ARANA_ROOT}/v1/tenants/<tenant>/clusters/<cluster>/groups/<group>/nodes/<node>
/arana/v1/tenants/arana/clusters/employees/groups/employees_0000/nodes/node0
/arana/v1/tenants/arana/clusters/employees/groups/employees_0000/nodes/node0_r_0

# 存储内容
- name: node0
  host: arana-mysql
  port: 3306
  username: root
  password: "123456"
  database: employees_0000
  weight: r10w10
  parameters:


# 路径 Key
${ARANA_ROOT}/v1/tenants/<tenant>/clusters/<cluster>/groups/<group>
/arana/v1/tenants/arana/clusters/employees/groups/employees_0000
/arana/v1/tenants/arana/clusters/employees/groups/employees_0001

# 存储内容
nodes:
  - node0
  - node1

Sharding Rule

# 路径 Key
${ARANA_ROOT}/v1/tenants/<tenant>/clusters/<cluster>/tables/<table>
/arana/v1/tenants/arana/clusters/employees/tables/student
/arana/v1/tenants/arana/clusters/employees/tables/order

# 存储内容
- name: student
  allow_full_scan: true
  sequence:
    type: snowflake
    option:
  db_rules:
    - column: uid
      type: scriptExpr
      expr: parseInt($value % 32 / 8)
  tbl_rules:
    - column: uid
      type: scriptExpr
      expr: $value % 32
      step: 32
  topology:
    db_pattern: employees_${0000..0003}
    tbl_pattern: student_${0000..0031}
  attributes:
    sqlMaxLimit: -1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfigKeyMapping map[PathKey]string = map[PathKey]string{
		DefaultConfigMetadataPath:           "metadata",
		DefaultConfigDataTenantsPath:        "data.tenants",
		DefaultConfigDataListenersPath:      "data.listeners",
		DefaultConfigDataSourceClustersPath: "data.clusters",
		DefaultConfigDataShardingRulePath:   "data.sharding_rule",
	}
)

Functions

func GetConnPropCapacity

func GetConnPropCapacity(connProps map[string]interface{}, defaultValue int) int

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

func GetConnPropMaxCapacity(connProps map[string]interface{}, defaultValue int) int

GetConnPropMaxCapacity parses the max capacity of backend connection pool, return default value if failed.

func Init

func Init(name string, options map[string]interface{}) error

func Register

func Register(s StoreOperate)

Register register store plugin

func Validate

func Validate(cfg *Configuration) error

Validate validates the input configuration.

Types

type Center

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

func NewCenter

func NewCenter(options ConfigOptions) (*Center, error)

func (*Center) Close

func (c *Center) Close() error

func (*Center) ImportConfiguration

func (c *Center) ImportConfiguration(cfg *Configuration) error

func (*Center) Load

func (c *Center) Load() (*Configuration, error)

func (*Center) LoadContext

func (c *Center) LoadContext(ctx context.Context) (*Configuration, error)

func (*Center) Persist

func (c *Center) Persist() error

func (*Center) PersistContext

func (c *Center) PersistContext(ctx context.Context) error

type Changeable

type Changeable interface {
	Name() string
	Sign() string
}

type ConfigOptions

type ConfigOptions struct {
	StoreName string                 `yaml:"name"`
	Options   map[string]interface{} `yaml:"options"`
}

type Configuration

type Configuration struct {
	Kind       string                 `yaml:"kind" json:"kind,omitempty"`
	APIVersion string                 `yaml:"apiVersion" json:"apiVersion,omitempty"`
	Metadata   map[string]interface{} `yaml:"metadata" json:"metadata"`
	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 {
	Listeners          []*Listener          `validate:"required,dive" yaml:"listeners" json:"listeners"`
	Tenants            []*Tenant            `validate:"required,dive" yaml:"tenants" json:"tenants"`
	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"`
}

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"`
	Tenant      string         `yaml:"tenant" json:"tenant"`
	Parameters  ParametersMap  `yaml:"parameters" json:"parameters"`
	Groups      []*Group       `yaml:"groups" json:"groups"`
}

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

func NewDecoder(reader io.Reader) *Decoder

NewDecoder creates a Decoder from a reader.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) error

type Group

type Group struct {
	Name  string  `yaml:"name" json:"name"`
	Nodes []*Node `yaml:"nodes" json:"nodes"`
}

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"`
}

func (*Node) GetReadAndWriteWeight

func (d *Node) GetReadAndWriteWeight() (int, int, error)

func (*Node) String

func (d *Node) String() string

type Observer

type Observer func()

type ParametersMap

type ParametersMap map[string]string

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 PathKey

type PathKey string

PathKey config path key type

const (
	DefaultConfigPath                   PathKey = "/arana-db/config"
	DefaultConfigMetadataPath           PathKey = "/arana-db/config/metadata"
	DefaultConfigDataListenersPath      PathKey = "/arana-db/config/data/listeners"
	DefaultConfigDataSourceClustersPath PathKey = "/arana-db/config/data/dataSourceClusters"
	DefaultConfigDataShardingRulePath   PathKey = "/arana-db/config/data/shardingRule"
	DefaultConfigDataTenantsPath        PathKey = "/arana-db/config/data/tenants"
)

type Prop

type Prop struct {
	Operation string `yaml:"operation" json:"operation"`
	Column    string `yaml:"column" json:"column"`
	Value     string `yaml:"value" json:"value"`
	Regex     string `yaml:"regex" json:"regex"`
}

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 {
	Column string `validate:"required" yaml:"column" json:"column"`
	Type   string `validate:"required" yaml:"type" json:"type"`
	Expr   string `validate:"required" yaml:"expr" json:"expr"`
	Step   int    `yaml:"step" json:"step"`
}

type RuleAttribute

type RuleAttribute struct {
	Column string `yaml:"column" json:"column"`
	Value  string `yaml:"value,omitempty" json:"value,omitempty"`
	Regex  string `yaml:"regex,omitempty" json:"regex,omitempty"`
}

type Sequence

type Sequence struct {
	Type   string            `yaml:"type" json:"type"`
	Option map[string]string `yaml:"option" json:"option"`
}

type ShadowRule

type ShadowRule struct {
	ShadowTables []*ShadowTable `yaml:"tables" json:"tables"`
}

type ShadowTable

type ShadowTable struct {
	Name       string       `yaml:"name" json:"name"`
	Enable     bool         `yaml:"enable" json:"enable"`
	GroupNode  string       `yaml:"group_node" json:"group_node"`
	MatchRules []*MatchRule `yaml:"match_rules" json:"match_rules"`
}

type ShardingRule

type ShardingRule struct {
	Tables []*Table `yaml:"tables" json:"tables"`
}

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 StoreOperate

type StoreOperate 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
}

StoreOperate config storage related plugins

func GetStoreOperate

func GetStoreOperate() (StoreOperate, error)

type Table

type Table struct {
	Name           string            `validate:"required" yaml:"name" json:"name"`
	Sequence       *Sequence         `yaml:"sequence" json:"sequence"`
	AllowFullScan  bool              `yaml:"allow_full_scan" json:"allow_full_scan,omitempty"`
	DbRules        []*Rule           `yaml:"db_rules" json:"db_rules"`
	TblRules       []*Rule           `yaml:"tbl_rules" json:"tbl_rules"`
	Topology       *Topology         `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 {
	Name  string  `validate:"required" yaml:"name" json:"name"`
	Users []*User `validate:"required" yaml:"users" json:"users"`
}

type Topology

type Topology struct {
	DbPattern  string `validate:"required" yaml:"db_pattern" json:"db_pattern"`
	TblPattern string `validate:"required" yaml:"tbl_pattern" json:"tbl_pattern"`
}

type User

type User struct {
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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