Documentation ¶
Index ¶
- Variables
- func AcquireBuffer() *bytes.Buffer
- func AcquireStringsBuilder() *strings.Builder
- func CreatePool(f func() interface{}) func() *sync.Pool
- func NewDB(driver string, url string, c ConnConfig) *sql.DB
- func ProvideDynamicRe(conf *Config) (map[string]*sql.DB, error)
- func ProvideYamlConfigFile(path string) (*os.File, func(), error)
- func ReleaseBuffer(b *bytes.Buffer)
- func ReleaseStringsBuilder(b *strings.Builder)
- type AnnuallyDbSelector
- type AnnuallyTableSelector
- type Cluster
- type Config
- type ConnConfig
- type DBHandler
- type DailyDbSelector
- type DailyTableSelector
- type DbConfig
- func (c DbConfig) GetConn() ConnConfig
- func (c DbConfig) GetDbname() string
- func (c DbConfig) GetDriver() string
- func (c DbConfig) GetHost() string
- func (c DbConfig) GetParams() map[string]string
- func (c DbConfig) GetPassword() string
- func (c DbConfig) GetProtocol() string
- func (c DbConfig) GetUrl(dbname string) string
- func (c DbConfig) GetUser() string
- type DbExecutor
- type DbSelector
- type Decoder
- type DynamicCluster
- type MonthlyDbSelector
- type MonthlyTableSelector
- type Partition
- type Replication
- type RoundRobinSelector
- type Shard
- type ShardConfig
- type Sharding
- type ShardingConfig
- type ShardingTableConfig
- type StandardSharding
- func (s *StandardSharding) Allocation(i int, dbname string, params ...interface{}) string
- func (s *StandardSharding) GetDbname() string
- func (s *StandardSharding) Select(table string, key []byte, params ...interface{}) (int, int, *bytes.Buffer)
- func (s *StandardSharding) TableSelector() TableSelector
- type StandardTableSelector
- type StaticCluster
- type StaticShard
- type TableSelector
- type YamlClusterConfig
- type YamlConfig
- type YamlConnConfig
- type YamlDBConfig
- type YamlDecoder
- type YamlMasterConfig
- type YamlNodeConfig
- type YamlReplicasConfig
- type YamlShardingConfig
- type YamlShardsConfig
- type YamlTableShardingConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrShardPicker = errors.New("pick shard error") ErrShardPickerOverLimit = errors.New("pick shard over limit") )
View Source
var ( StaticClusterSet = wire.NewSet( wire.Bind(new(Cluster), new(*StaticCluster)), wire.Struct(new(StaticCluster), "*"), ProvideStaticShards, ) StandardShardingSet = wire.NewSet( wire.Bind(new(Sharding), new(*StandardSharding)), ProvideStandardSharding, ) RoundRobinLBSet = wire.NewSet( wire.Bind(new(Replication), new(*RoundRobinSelector)), ProvideRoundRobinSelector, ) DefaultDbExecutorSet = wire.NewSet( wire.Value(DefaultDBExecutor), ) DefaultTableSelectorSet = wire.NewSet( wire.Bind(new(TableSelector), new(*StandardTableSelector)), ProvideStandardTableSelector, ) DailyTableSelectorSet = wire.NewSet( wire.Bind(new(TableSelector), new(*DailyTableSelector)), ProvideDailyTableSelector, ) MonthlyTableSelectorSet = wire.NewSet( wire.Bind(new(TableSelector), new(*MonthlyTableSelector)), ProvideMonthlyTableSelector, ) AnnuallyTableSelectorSet = wire.NewSet( wire.Bind(new(TableSelector), new(*AnnuallyTableSelector)), ProvideAnnuallyTableSelector, ) DefaultPartitionSet = wire.NewSet( wire.Bind(new(Partition), new(*distributed.ModularHash)), distributed.ModularHashIEEE, ) )
View Source
var ( DynamicClusterSet = wire.NewSet( wire.Bind(new(Cluster), new(*DynamicCluster)), wire.Struct(new(DynamicCluster), "*"), ProvideDynamicRe, ) DailyDbSelectorSet = wire.NewSet( wire.Bind(new(DbSelector), new(*DailyDbSelector)), ProvideDailyDbSelector, ) MonthlyDbSelectorSet = wire.NewSet( wire.Bind(new(DbSelector), new(*MonthlyDbSelector)), ProvideMonthlyDbSelector, ) AnnuallyDbSelectorSet = wire.NewSet( wire.Bind(new(DbSelector), new(*AnnuallyDbSelector)), ProvideAnnuallyDbSelector, ) )
View Source
var ( DefaultConfigSet = wire.NewSet( defaultYamlConfigSet, ProvideConfig, ) )
View Source
var ( GetBufferPool = CreatePool(func() interface{} { var b bytes.Buffer return &b }) )
View Source
var ( GetStringsBuilderPool = CreatePool(func() interface{} { var b bytes.Buffer return &b }) )
Functions ¶
func AcquireBuffer ¶
func AcquireStringsBuilder ¶
func CreatePool ¶
func ReleaseBuffer ¶
func ReleaseStringsBuilder ¶
Types ¶
type AnnuallyDbSelector ¶
type AnnuallyDbSelector struct { }
func ProvideAnnuallyDbSelector ¶
func ProvideAnnuallyDbSelector() *AnnuallyDbSelector
type AnnuallyTableSelector ¶
type AnnuallyTableSelector struct {
// contains filtered or unexported fields
}
func ProvideAnnuallyTableSelector ¶
func ProvideAnnuallyTableSelector(conf *Config, dp Partition) *AnnuallyTableSelector
func (*AnnuallyTableSelector) Pick ¶
func (s *AnnuallyTableSelector) Pick(table string, node int, params ...interface{}) *bytes.Buffer
func (*AnnuallyTableSelector) Total ¶
func (s *AnnuallyTableSelector) Total(table string) int
type Config ¶
type Config struct { ShardingConfig ShardingConfig ShardsConfig []ShardConfig }
func ProvideConfig ¶
func ProvideConfig(config *YamlConfig) (*Config, error)
func (Config) GetShardingConfig ¶
func (c Config) GetShardingConfig() ShardingConfig
func (Config) GetShardsConfig ¶
func (c Config) GetShardsConfig() []ShardConfig
type ConnConfig ¶
func (ConnConfig) GetMaxIdleConns ¶
func (c ConnConfig) GetMaxIdleConns() int
func (ConnConfig) GetMaxLifeTime ¶
func (c ConnConfig) GetMaxLifeTime() time.Duration
func (ConnConfig) GetMaxOpenConns ¶
func (c ConnConfig) GetMaxOpenConns() int
type DailyDbSelector ¶
type DailyDbSelector struct { }
func ProvideDailyDbSelector ¶
func ProvideDailyDbSelector() *DailyDbSelector
type DailyTableSelector ¶
type DailyTableSelector struct {
// contains filtered or unexported fields
}
func ProvideDailyTableSelector ¶
func ProvideDailyTableSelector(conf *Config, dp Partition) *DailyTableSelector
func (*DailyTableSelector) Pick ¶
func (s *DailyTableSelector) Pick(table string, node int, params ...interface{}) *bytes.Buffer
func (*DailyTableSelector) Total ¶
func (s *DailyTableSelector) Total(table string) int
type DbConfig ¶
type DbConfig struct { Driver string Dbname string Protocol string Host string User string Password string Params map[string]string Conn ConnConfig }
func (DbConfig) GetConn ¶
func (c DbConfig) GetConn() ConnConfig
func (DbConfig) GetPassword ¶
func (DbConfig) GetProtocol ¶
type DbExecutor ¶
type DynamicCluster ¶
type DynamicCluster struct { Re map[string]*sql.DB Config *Config Sharding Sharding Selector DbSelector Executor DbExecutor Lb Replication // contains filtered or unexported fields }
func (*DynamicCluster) GetShardsTotal ¶
func (s *DynamicCluster) GetShardsTotal() int
func (*DynamicCluster) Read ¶
func (s *DynamicCluster) Read(table string, key []byte, handler DBHandler, params ...interface{})
func (*DynamicCluster) TableSelector ¶
func (s *DynamicCluster) TableSelector() TableSelector
type MonthlyDbSelector ¶
type MonthlyDbSelector struct { }
func ProvideMonthlyDbSelector ¶
func ProvideMonthlyDbSelector() *MonthlyDbSelector
type MonthlyTableSelector ¶
type MonthlyTableSelector struct {
// contains filtered or unexported fields
}
func ProvideMonthlyTableSelector ¶
func ProvideMonthlyTableSelector(conf *Config, dp Partition) *MonthlyTableSelector
func (*MonthlyTableSelector) Pick ¶
func (s *MonthlyTableSelector) Pick(table string, node int, params ...interface{}) *bytes.Buffer
func (*MonthlyTableSelector) Total ¶
func (s *MonthlyTableSelector) Total(table string) int
type Replication ¶
type RoundRobinSelector ¶
type RoundRobinSelector = distributed.RoundRobinSelector
func ProvideRoundRobinSelector ¶
func ProvideRoundRobinSelector() *RoundRobinSelector
type Shard ¶
func ProvideStaticShards ¶
func ProvideStaticShards(conf *Config, sharding Sharding, lb Replication) ([]Shard, error)
type ShardConfig ¶
func (ShardConfig) GetMasterConfig ¶
func (c ShardConfig) GetMasterConfig() DbConfig
func (ShardConfig) GetReplicasConfig ¶
func (c ShardConfig) GetReplicasConfig() []DbConfig
type ShardingConfig ¶
type ShardingConfig struct { Dbname string Total int Type string Table []ShardingTableConfig }
func (ShardingConfig) GetDbname ¶
func (s ShardingConfig) GetDbname() string
func (ShardingConfig) GetTableConfig ¶
func (s ShardingConfig) GetTableConfig() []ShardingTableConfig
func (ShardingConfig) GetTotal ¶
func (s ShardingConfig) GetTotal() int
func (ShardingConfig) GetType ¶
func (s ShardingConfig) GetType() string
type ShardingTableConfig ¶
func (*ShardingTableConfig) GetTableName ¶
func (s *ShardingTableConfig) GetTableName() string
func (*ShardingTableConfig) GetTotal ¶
func (s *ShardingTableConfig) GetTotal() int
type StandardSharding ¶
type StandardSharding struct {
// contains filtered or unexported fields
}
func ProvideStandardSharding ¶
func ProvideStandardSharding(conf *Config, selector TableSelector) *StandardSharding
func (*StandardSharding) Allocation ¶
func (s *StandardSharding) Allocation(i int, dbname string, params ...interface{}) string
func (*StandardSharding) GetDbname ¶
func (s *StandardSharding) GetDbname() string
func (*StandardSharding) TableSelector ¶
func (s *StandardSharding) TableSelector() TableSelector
type StandardTableSelector ¶
type StandardTableSelector struct {
// contains filtered or unexported fields
}
func ProvideStandardTableSelector ¶
func ProvideStandardTableSelector(conf *Config, dp Partition) *StandardTableSelector
func (*StandardTableSelector) Pick ¶
func (s *StandardTableSelector) Pick(table string, node int, params ...interface{}) *bytes.Buffer
func (*StandardTableSelector) Total ¶
func (s *StandardTableSelector) Total(table string) int
type StaticCluster ¶
type StaticCluster struct { Sharding Sharding Shards []Shard Config *Config Executor DbExecutor }
func (*StaticCluster) GetShardsTotal ¶
func (s *StaticCluster) GetShardsTotal() int
func (*StaticCluster) Read ¶
func (s *StaticCluster) Read(table string, key []byte, handler DBHandler, params ...interface{})
func (*StaticCluster) TableSelector ¶
func (s *StaticCluster) TableSelector() TableSelector
type StaticShard ¶
type StaticShard struct { Master *sql.DB Replica []*sql.DB // contains filtered or unexported fields }
func NewShard ¶
func NewShard(conf ShardConfig, dbname string, lb Replication) *StaticShard
func (*StaticShard) GetMaster ¶
func (s *StaticShard) GetMaster() *sql.DB
func (*StaticShard) GetReplica ¶
func (s *StaticShard) GetReplica() *sql.DB
func (*StaticShard) GetReplicaTotal ¶
func (s *StaticShard) GetReplicaTotal() int
type TableSelector ¶
type YamlClusterConfig ¶
type YamlClusterConfig struct { YamlDBConfig `yaml:",inline"` Sharding YamlShardingConfig `yaml:"sharding"` }
type YamlConfig ¶
type YamlConfig struct { Cluster YamlClusterConfig `yaml:"cluster"` Shards []*YamlShardsConfig `yaml:"shards"` }
func ProvideYamlConfig ¶
func ProvideYamlConfig(dec Decoder) (*YamlConfig, error)
type YamlConnConfig ¶
type YamlDBConfig ¶
type YamlDBConfig struct { Driver string `yaml:"driver"` Dbname string `yaml:"dbname"` Type string `yaml:"type"` Conn YamlConnConfig `yaml:"conn"` }
type YamlDecoder ¶
type YamlDecoder = yaml.Decoder
func ProvideYamlDecoder ¶
func ProvideYamlDecoder(rd io.Reader) *YamlDecoder
type YamlMasterConfig ¶
type YamlMasterConfig struct { Host string `yaml:"host"` YamlNodeConfig `yaml:",inline"` }
type YamlNodeConfig ¶
type YamlReplicasConfig ¶
type YamlReplicasConfig struct { Hosts []string `yaml:"hosts"` YamlNodeConfig `yaml:",inline"` }
type YamlShardingConfig ¶
type YamlShardingConfig struct { DbTotal int `yaml:"total"` Table []*YamlTableShardingConfig `yaml:"table"` }
type YamlShardsConfig ¶
type YamlShardsConfig struct { Master YamlMasterConfig `yaml:"master"` Replicas YamlReplicasConfig `yaml:"replicas"` }
type YamlTableShardingConfig ¶
Click to show internal directories.
Click to hide internal directories.