activerecord

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoData = errors.New("no data")

Functions

func InitActiveRecord

func InitActiveRecord(opts ...Option)

func Logger

func Logger() logger.LoggerInterface

func NewDefaultConfig

func NewDefaultConfig() func(ctx context.Context) ConfigInterface

func ReinitActiveRecord

func ReinitActiveRecord(opts ...Option)

func WithShard

func WithShard(masters []OptionInterface, replicas []OptionInterface) clusterOption

Types

type ARMertics

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

func NewARMetrics

func NewARMetrics(metrics *prometheus.Registry, cumulativeMetrics CumulativeMetricsInterface) *ARMertics

func (*ARMertics) ErrorCount

func (m *ARMertics) ErrorCount(storage, entity string) MetricStatCountInterface

func (*ARMertics) StatCount

func (m *ARMertics) StatCount(storage, entity string) MetricStatCountInterface

func (*ARMertics) Timer

func (m *ARMertics) Timer(storage, entity string) MetricTimerInterface

type ARMetricCount

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

func (*ARMetricCount) Inc

func (m *ARMetricCount) Inc(ctx context.Context, name string, val float64)

type ARMetricTimer

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

func (*ARMetricTimer) Finish

func (m *ARMetricTimer) Finish(ctx context.Context, name string)

func (*ARMetricTimer) Timing

func (m *ARMetricTimer) Timing(ctx context.Context, name string)

type ActiveRecord

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

func GetInstance

func GetInstance() *ActiveRecord

type BaseConnectionOptions

type BaseConnectionOptions struct {
	Mode           ServerModeType
	ConnectionHash hash.Hash32
	Calculated     bool
}

BaseConnectionOptions - опции используемые для подключения

func (*BaseConnectionOptions) GetConnectionID

func (o *BaseConnectionOptions) GetConnectionID() string

GetConnectionID - получение ConnecitionID. После первого получения, больше нельзя его модифицировать. Можно только новый Options создать

func (*BaseConnectionOptions) InstanceMode

func (o *BaseConnectionOptions) InstanceMode() ServerModeType

InstanceMode - метод для получения режима работы инстанса RO или RW

func (*BaseConnectionOptions) UpdateHash

func (o *BaseConnectionOptions) UpdateHash(data ...interface{}) error

UpdateHash - функция расчета ConnectionID, необходима для шаринга конектов между моделями.

type BaseField

type BaseField struct {
	Collection []ModelStruct
	Objects    map[string][]ModelStruct
	Exists     bool
	ShardNum   uint32
	IsReplica  bool
	Readonly   bool
}

type Cluster

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

Тип описывающий кластер. Сейчас кластер - это набор шардов.

func AddClusterChecker

func AddClusterChecker(ctx context.Context, configPath string, params ClusterConfigParameters) (*Cluster, error)

AddClusterChecker регистрирует конфигурацию кластера в локальном пингере

func GetClusterInfoFromCfg

func GetClusterInfoFromCfg(ctx context.Context, path string, globs MapGlobParam, optionCreator func(ShardInstanceConfig) (OptionInterface, error)) (*Cluster, error)

Констркуктор позволяющий проинициализировать кластер их конфигурации. На вход передаётся путь в конфиге, значения по умолчанию, и ссылка на функцию, которая создаёт структуру опций и считает контрольную сумму, для того, что бы следить за их изменением в онлайне.

func NewCluster

func NewCluster(shardCnt int) *Cluster

func NewClusterInfo

func NewClusterInfo(opts ...clusterOption) *Cluster

Конструктор который позволяет проинициализировать новый кластер. В опциях передаются все шарды, сколько шардов, столько и опций. Используется в случаях, когда информация по кластеру прописана непосредственно в декларации модели, а не в конфиге. Так же используется при тестировании.

func (*Cluster) Append

func (c *Cluster) Append(shard Shard)

Append добавляет новый шард в кластер

func (*Cluster) Equal

func (c *Cluster) Equal(c2 *Cluster) bool

Equal сравнивает загруженные конфигурации кластеров на основе контрольной суммы всех инстансов кластера

func (*Cluster) NextMaster

func (c *Cluster) NextMaster(shardNum int) ShardInstance

NextMaster выбирает следующий доступный инстанс мастера в шарде shardNum

func (*Cluster) NextReplica

func (c *Cluster) NextReplica(shardNum int) (ShardInstance, bool)

NextMaster выбирает следующий доступный инстанс реплики в шарде shardNum

func (*Cluster) SetShardInstances

func (c *Cluster) SetShardInstances(shardNum int, instances []ShardInstance)

SetShardInstances заменяет инстансы кластера в шарде shardNum на инстансы из instances

func (*Cluster) ShardInstances

func (c *Cluster) ShardInstances(shardNum int) []ShardInstance

ShardInstances копия всех инстансов из шарды shardNum

func (*Cluster) Shards

func (c *Cluster) Shards() int

Shards кол-во доступных шард кластера

type ClusterCheckerInterface

type ClusterCheckerInterface interface {
	AddClusterChecker(ctx context.Context, path string, params ClusterConfigParameters) (*Cluster, error)
}

type ClusterConfigParameters

type ClusterConfigParameters struct {
	Globs         MapGlobParam
	OptionCreator func(ShardInstanceConfig) (OptionInterface, error)
	OptionChecker func(ctx context.Context, instance ShardInstance) (OptionInterface, error)
}

func (ClusterConfigParameters) Validate

func (c ClusterConfigParameters) Validate() bool

type ConfigCacherInterface

type ConfigCacherInterface interface {
	Get(ctx context.Context, path string, glob MapGlobParam, optionCreator func(ShardInstanceConfig) (OptionInterface, error)) (*Cluster, error)
}

func ConfigCacher

func ConfigCacher() ConfigCacherInterface

type ConfigInterface

type ConfigInterface interface {
	GetBool(confPath string, dfl ...bool) (bool, error)
	GetBoolIfExists(confPath string) (value bool, ok bool, err error)
	GetInt(confPath string, dfl ...int64) (int64, error)
	GetIntIfExists(confPath string) (int64, bool, error)
	GetDuration(confPath string, dfl ...time.Duration) (time.Duration, error)
	GetDurationIfExists(confPath string) (time.Duration, bool, error)
	GetString(confPath string, dfl ...string) (string, error)
	GetStringIfExists(confPath string) (string, bool, error)
	GetStrings(confPath string, dfl []string) ([]string, error)
	GetStruct(confPath string, valuePtr interface{}) (bool, error)
}

func Config

func Config(ctx context.Context) ConfigInterface

type ConnectionCacherInterface

type ConnectionCacherInterface interface {
	Add(shard ShardInstance, connector func(interface{}) (ConnectionInterface, error)) (ConnectionInterface, error)
	GetOrAdd(shard ShardInstance, connector func(interface{}) (ConnectionInterface, error)) (ConnectionInterface, error)
	Get(shard ShardInstance) ConnectionInterface
	CloseConnection(context.Context)
}

func ConnectionCacher

func ConnectionCacher() ConnectionCacherInterface

type ConnectionInterface

type ConnectionInterface interface {
	Close()
	Done() <-chan struct{}
}

func GetConnection

func GetConnection(
	ctx context.Context,
	configPath string,
	globParam MapGlobParam,
	optionCreator func(ShardInstanceConfig) (OptionInterface, error),
	instType ShardInstanceType,
	shard int,
	getConnection func(options interface{}) (ConnectionInterface, error),
) (ConnectionInterface, error)

TODO - сделать статистику по используемым инстансам - прикрутить локальный пингер и исключать недоступные инстансы

type CumulativeMetricsInterface

type CumulativeMetricsInterface interface {
	TimeCumulativeMetric(ctx context.Context, name string, dur time.Duration)
	IncCumulativeMetric(ctx context.Context, name string, diff int32)
}

type DefaultConfig

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

func NewDefaultConfigFromMap

func NewDefaultConfigFromMap(cfg map[string]interface{}) *DefaultConfig

func (*DefaultConfig) GetBool

func (dc *DefaultConfig) GetBool(confPath string, dfl ...bool) (bool, error)

func (*DefaultConfig) GetBoolIfExists

func (dc *DefaultConfig) GetBoolIfExists(confPath string) (value bool, ok bool, err error)

func (*DefaultConfig) GetDuration

func (dc *DefaultConfig) GetDuration(confPath string, dfl ...time.Duration) (time.Duration, error)

func (*DefaultConfig) GetDurationIfExists

func (dc *DefaultConfig) GetDurationIfExists(confPath string) (time.Duration, bool, error)

func (*DefaultConfig) GetInt

func (dc *DefaultConfig) GetInt(confPath string, dfl ...int64) (int64, error)

func (*DefaultConfig) GetIntIfExists

func (dc *DefaultConfig) GetIntIfExists(confPath string) (int64, bool, error)

func (*DefaultConfig) GetLastUpdateTime

func (dc *DefaultConfig) GetLastUpdateTime() time.Time

func (*DefaultConfig) GetString

func (dc *DefaultConfig) GetString(confPath string, dfl ...string) (string, error)

func (*DefaultConfig) GetStringIfExists

func (dc *DefaultConfig) GetStringIfExists(confPath string) (string, bool, error)

func (*DefaultConfig) GetStrings

func (dc *DefaultConfig) GetStrings(confPath string, dfl []string) ([]string, error)

func (*DefaultConfig) GetStruct

func (dc *DefaultConfig) GetStruct(confPath string, valuePtr interface{}) (bool, error)

type DefaultConfigCacher

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

Структура для кеширования полученных конфигураций. Инвалидация происходит посредством сравнения updateTime сданной труктуры и самого конфига. Используется для шаринга конфигов между можелями если они используют одну и ту же конфигурацию для подключений

func NewConfigCacher

func NewConfigCacher() *DefaultConfigCacher

Конструктор для создания нового кешера конфигов

func (*DefaultConfigCacher) Get

func (cc *DefaultConfigCacher) Get(ctx context.Context, path string, globs MapGlobParam, optionCreator func(ShardInstanceConfig) (OptionInterface, error)) (*Cluster, error)

Получение конфигурации. Если есть в кеше и он еще валидный, то конфигурация берётся из кеша если в кеше нет, то достаём из конфига и кешируем.

type DefaultNoopMetric

type DefaultNoopMetric struct{}

func NewDefaultNoopMetric

func NewDefaultNoopMetric() *DefaultNoopMetric

func (*DefaultNoopMetric) ErrorCount

func (*DefaultNoopMetric) ErrorCount(storage, entity string) MetricStatCountInterface

func (*DefaultNoopMetric) StatCount

func (*DefaultNoopMetric) StatCount(storage, entity string) MetricStatCountInterface

func (*DefaultNoopMetric) Timer

func (*DefaultNoopMetric) Timer(storage, entity string) MetricTimerInterface

type DefaultNoopMetricCount

type DefaultNoopMetricCount struct{}

func (*DefaultNoopMetricCount) Inc

func (*DefaultNoopMetricCount) Inc(ctx context.Context, name string, val float64)

type DefaultNoopMetricTimer

type DefaultNoopMetricTimer struct{}

func (*DefaultNoopMetricTimer) Finish

func (*DefaultNoopMetricTimer) Finish(ctx context.Context, name string)

func (*DefaultNoopMetricTimer) Timing

func (*DefaultNoopMetricTimer) Timing(ctx context.Context, name string)

type Limiter

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

func EmptyLimiter

func EmptyLimiter() Limiter

func NewLimitOffset

func NewLimitOffset(limit uint32, offset uint32) Limiter

func NewLimiter

func NewLimiter(limit uint32) Limiter

func NewThreshold

func NewThreshold(limit uint32) Limiter

func (Limiter) FulfillWarn

func (l Limiter) FulfillWarn() bool

func (Limiter) Limit

func (l Limiter) Limit() uint32

func (Limiter) Offset

func (l Limiter) Offset() uint32

func (Limiter) String

func (l Limiter) String() string

type MapGlobParam

type MapGlobParam struct {
	Timeout  time.Duration
	PoolSize int
}

Тип используемый для передачи набора значений по умолчанию для параметров

type MetricErrorCountInterface

type MetricErrorCountInterface interface {
	Inc(ctx context.Context, name string, val float64)
}

type MetricInterface

type MetricInterface interface {
	StatCount(storage, entity string) MetricStatCountInterface
	ErrorCount(storage, entity string) MetricStatCountInterface
	Timer(storage, entity string) MetricTimerInterface
}

func Metric

func Metric() MetricInterface

type MetricStatCountInterface

type MetricStatCountInterface interface {
	Inc(ctx context.Context, name string, val float64)
}

type MetricTimerInterface

type MetricTimerInterface interface {
	Timing(ctx context.Context, name string)
	Finish(ctx context.Context, name string)
}

type MockConfig

type MockConfig struct {
	mock.Mock
}

MockConfig is an autogenerated mock type for the ConfigInterface type

func NewMockConfig

func NewMockConfig(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockConfig

NewMockConfig creates a new instance of MockConfig. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockConfig) EXPECT

func (_m *MockConfig) EXPECT() *MockConfig_Expecter

func (*MockConfig) GetBool

func (_m *MockConfig) GetBool(confPath string, dfl ...bool) (bool, error)

GetBool provides a mock function with given fields: confPath, dfl

func (*MockConfig) GetBoolIfExists

func (_m *MockConfig) GetBoolIfExists(confPath string) (bool, bool, error)

GetBoolIfExists provides a mock function with given fields: confPath

func (*MockConfig) GetDuration

func (_m *MockConfig) GetDuration(confPath string, dfl ...time.Duration) (time.Duration, error)

GetDuration provides a mock function with given fields: confPath, dfl

func (*MockConfig) GetDurationIfExists

func (_m *MockConfig) GetDurationIfExists(confPath string) (time.Duration, bool, error)

GetDurationIfExists provides a mock function with given fields: confPath

func (*MockConfig) GetInt

func (_m *MockConfig) GetInt(confPath string, dfl ...int64) (int64, error)

GetInt provides a mock function with given fields: confPath, dfl

func (*MockConfig) GetIntIfExists

func (_m *MockConfig) GetIntIfExists(confPath string) (int64, bool, error)

GetIntIfExists provides a mock function with given fields: confPath

func (*MockConfig) GetString

func (_m *MockConfig) GetString(confPath string, dfl ...string) (string, error)

GetString provides a mock function with given fields: confPath, dfl

func (*MockConfig) GetStringIfExists

func (_m *MockConfig) GetStringIfExists(confPath string) (string, bool, error)

GetStringIfExists provides a mock function with given fields: confPath

func (*MockConfig) GetStrings

func (_m *MockConfig) GetStrings(confPath string, dfl []string) ([]string, error)

GetStrings provides a mock function with given fields: confPath, dfl

func (*MockConfig) GetStruct

func (_m *MockConfig) GetStruct(confPath string, valuePtr interface{}) (bool, error)

GetStruct provides a mock function with given fields: confPath, valuePtr

type MockConfig_Expecter

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

func (*MockConfig_Expecter) GetBool

func (_e *MockConfig_Expecter) GetBool(confPath interface{}, dfl ...interface{}) *MockConfig_GetBool_Call

GetBool is a helper method to define mock.On call

  • confPath string
  • dfl ...bool

func (*MockConfig_Expecter) GetBoolIfExists

func (_e *MockConfig_Expecter) GetBoolIfExists(confPath interface{}) *MockConfig_GetBoolIfExists_Call

GetBoolIfExists is a helper method to define mock.On call

  • confPath string

func (*MockConfig_Expecter) GetDuration

func (_e *MockConfig_Expecter) GetDuration(confPath interface{}, dfl ...interface{}) *MockConfig_GetDuration_Call

GetDuration is a helper method to define mock.On call

  • confPath string
  • dfl ...time.Duration

func (*MockConfig_Expecter) GetDurationIfExists

func (_e *MockConfig_Expecter) GetDurationIfExists(confPath interface{}) *MockConfig_GetDurationIfExists_Call

GetDurationIfExists is a helper method to define mock.On call

  • confPath string

func (*MockConfig_Expecter) GetInt

func (_e *MockConfig_Expecter) GetInt(confPath interface{}, dfl ...interface{}) *MockConfig_GetInt_Call

GetInt is a helper method to define mock.On call

  • confPath string
  • dfl ...int64

func (*MockConfig_Expecter) GetIntIfExists

func (_e *MockConfig_Expecter) GetIntIfExists(confPath interface{}) *MockConfig_GetIntIfExists_Call

GetIntIfExists is a helper method to define mock.On call

  • confPath string

func (*MockConfig_Expecter) GetString

func (_e *MockConfig_Expecter) GetString(confPath interface{}, dfl ...interface{}) *MockConfig_GetString_Call

GetString is a helper method to define mock.On call

  • confPath string
  • dfl ...string

func (*MockConfig_Expecter) GetStringIfExists

func (_e *MockConfig_Expecter) GetStringIfExists(confPath interface{}) *MockConfig_GetStringIfExists_Call

GetStringIfExists is a helper method to define mock.On call

  • confPath string

func (*MockConfig_Expecter) GetStrings

func (_e *MockConfig_Expecter) GetStrings(confPath interface{}, dfl interface{}) *MockConfig_GetStrings_Call

GetStrings is a helper method to define mock.On call

  • confPath string
  • dfl []string

func (*MockConfig_Expecter) GetStruct

func (_e *MockConfig_Expecter) GetStruct(confPath interface{}, valuePtr interface{}) *MockConfig_GetStruct_Call

GetStruct is a helper method to define mock.On call

  • confPath string
  • valuePtr interface{}

type MockConfig_GetBoolIfExists_Call

type MockConfig_GetBoolIfExists_Call struct {
	*mock.Call
}

MockConfig_GetBoolIfExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBoolIfExists'

func (*MockConfig_GetBoolIfExists_Call) Return

func (*MockConfig_GetBoolIfExists_Call) Run

func (*MockConfig_GetBoolIfExists_Call) RunAndReturn

type MockConfig_GetBool_Call

type MockConfig_GetBool_Call struct {
	*mock.Call
}

MockConfig_GetBool_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetBool'

func (*MockConfig_GetBool_Call) Return

func (*MockConfig_GetBool_Call) Run

func (_c *MockConfig_GetBool_Call) Run(run func(confPath string, dfl ...bool)) *MockConfig_GetBool_Call

func (*MockConfig_GetBool_Call) RunAndReturn

func (_c *MockConfig_GetBool_Call) RunAndReturn(run func(string, ...bool) (bool, error)) *MockConfig_GetBool_Call

type MockConfig_GetDurationIfExists_Call

type MockConfig_GetDurationIfExists_Call struct {
	*mock.Call
}

MockConfig_GetDurationIfExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDurationIfExists'

func (*MockConfig_GetDurationIfExists_Call) Return

func (*MockConfig_GetDurationIfExists_Call) Run

func (*MockConfig_GetDurationIfExists_Call) RunAndReturn

type MockConfig_GetDuration_Call

type MockConfig_GetDuration_Call struct {
	*mock.Call
}

MockConfig_GetDuration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDuration'

func (*MockConfig_GetDuration_Call) Return

func (*MockConfig_GetDuration_Call) Run

func (_c *MockConfig_GetDuration_Call) Run(run func(confPath string, dfl ...time.Duration)) *MockConfig_GetDuration_Call

func (*MockConfig_GetDuration_Call) RunAndReturn

type MockConfig_GetIntIfExists_Call

type MockConfig_GetIntIfExists_Call struct {
	*mock.Call
}

MockConfig_GetIntIfExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetIntIfExists'

func (*MockConfig_GetIntIfExists_Call) Return

func (*MockConfig_GetIntIfExists_Call) Run

func (*MockConfig_GetIntIfExists_Call) RunAndReturn

type MockConfig_GetInt_Call

type MockConfig_GetInt_Call struct {
	*mock.Call
}

MockConfig_GetInt_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetInt'

func (*MockConfig_GetInt_Call) Return

func (*MockConfig_GetInt_Call) Run

func (_c *MockConfig_GetInt_Call) Run(run func(confPath string, dfl ...int64)) *MockConfig_GetInt_Call

func (*MockConfig_GetInt_Call) RunAndReturn

func (_c *MockConfig_GetInt_Call) RunAndReturn(run func(string, ...int64) (int64, error)) *MockConfig_GetInt_Call

type MockConfig_GetStringIfExists_Call

type MockConfig_GetStringIfExists_Call struct {
	*mock.Call
}

MockConfig_GetStringIfExists_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStringIfExists'

func (*MockConfig_GetStringIfExists_Call) Return

func (*MockConfig_GetStringIfExists_Call) Run

func (*MockConfig_GetStringIfExists_Call) RunAndReturn

type MockConfig_GetString_Call

type MockConfig_GetString_Call struct {
	*mock.Call
}

MockConfig_GetString_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetString'

func (*MockConfig_GetString_Call) Return

func (*MockConfig_GetString_Call) Run

func (_c *MockConfig_GetString_Call) Run(run func(confPath string, dfl ...string)) *MockConfig_GetString_Call

func (*MockConfig_GetString_Call) RunAndReturn

func (_c *MockConfig_GetString_Call) RunAndReturn(run func(string, ...string) (string, error)) *MockConfig_GetString_Call

type MockConfig_GetStrings_Call

type MockConfig_GetStrings_Call struct {
	*mock.Call
}

MockConfig_GetStrings_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStrings'

func (*MockConfig_GetStrings_Call) Return

func (*MockConfig_GetStrings_Call) Run

func (_c *MockConfig_GetStrings_Call) Run(run func(confPath string, dfl []string)) *MockConfig_GetStrings_Call

func (*MockConfig_GetStrings_Call) RunAndReturn

func (_c *MockConfig_GetStrings_Call) RunAndReturn(run func(string, []string) ([]string, error)) *MockConfig_GetStrings_Call

type MockConfig_GetStruct_Call

type MockConfig_GetStruct_Call struct {
	*mock.Call
}

MockConfig_GetStruct_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetStruct'

func (*MockConfig_GetStruct_Call) Return

func (*MockConfig_GetStruct_Call) Run

func (_c *MockConfig_GetStruct_Call) Run(run func(confPath string, valuePtr interface{})) *MockConfig_GetStruct_Call

func (*MockConfig_GetStruct_Call) RunAndReturn

func (_c *MockConfig_GetStruct_Call) RunAndReturn(run func(string, interface{}) (bool, error)) *MockConfig_GetStruct_Call

type ModelStruct

type ModelStruct interface {
	Insert(ctx context.Context) error
	Replace(ctx context.Context) error
	InsertOrReplace(ctx context.Context) error
	Update(ctx context.Context) error
	Delete(ctx context.Context) error
}

type OpCode

type OpCode uint8
const (
	OpSet    OpCode = iota // Set field value
	OpAdd                  // Atomic increment
	OpAnd                  // Atomic logic values
	OpXor                  // Atomic logic xor
	OpOr                   // Atomic logic or
	OpSplice               // Atomic splice array
	OpDelete               // Atomic delete array value
	OpInsert
	OpUpdate
)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithConfig

func WithConfig(config func(ctx context.Context) ConfigInterface) Option

func WithConfigCacher

func WithConfigCacher(configCacher ConfigCacherInterface) Option

func WithConnectionPinger

func WithConnectionPinger(pc ClusterCheckerInterface) Option

func WithLogger

func WithLogger(logger logger.LoggerInterface) Option

func WithMetrics

func WithMetrics(metric MetricInterface) Option

type OptionInterface

type OptionInterface interface {
	GetConnectionID() string
	InstanceMode() ServerModeType
}

Интерфейс которому должен соответствовать билдер опций подключения к конретному инстансу

type SelectorLimiter

type SelectorLimiter interface {
	Limit() uint32
	Offset() uint32
	FulfillWarn() bool
	fmt.Stringer
}

type SerializerInterface

type SerializerInterface interface {
	Unmarshal(val interface{}) (interface{}, error)
	Marshal(data interface{}) (interface{}, error)
}

type ServerModeType

type ServerModeType uint8

Тип и константы для определения режима работы конкретного инстанса.

const (
	ModeMaster ServerModeType = iota
	ModeReplica
)

type Shard

type Shard struct {
	Masters  []ShardInstance
	Replicas []ShardInstance
	// contains filtered or unexported fields
}

Структура описывающая конкретный шард. Каждый шард может состоять из набора мастеров и реплик

func (*Shard) Instances

func (c *Shard) Instances() []ShardInstance

Instances копия списка конфигураций всех инстансов шарды. В начале списка следуют мастера, потом реплики

func (*Shard) NextMaster

func (s *Shard) NextMaster() ShardInstance

Функция выбирающая следующий доступный инстанс мастера в конкретном шарде

func (*Shard) NextReplica

func (s *Shard) NextReplica() ShardInstance

Инстанс выбирающий следующий доступный инстанс реплики в конкретном шарде

type ShardInstance

type ShardInstance struct {
	ParamsID string
	Config   ShardInstanceConfig
	Options  interface{}
	Offline  bool
}

Структура описывающая инстанс в кластере

type ShardInstanceConfig

type ShardInstanceConfig struct {
	Timeout  time.Duration
	Mode     ServerModeType
	PoolSize int32
	Addr     string
	User     string
	Password string
	Port     uint16
	DB       string
}

Структура используется для описания конфигурации конктретного инстанса

type ShardInstanceType

type ShardInstanceType uint8

Тип и константы для выбора инстанса в шарде

const (
	MasterInstanceType          ShardInstanceType = iota // Любой из описанных мастеров. По умолчанию используется для rw запросов
	ReplicaInstanceType                                  // Любой из описанных реплик
	ReplicaOrMasterInstanceType                          // Любая реплика если есть, если нет то любой мастер. По умолчанию используется при селекте
)

Jump to

Keyboard shortcuts

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