models

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 18 Imported by: 28

Documentation

Index

Constants

View Source
const (
	// MinNumKey min int64
	MinNumKey = math.MinInt64
	// MaxNumKey max int64
	MaxNumKey = math.MaxInt64
)
View Source
const (
	ShardDefault         = "default"
	ShardGlobal          = "global"
	ShardLinked          = "linked"
	ShardMod             = "mod"
	ShardHash            = "hash"
	ShardRange           = "range"
	ShardYear            = "date_year"
	ShardMonth           = "date_month"
	ShardDay             = "date_day"
	ShardMycatMod        = "mycat_mod"
	ShardMycatLong       = "mycat_long"
	ShardMycatString     = "mycat_string"
	ShardMycatMURMUR     = "mycat_murmur"
	ShardMycatPaddingMod = "mycat_padding_mod"

	// PartitionLength length of partition
	PartitionLength = 1024

	// mod padding
	PaddingModLeftEnd  = 0
	PaddingModRightEnd = 1

	PaddingModDefaultPadFrom   = PaddingModRightEnd
	PaddingModDefaultPadLength = 18
	PaddingModDefaultModBegin  = 10
	PaddingModDefaultModEnd    = 16
	PaddingModDefaultMod       = 2
)

constants of shard type

View Source
const (
	ConfigFile = "file"
	ConfigEtcd = "etcd"
)

config type

View Source
const (
	// 只读
	ReadOnly = 1
	// 可读可写
	ReadWrite = 2
)

用户只读标识 read write privileges

View Source
const (
	// NoReadWriteSplit 非读写分离
	NoReadWriteSplit = 0
	// ReadWriteSplit 读写分离
	ReadWriteSplit = 1
	// StatisticUser 统计用户
	StatisticUser = 1
)

用户读写分离标识

Variables

This section is empty.

Functions

func IsMycatShardingRule added in v1.0.2

func IsMycatShardingRule(ruleType string) bool

func JSONDecode

func JSONDecode(v interface{}, data []byte) error

JSONDecode parses the JSON-encoded data and stores the result in the value pointed to by v

func JSONEncode

func JSONEncode(v interface{}) []byte

JSONEncode return json encoding of v

func ParseDayRange added in v1.0.2

func ParseDayRange(dateRange string) ([]int, error)

ParseDayRange return date of daynumber by order 20151201-20151205 20151201,20151202,20151203,20151204,20151205

func ParseMonthRange added in v1.0.2

func ParseMonthRange(dateRange string) ([]int, error)

ParseMonthRange return date of month by order 201510-201512 201510,201511,201512

func ParseYearRange added in v1.0.2

func ParseYearRange(dateRange string) ([]int, error)

ParseYearRange return date of year by order 2013-2015 2013,2014,2015

Types

type CCConfig

type CCConfig struct {
	Addr          string `ini:"addr"`
	AdminUserName string `ini:"admin_username"`
	AdminPassword string `ini:"admin_password"`
	ProxyUserName string `ini:"proxy_username"`
	ProxyPassword string `ini:"proxy_password"`
	// etcd 相关配置
	CoordinatorAddr string `ini:"coordinator_addr"`
	CoordinatorRoot string `ini:"coordinator_root"`
	UserName        string `ini:"username"`
	Password        string `ini:"password"`

	DefaultCluster string `ini:"default_cluster"`

	LogPath     string `ini:"log_path"`
	LogLevel    string `ini:"log_level"`
	LogFileName string `ini:"log_filename"`
	LogOutput   string `ini:"log_output"`

	EncryptKey string `ini:"encrypt_key"`
}

CCConfig means gaea cc config

func ParseCCConfig

func ParseCCConfig(cfgFile string) (*CCConfig, error)

ParseCCConfig parser gaea cc config from file

func (*CCConfig) Verify

func (cc *CCConfig) Verify() error

Verify verify cc config

type Client

type Client interface {
	Create(path string, data []byte) error
	Update(path string, data []byte) error
	UpdateWithTTL(path string, data []byte, ttl time.Duration) error
	Delete(path string) error
	Read(path string) ([]byte, error)
	List(path string) ([]string, error)
	Close() error
	BasePrefix() string
}

Client client interface

func NewClient

func NewClient(configType, addr, username, password, root string) Client

NewClient constructor to create client by case etcd/file/zk etc.

type GlobalSequence

type GlobalSequence struct {
	DB        string `json:"db"`
	Table     string `json:"table"`
	Type      string `json:"type"`       // 全局序列号类型,目前只兼容mycat的数据库方式
	SliceName string `json:"slice_name"` // 对应sequence表所在的分片,默认都在0号片
	PKName    string `json:"pk_name"`    // 全局序列号字段名称
}

GlobalSequence means config of global sequences with different types

func (*GlobalSequence) Encode

func (p *GlobalSequence) Encode() []byte

Encode means encode for easy use

type Namespace

type Namespace struct {
	OpenGeneralLog   bool              `json:"open_general_log"`
	IsEncrypt        bool              `json:"is_encrypt"` // true: 加密存储 false: 非加密存储,目前加密Slice、User中的用户名、密码
	Name             string            `json:"name"`
	Online           bool              `json:"online"`
	ReadOnly         bool              `json:"read_only"`
	AllowedDBS       map[string]bool   `json:"allowed_dbs"`
	DefaultPhyDBS    map[string]string `json:"default_phy_dbs"`
	SlowSQLTime      string            `json:"slow_sql_time"`
	BlackSQL         []string          `json:"black_sql"`
	AllowedIP        []string          `json:"allowed_ip"`
	Slices           []*Slice          `json:"slices"`
	ShardRules       []*Shard          `json:"shard_rules"`
	Users            []*User           `json:"users"` // 客户端接入proxy用户,每个用户可以设置读写分离、读写权限等
	DefaultSlice     string            `json:"default_slice"`
	GlobalSequences  []*GlobalSequence `json:"global_sequences"`
	DefaultCharset   string            `json:"default_charset"`
	DefaultCollation string            `json:"default_collation"`
}

Namespace means namespace model stored in etcd

func (*Namespace) Decrypt added in v1.0.1

func (n *Namespace) Decrypt(key string) (err error)

Decrypt decrypt user/password in namespace

func (*Namespace) Encode

func (n *Namespace) Encode() []byte

Encode encode json

func (*Namespace) Encrypt added in v1.0.1

func (n *Namespace) Encrypt(key string) (err error)

Encrypt encrypt user/password in namespace

func (*Namespace) Verify

func (n *Namespace) Verify() error

Verify verify namespace contents

type NumKeyRange added in v1.0.2

type NumKeyRange struct {
	Start int64
	End   int64
}

NumKeyRange [start,end)

func ParseNumSharding added in v1.0.2

func ParseNumSharding(Locations []int, TableRowLimit int) ([]NumKeyRange, error)

ParseNumSharding parse num shard

func (NumKeyRange) Contains added in v1.0.2

func (kr NumKeyRange) Contains(i int64) bool

Contains check if range contains i

func (NumKeyRange) MapKey added in v1.0.2

func (kr NumKeyRange) MapKey() string

MapKey key range

func (NumKeyRange) String added in v1.0.2

func (kr NumKeyRange) String() string

type Proxy

type Proxy struct {
	// config type
	ConfigType string `ini:"config_type"`

	// 文件配置类型内容
	FileConfigPath string `ini:"file_config_path"`

	// etcd 相关配置
	CoordinatorAddr string `ini:"coordinator_addr"`
	CoordinatorRoot string `ini:"coordinator_root"`
	UserName        string `ini:"username"`
	Password        string `ini:"password"`

	// 服务相关信息
	Environ string `ini:"environ"`
	Service string `ini:"service_name"`
	Cluster string `ini:"cluster_name"`

	LogPath     string `ini:"log_path"`
	LogLevel    string `ini:"log_level"`
	LogFileName string `ini:"log_filename"`
	LogOutput   string `ini:"log_output"`

	ProtoType      string `ini:"proto_type"`
	ProxyAddr      string `ini:"proxy_addr"`
	AdminAddr      string `ini:"admin_addr"`
	AdminUser      string `ini:"admin_user"`
	AdminPassword  string `ini:"admin_password"`
	SlowSQLTime    int64  `ini:"slow_sql_time"`
	SessionTimeout int    `ini:"session_timeout"`

	// 监控配置
	StatsEnabled  string `ini:"stats_enabled"`  // set true to enable stats
	StatsInterval int    `ini:"stats_interval"` // set stats interval of connect pool

	EncryptKey string `ini:"encrypt_key"`
}

Proxy means proxy structure of proxy config

func ParseProxyConfigFromFile

func ParseProxyConfigFromFile(cfgFile string) (*Proxy, error)

ParseProxyConfigFromFile parser proxy config from file

func (*Proxy) Verify

func (p *Proxy) Verify() error

Verify verify proxy config

type ProxyInfo

type ProxyInfo struct {
	Token     string `json:"token"`
	StartTime string `json:"start_time"`

	IP        string `json:"ip"`
	ProtoType string `json:"proto_type"`
	ProxyPort string `json:"proxy_port"`
	AdminPort string `json:"admin_port"`

	Pid int    `json:"pid"`
	Pwd string `json:"pwd"`
	Sys string `json:"sys"`
}

ProxyInfo for report proxy information

func (*ProxyInfo) Encode

func (p *ProxyInfo) Encode() []byte

Encode encode proxy info

type ProxyMonitorMetric

type ProxyMonitorMetric struct {
	Token     string `json:"token"` //目前同AdminAddr
	StartTime string `json:"start_time"`

	IP        string `json:"ip"`
	AdminPort string `json:"admin_port"`
	ProxyPort string `json:"proxy_port"`

	Pid int    `json:"pid"`
	Pwd string `json:"pwd"`
	Sys string `json:"sys"`
}

ProxyMonitorMetric proxy register information

func (*ProxyMonitorMetric) Encode

func (p *ProxyMonitorMetric) Encode() []byte

Encode encode jsosn

type Shard

type Shard struct {
	DB            string   `json:"db"`
	Table         string   `json:"table"`
	ParentTable   string   `json:"parent_table"`
	Type          string   `json:"type"` // 表类型: 包括分表如hash/range/data,关联表如: linked 全局表如: global等
	Key           string   `json:"key"`
	Locations     []int    `json:"locations"`
	Slices        []string `json:"slices"`
	DateRange     []string `json:"date_range"`
	TableRowLimit int      `json:"table_row_limit"`

	// only used in mycat logic database (schema)
	Databases []string `json:"databases"`

	// used in mycat partition long shard and partition string shard
	PartitionCount  string `json:"partition_count"`
	PartitionLength string `json:"partition_length"`

	// used in mycat partition string shard
	HashSlice string `json:"hash_slice"`

	// used in mycat murmur hash shard
	Seed               string `json:"seed"`
	VirtualBucketTimes string `json:"virtual_bucket_times"`

	// used in mycat padding mod shard
	PadFrom   string `json:"pad_from"`
	PadLength string `json:"pad_length"`
	ModBegin  string `json:"mod_begin"`
	ModEnd    string `json:"mod_end"`
}

Shard means shard model in etcd

func (*Shard) Encode

func (s *Shard) Encode() []byte

Encode encode json

type Slice

type Slice struct {
	Name            string   `json:"name"`
	UserName        string   `json:"user_name"`
	Password        string   `json:"password"`
	Master          string   `json:"master"`
	Slaves          []string `json:"slaves"`
	StatisticSlaves []string `json:"statistic_slaves"`

	Capacity    int `json:"capacity"`     // connection pool capacity
	MaxCapacity int `json:"max_capacity"` // max connection pool capacity
	IdleTimeout int `json:"idle_timeout"` // close backend direct connection after idle_timeout,unit: seconds
}

Slice means config model of slice

type Store

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

Store means exported client to use

func NewStore

func NewStore(client Client) *Store

NewStore constructor of Store

func (*Store) Close

func (s *Store) Close() error

Close close store

func (*Store) CreateProxy

func (s *Store) CreateProxy(p *ProxyInfo) error

CreateProxy create proxy model

func (*Store) DelNamespace

func (s *Store) DelNamespace(name string) error

DelNamespace delete namespace

func (*Store) DeleteProxy

func (s *Store) DeleteProxy(token string) error

DeleteProxy delete proxy path

func (*Store) ListNamespace

func (s *Store) ListNamespace() ([]string, error)

ListNamespace list namespace

func (*Store) ListProxyMonitorMetrics

func (s *Store) ListProxyMonitorMetrics() (map[string]*ProxyMonitorMetric, error)

ListProxyMonitorMetrics list proxies in proxy register path

func (*Store) LoadNamespace

func (s *Store) LoadNamespace(key, name string) (*Namespace, error)

LoadNamespace load namespace value

func (*Store) NamespaceBase

func (s *Store) NamespaceBase() string

NamespaceBase return namespace path base

func (*Store) NamespacePath

func (s *Store) NamespacePath(name string) string

NamespacePath concat namespace path

func (*Store) ProxyBase

func (s *Store) ProxyBase() string

ProxyBase return proxy path base

func (*Store) ProxyPath

func (s *Store) ProxyPath(token string) string

ProxyPath concat proxy path

func (*Store) UpdateNamespace

func (s *Store) UpdateNamespace(p *Namespace) error

UpdateNamespace update namespace path with data

type User

type User struct {
	UserName      string `json:"user_name"`
	Password      string `json:"password"`
	Namespace     string `json:"namespace"`
	RWFlag        int    `json:"rw_flag"`        //1: 只读 2:读写
	RWSplit       int    `json:"rw_split"`       //0: 不采用读写分离 1:读写分离
	OtherProperty int    `json:"other_property"` // 1:统计用户
}

User meand user struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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