Documentation ¶
Index ¶
- Variables
- func AcquireBuffer() *bytes.Buffer
- func AcquireStringsBuilder() *strings.Builder
- func CreatePool(f func() interface{}) func() *sync.Pool
- func DividesGenerate(prefix string, num int) string
- func NewDB(driver string, url string, c ConnConfiger) *sql.DB
- func ReleaseBuffer(b *bytes.Buffer)
- func ReleaseStringsBuilder(b *strings.Builder)
- type Cluster
- type ClusterConfig
- type ClusterConfiger
- type Config
- type Configer
- type ConnConfiger
- type DBHandler
- type DbConfiger
- type DbPartition
- type DbPartitioner
- type Decoder
- type MasterNode
- type MasterNodeConfiger
- type NopDbPartition
- type NopReplication
- type NopTablePartition
- type Option
- type Partition
- type PartitionConfig
- type PartitionConfiger
- type PreloadTablePartition
- type ReplicaNode
- type ReplicaNodeConfiger
- type ReplicaNodeOption
- type Replication
- type ReplicationConfig
- type ReplicationConfiger
- type Shard
- type ShardConfig
- func (s *ShardConfig) GetDbname() string
- func (s *ShardConfig) GetDriver() string
- func (s *ShardConfig) GetMasterUrl() string
- func (s *ShardConfig) GetMaxIdleConns() int
- func (s *ShardConfig) GetMaxLifetime() time.Duration
- func (s *ShardConfig) GetMaxOpenConns() int
- func (s *ShardConfig) GetReplicaUrls() []string
- func (s *ShardConfig) SetDbname(name string)
- type ShardConfiger
- type TablePartition
- type TablePartitionConfig
- type TablePartitionConfiger
- type TablePartitionNodeConfig
- type TableSelector
- type YamlClusterConfig
- type YamlConfig
- type YamlConnConfig
- type YamlDBConfig
- type YamlMasterConfig
- type YamlNodeConfig
- type YamlPartitionConfig
- type YamlReplicasConfig
- type YamlReplicationConfig
- type YamlShardConfig
- type YamlTablePartitionConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( GetBufferPool = CreatePool(func() interface{} { var b bytes.Buffer return &b }) )
View Source
var GetNopDbPartition = createNopDbPartition()
View Source
var GetNopTablePartition = createNopTablePartition()
View Source
var ( GetStringsBuilderPool = CreatePool(func() interface{} { var b bytes.Buffer return &b }) )
View Source
var (
NopDbPartitionError = errors.New("Empty DB Partition Config ")
)
Functions ¶
func AcquireBuffer ¶
func AcquireStringsBuilder ¶
func CreatePool ¶
func DividesGenerate ¶
func ReleaseBuffer ¶
func ReleaseStringsBuilder ¶
Types ¶
type ClusterConfig ¶
type ClusterConfig struct { ReplicationConfig ReplicationConfig PartitionConfig PartitionConfig }
func NewClusterConfig ¶
func NewClusterConfig(config *YamlClusterConfig) *ClusterConfig
func (*ClusterConfig) GetPartitionConfig ¶
func (c *ClusterConfig) GetPartitionConfig() *PartitionConfig
func (*ClusterConfig) GetReplicationConfig ¶
func (c *ClusterConfig) GetReplicationConfig() *ReplicationConfig
type ClusterConfiger ¶
type ClusterConfiger interface { GetReplicationConfig() *ReplicationConfig GetPartitionConfig() *PartitionConfig }
type Config ¶
type Config struct { Cluster *ClusterConfig Shards []*ShardConfig }
func NewConfig ¶
func NewConfig(conf *YamlConfig) *Config
func (*Config) GetClusterConfig ¶
func (c *Config) GetClusterConfig() *ClusterConfig
func (*Config) GetShardsConfig ¶
func (c *Config) GetShardsConfig() []*ShardConfig
type Configer ¶
type Configer interface { GetClusterConfig() *ClusterConfig GetShardsConfig() []*ShardConfig }
type ConnConfiger ¶
type DbConfiger ¶
type DbConfiger interface { GetDriver() string GetDbname() string SetDbname(string) ConnConfiger }
type DbPartition ¶
type DbPartition struct { Total int // contains filtered or unexported fields }
type DbPartitioner ¶
type DbPartitioner interface { Pick(prefix string, index int) string Partition([]byte, string) int TableSelector }
func NewPartition ¶
func NewPartition(conf PartitionConfiger) (DbPartitioner, error)
type MasterNode ¶
type MasterNode struct {
// contains filtered or unexported fields
}
func NewMasterNode ¶
func NewMasterNode(driver string, c MasterNodeConfiger) *MasterNode
func (*MasterNode) GetDB ¶
func (m *MasterNode) GetDB() *sql.DB
type MasterNodeConfiger ¶
type MasterNodeConfiger interface { GetMasterUrl() string DbConfiger }
type NopDbPartition ¶
type NopDbPartition struct { }
func (*NopDbPartition) GetTablePartition ¶
func (p *NopDbPartition) GetTablePartition(table string) TablePartition
type NopReplication ¶
type NopReplication struct { }
func (*NopReplication) Replicate ¶
func (lb *NopReplication) Replicate(int) int
type NopTablePartition ¶
type NopTablePartition struct { }
func (*NopTablePartition) GetTableChunkTotal ¶
func (p *NopTablePartition) GetTableChunkTotal() int
func (*NopTablePartition) GetTableTotal ¶
func (p *NopTablePartition) GetTableTotal() int
func (*NopTablePartition) Partition ¶
func (p *NopTablePartition) Partition(key []byte) int
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func AddExecutor ¶
func AddExecutor(f func(*sql.DB, DBHandler, TableSelector)) Option
func AddMaster ¶
func AddMaster(conf ShardConfiger) Option
func AddReplica ¶
func AddReplica(conf ShardConfiger, opts ...ReplicaNodeOption) Option
func AddTablePartition ¶
func AddTablePartition(selector TableSelector) Option
type Partition ¶
type Partition = distributed.Partition
type PartitionConfig ¶
type PartitionConfig struct { Type string DbTotal int Table *TablePartitionConfig }
func (*PartitionConfig) GetDbTotal ¶
func (p *PartitionConfig) GetDbTotal() int
func (*PartitionConfig) GetTablePartitionConfig ¶
func (p *PartitionConfig) GetTablePartitionConfig() *TablePartitionConfig
func (*PartitionConfig) GetType ¶
func (p *PartitionConfig) GetType() string
type PartitionConfiger ¶
type PartitionConfiger interface { GetDbTotal() int GetType() string GetTablePartitionConfig() *TablePartitionConfig }
type PreloadTablePartition ¶
type PreloadTablePartition struct { Table string TableTotal int TableChunkTotal int // contains filtered or unexported fields }
func (*PreloadTablePartition) GetTableChunkTotal ¶
func (p *PreloadTablePartition) GetTableChunkTotal() int
func (*PreloadTablePartition) GetTableTotal ¶
func (p *PreloadTablePartition) GetTableTotal() int
func (*PreloadTablePartition) Partition ¶
func (p *PreloadTablePartition) Partition(key []byte) int
type ReplicaNode ¶
type ReplicaNode struct {
// contains filtered or unexported fields
}
func NewReplicasNode ¶
func NewReplicasNode(driver string, c ReplicaNodeConfiger, opts ...ReplicaNodeOption) *ReplicaNode
func (*ReplicaNode) GetDB ¶
func (r *ReplicaNode) GetDB() *sql.DB
func (*ReplicaNode) SetReplication ¶
func (r *ReplicaNode) SetReplication(lb Replication)
func (*ReplicaNode) WithOptions ¶
func (r *ReplicaNode) WithOptions(opts ...ReplicaNodeOption) *ReplicaNode
type ReplicaNodeConfiger ¶
type ReplicaNodeConfiger interface { GetReplicaUrls() []string DbConfiger }
type ReplicaNodeOption ¶
type ReplicaNodeOption interface {
// contains filtered or unexported methods
}
func AddReplication ¶
func AddReplication(lb Replication) ReplicaNodeOption
type Replication ¶
type Replication = distributed.Replication
func NewReplication ¶
func NewReplication(conf ReplicationConfiger) Replication
type ReplicationConfig ¶
type ReplicationConfig struct {
YamlReplicationConfig
}
func NewReplicationConfig ¶
func NewReplicationConfig(conf *YamlReplicationConfig) *ReplicationConfig
func (*ReplicationConfig) GetType ¶
func (r *ReplicationConfig) GetType() string
type ReplicationConfiger ¶
type ReplicationConfiger interface {
GetType() string
}
type Shard ¶
type Shard struct { Master *MasterNode Replica *ReplicaNode Executor func(*sql.DB, DBHandler, TableSelector) // contains filtered or unexported fields }
func NewShard ¶
func NewShard(conf *ShardConfig, options ...Option) *Shard
func (*Shard) WithOptions ¶
type ShardConfig ¶
type ShardConfig struct { YamlDBConfig YamlShardConfig // contains filtered or unexported fields }
func NewShardConfig ¶
func NewShardConfig(shard *YamlShardConfig, db *YamlDBConfig, r *YamlReplicationConfig) *ShardConfig
func (*ShardConfig) GetDbname ¶
func (s *ShardConfig) GetDbname() string
func (*ShardConfig) GetDriver ¶
func (s *ShardConfig) GetDriver() string
func (*ShardConfig) GetMasterUrl ¶
func (s *ShardConfig) GetMasterUrl() string
func (*ShardConfig) GetMaxIdleConns ¶
func (s *ShardConfig) GetMaxIdleConns() int
func (*ShardConfig) GetMaxLifetime ¶
func (s *ShardConfig) GetMaxLifetime() time.Duration
func (*ShardConfig) GetMaxOpenConns ¶
func (s *ShardConfig) GetMaxOpenConns() int
func (*ShardConfig) GetReplicaUrls ¶
func (s *ShardConfig) GetReplicaUrls() []string
func (*ShardConfig) SetDbname ¶
func (s *ShardConfig) SetDbname(name string)
type ShardConfiger ¶
type ShardConfiger interface { MasterNodeConfiger ReplicaNodeConfiger ReplicationConfiger }
type TablePartition ¶
type TablePartition interface { Select(key []byte, table string) string Partition(key []byte) int GetTableTotal() int GetTableChunkTotal() int }
func NewTablePartition ¶
func NewTablePartition(conf TablePartitionConfiger) TablePartition
type TablePartitionConfig ¶
type TablePartitionConfig struct { DbTotal int TableConfig []*TablePartitionNodeConfig }
func NewTablePartitionConfig ¶
func NewTablePartitionConfig(conf []*YamlTablePartitionConfig, dbTotal int) *TablePartitionConfig
分表
func (*TablePartitionConfig) GetTablePartitionNodeConfig ¶
func (c *TablePartitionConfig) GetTablePartitionNodeConfig() []TablePartitionConfiger
type TablePartitionConfiger ¶
type TablePartitionNodeConfig ¶
func (*TablePartitionNodeConfig) GetDbTotal ¶
func (t *TablePartitionNodeConfig) GetDbTotal() int
func (*TablePartitionNodeConfig) GetName ¶
func (t *TablePartitionNodeConfig) GetName() string
func (*TablePartitionNodeConfig) GetTableTotal ¶
func (t *TablePartitionNodeConfig) GetTableTotal() int
type TableSelector ¶
type YamlClusterConfig ¶
type YamlClusterConfig struct { Replication YamlReplicationConfig `yaml:"replication"` Partition YamlPartitionConfig `yaml:"partition"` }
type YamlConfig ¶
type YamlConfig struct { Cluster YamlClusterConfig `yaml:"cluster"` Db YamlDBConfig `yaml:"db"` Shards []*YamlShardConfig `yaml:"shards"` }
func ParseYamlConfig ¶
func ParseYamlConfig(d Decoder) (*YamlConfig, error)
func ParseYamlConfigFile ¶
func ParseYamlConfigFile(path string) (*YamlConfig, error)
type YamlConnConfig ¶
type YamlDBConfig ¶
type YamlDBConfig struct { Driver string `yaml:"driver"` Dbname string `yaml:"dbname"` Conn YamlConnConfig `yaml:"conn"` }
type YamlMasterConfig ¶
type YamlMasterConfig struct { Host string `yaml:"host"` YamlNodeConfig `yaml:",inline"` }
type YamlNodeConfig ¶
type YamlPartitionConfig ¶
type YamlPartitionConfig struct { Type string `yaml:"type"` DbTotal int `yaml:"db_total"` Table []*YamlTablePartitionConfig `yaml:"table"` }
type YamlReplicasConfig ¶
type YamlReplicasConfig struct { Hosts []string `yaml:"hosts"` YamlNodeConfig `yaml:",inline"` }
type YamlReplicationConfig ¶
type YamlReplicationConfig struct {
Type string `yaml:"type"`
}
type YamlShardConfig ¶
type YamlShardConfig struct { Master YamlMasterConfig `yaml:"master"` Replicas YamlReplicasConfig `yaml:"replicas"` }
Click to show internal directories.
Click to hide internal directories.