Documentation
¶
Index ¶
- Variables
- type DB
- func (s *DB) Begin(ctx context.Context, shardKey string, f func(context.Context) error, ...) error
- func (s *DB) Connection(ctx context.Context, shardKey string, opt ...conn.ConnectionOption) conn.IConnection
- func (s *DB) GetFunc() ShardFunc
- func (s *DB) GetShards() []ShardID
- func (s *DB) GetTxManager(shardID ShardID) txmgr.ITransactionManager
- func (s *DB) Info() bootstrap.Info
- func (s *DB) RunFunc(ctx context.Context, ...) error
- func (s *DB) Start(ctx context.Context) error
- func (s *DB) Stop(ctx context.Context) error
- func (s *DB) WithoutTransaction(ctx context.Context, shardKey string) context.Context
- type DSNInfo
- type Option
- type ShardFunc
- type ShardID
- type ShardInfo
Constants ¶
This section is empty.
Variables ¶
var DefaultShardFunc = func(_ context.Context, shardKey string) ShardID { shardID, err := strconv.Atoi(shardKey) if err != nil { return math.MaxInt32 } return ShardID(shardID) }
DefaultShardFunc default function for determining shard number by shardKey.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB sharded database. Contains information about all shards. Each shard is a separate database. This is a service object that is used in bucket.DB for managing connections to shards.
func NewFromDSN ¶
NewFromDSN creates a sharded database by creating PxDB based on DSN.
func (*DB) Begin ¶
func (s *DB) Begin(ctx context.Context, shardKey string, f func(context.Context) error, opts ...txmgr.Option, ) error
Begin starts a function in a transaction for the specified shardKey.
func (*DB) Connection ¶
func (s *DB) Connection(ctx context.Context, shardKey string, opt ...conn.ConnectionOption) conn.IConnection
Connection returns IConnection interface implementation for the specified shardKey.
func (*DB) GetTxManager ¶
func (s *DB) GetTxManager(shardID ShardID) txmgr.ITransactionManager
GetTxManager returns transaction manager for the shard.
func (*DB) RunFunc ¶
func (s *DB) RunFunc(ctx context.Context, f func(ctx context.Context, shardID ShardID, con conn.IConnection) error, runParallel int, ) error
RunFunc executes a function for all shards. The order of shards is not defined. runParallel specifies the number of goroutines to use for parallel execution. If runParallel is 0, the function will be executed in the sequential way.
type Option ¶
type Option func(*DB)
Option option for DB.
func WithRestartPolicy ¶
func WithRestartPolicy(restartPolicy []backoff.RetryOption) Option
WithRestartPolicy sets the restart policy.
type ShardInfo ¶
type ShardInfo struct { ShardID ShardID Connector db.IStartStopConnector TxBeginner txmgr.ITransactionBeginner TxInformer txmgr.ITransactionInformer // contains filtered or unexported fields }
ShardInfo information about a shard.
func NewInfoPxDB ¶
NewInfoPxDB helper function, that creates shard information based on db.PxDB. telemetry is optional.