dcs

package
v0.0.0-...-8c8ecaa Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathHANodesPrefix      = "ha_nodes"
	PathCascadeNodesPrefix = "cascade_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 any) error
	CreateEphemeral(path string, value any) error
	Set(path string, value any) error
	SetEphemeral(path string, value any) error
	Get(path string, dest any) error
	Delete(path string) error
	GetTree(path string) (any, 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 *log.Logger) (DCS, error)

NewZookeeper returns Zookeeper based DCS storage

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 *log.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 return default Zookeeper connection configuration

Jump to

Keyboard shortcuts

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