dcs

package
v0.0.0-...-20a187a Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathHANodesPrefix = "ha_nodes"
)

Variables

View Source
var (
	// ErrExists means that node being created already exists
	ErrExists = errors.New("key already exists")
	// ErrNotFound means that requested not does not exist
	ErrNotFound = errors.New("key was not found in DCS")
	// ErrMalformed means that we failed to unmarshall received data
	ErrMalformed = errors.New("failed to parse DCS value, possibly data format changed")
)

Functions

func CreateTLSConfig

func CreateTLSConfig(rootCAFile, certFile, keyFile string) (*tls.Config, error)

func GetTLSDialer

func GetTLSDialer(dialer *net.Dialer, tlsConfig *tls.Config) (zk.Dialer, error)

func JoinPath

func JoinPath(parts ...string) string

JoinPath build node path from chunks

Types

type DCS

type DCS interface {
	IsConnected() bool
	WaitConnected(timeout time.Duration) bool
	Initialize() // Create initial data structure if not exists
	SetDisconnectCallback(callback func() error)
	AcquireLock(path string) bool
	ReleaseLock(path string)
	Create(path string, value interface{}) error
	CreateEphemeral(path string, value interface{}) error
	Set(path string, value interface{}) error
	SetEphemeral(path string, value interface{}) error
	Get(path string, dest interface{}) error
	Delete(path string) error
	GetTree(path string) (interface{}, error)
	GetChildren(path string) ([]string, error)
	Close()
}

DCS is the main interface representing data store DCS implementation should maintain connection to a server, track connection status changes (connected/disconnected) and perform basic operations

func NewZookeeper

func NewZookeeper(ctx context.Context, config *ZookeeperConfig, logger *slog.Logger) (DCS, error)

NewZookeeper returns Zookeeper based DCS storage

type ExtendedLockDCS

type ExtendedLockDCS interface {
	DCS
	ReleaseLockOrError(path string) error
}

type LockOwner

type LockOwner struct {
	Hostname string `json:"hostname"`
	Pid      int    `json:"pid"`
}

LockOwner contains info about the process holding the lock

type RandomHostProvider

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

func NewRandomHostProvider

func NewRandomHostProvider(ctx context.Context, config *RandomHostProviderConfig, useAddrs bool, logger *slog.Logger) *RandomHostProvider

func (*RandomHostProvider) Connected

func (rhp *RandomHostProvider) Connected()

func (*RandomHostProvider) Init

func (rhp *RandomHostProvider) Init(servers []string) error

func (*RandomHostProvider) Len

func (rhp *RandomHostProvider) Len() int

func (*RandomHostProvider) Next

func (rhp *RandomHostProvider) Next() (server string, retryStart bool)

type RandomHostProviderConfig

type RandomHostProviderConfig struct {
	LookupTimeout      time.Duration `config:"lookup_timeout" yaml:"lookup_timeout"`
	LookupTTL          time.Duration `config:"lookup_ttl" yaml:"lookup_ttl"`
	LookupTickInterval time.Duration `config:"lookup_tick_interval" yaml:"lookup_tick_interval"`
}

func DefaultRandomHostProviderConfig

func DefaultRandomHostProviderConfig() RandomHostProviderConfig

type ZookeeperConfig

type ZookeeperConfig struct {
	Hostname              string                   `config:"hostname" yaml:"hostname"`
	SessionTimeout        time.Duration            `config:"session_timeout" yaml:"session_timeout"`
	Namespace             string                   `config:"namespace,required"`
	Hosts                 []string                 `config:"hosts,required"`
	BackoffInterval       time.Duration            `config:"backoff_interval" yaml:"backoff_interval"`
	BackoffRandFactor     float64                  `config:"backoff_rand_factor" yaml:"backoff_rand_factor"`
	BackoffMultiplier     float64                  `config:"backoff_multiplier" yaml:"backoff_multiplier"`
	BackoffMaxInterval    time.Duration            `config:"backoff_max_interval" yaml:"backoff_max_interval"`
	BackoffMaxElapsedTime time.Duration            `config:"backoff_max_elapsed_time" yaml:"backoff_max_elapsed_time"`
	BackoffMaxRetries     uint64                   `config:"backoff_max_retries" yaml:"backoff_max_retries"`
	RandomHostProvider    RandomHostProviderConfig `config:"random_host_provider" yaml:"random_host_provider"`
	Auth                  bool                     `config:"auth" yaml:"auth"`
	Username              string                   `config:"username" yaml:"username"`
	Password              string                   `config:"password" yaml:"password"`
	UseSSL                bool                     `config:"use_ssl" yaml:"use_ssl"`
	KeyFile               string                   `config:"keyfile" yaml:"keyfile"`
	CertFile              string                   `config:"certfile" yaml:"certfile"`
	CACert                string                   `config:"ca_cert" yaml:"ca_cert"`
	VerifyCerts           bool                     `config:"verify_certs" yaml:"verify_certs"`
}

ZookeeperConfig contains Zookeeper connection info

func DefaultZookeeperConfig

func DefaultZookeeperConfig() (ZookeeperConfig, error)

DefaultZookeeperConfig returns default Zookeeper connection configuration

Jump to

Keyboard shortcuts

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