store

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEtcdEndpoints   = "http://127.0.0.1:2379"
	DefaultConsulEndpoints = "http://127.0.0.1:8500"
)
View Source
const (
	//TODO(sgotti) fix this in libkv?
	// consul min ttl is 10s and libkv divides this by 2
	MinTTL = 20 * time.Second
)

Variables

View Source
var (
	// ErrKeyNotFound is thrown when the key is not found in the store during a Get operation
	ErrKeyNotFound      = errors.New("Key not found in store")
	ErrKeyModified      = errors.New("Unable to complete atomic operation, key modified")
	ErrElectionNoLeader = errors.New("election: no leader")
)
View Source
var URLSchemeRegexp = regexp.MustCompile(`^([a-zA-Z][a-zA-Z0-9+-.]*)://`)

Functions

This section is empty.

Types

type Backend

type Backend string

Backend represents a KV Store Backend

const (
	CONSUL Backend = "consul"
	ETCDV2 Backend = "etcdv2"
	ETCDV3 Backend = "etcdv3"
)

type ComponentLabelValue

type ComponentLabelValue string
const (
	DefaultComponentLabel = "component"

	KeeperLabelValue   ComponentLabelValue = "stolon-keeper"
	SentinelLabelValue ComponentLabelValue = "stolon-sentinel"
	ProxyLabelValue    ComponentLabelValue = "stolon-proxy"
)

type Config

type Config struct {
	Backend       Backend
	Endpoints     string
	Timeout       time.Duration
	BasePath      string
	CertFile      string
	KeyFile       string
	CAFile        string
	SkipTLSVerify bool
}

type Election

type Election interface {
	// TODO(sgotti) this mimics the current docker/leadership API and the etcdv3
	// implementations adapt to it. In future it could be replaced with a better
	// api like the current one implemented by etcdclientv3/concurrency.
	//
	// WARNING: If the election error channel receives any error, it is vital that
	// the consuming code calls election.Stop(). Failure to do so can cause
	// subsequent elections to hang indefinitely across all participants of an
	// election.
	RunForElection() (<-chan bool, <-chan error)
	Leader() (string, error)
	Stop()
}

func NewKVBackedElection

func NewKVBackedElection(kvStore KVStore, path, candidateUID string, timeout time.Duration) Election

type KVBackedStore

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

func NewKVBackedStore

func NewKVBackedStore(kvStore KVStore, path string) *KVBackedStore

func (*KVBackedStore) AtomicPutClusterData

func (s *KVBackedStore) AtomicPutClusterData(ctx context.Context, cd *cluster.ClusterData, previous *KVPair) (*KVPair, error)

func (*KVBackedStore) GetClusterData

func (s *KVBackedStore) GetClusterData(ctx context.Context) (*cluster.ClusterData, *KVPair, error)

func (*KVBackedStore) GetKeepersInfo

func (s *KVBackedStore) GetKeepersInfo(ctx context.Context) (cluster.KeepersInfo, error)

func (*KVBackedStore) GetProxiesInfo

func (s *KVBackedStore) GetProxiesInfo(ctx context.Context) (cluster.ProxiesInfo, error)

func (*KVBackedStore) GetSentinelsInfo

func (s *KVBackedStore) GetSentinelsInfo(ctx context.Context) (cluster.SentinelsInfo, error)

func (*KVBackedStore) PutClusterData

func (s *KVBackedStore) PutClusterData(ctx context.Context, cd *cluster.ClusterData) error

func (*KVBackedStore) SetKeeperInfo

func (s *KVBackedStore) SetKeeperInfo(ctx context.Context, id string, ms *cluster.KeeperInfo, ttl time.Duration) error

func (*KVBackedStore) SetProxyInfo

func (s *KVBackedStore) SetProxyInfo(ctx context.Context, pi *cluster.ProxyInfo, ttl time.Duration) error

func (*KVBackedStore) SetSentinelInfo

func (s *KVBackedStore) SetSentinelInfo(ctx context.Context, si *cluster.SentinelInfo, ttl time.Duration) error

type KVPair

type KVPair struct {
	Key       string
	Value     []byte
	LastIndex uint64
}

KVPair represents {Key, Value, Lastindex} tuple

type KVStore

type KVStore interface {
	// Put a value at the specified key
	Put(ctx context.Context, key string, value []byte, options *WriteOptions) error

	// Get a value given its key
	Get(ctx context.Context, key string) (*KVPair, error)

	// List the content of a given prefix
	List(ctx context.Context, directory string) ([]*KVPair, error)

	// Atomic CAS operation on a single value.
	// Pass previous = nil to create a new key.
	AtomicPut(ctx context.Context, key string, value []byte, previous *KVPair, options *WriteOptions) (*KVPair, error)

	Delete(ctx context.Context, key string) error

	// Close the store connection
	Close() error
}

func NewKVStore

func NewKVStore(cfg Config) (KVStore, error)

type KubeElection

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

func NewKubeElection

func NewKubeElection(kubecli *kubernetes.Clientset, podName, namespace, clusterName, candidateUID string) (*KubeElection, error)

func (*KubeElection) Leader

func (e *KubeElection) Leader() (string, error)

func (*KubeElection) RunForElection

func (e *KubeElection) RunForElection() (<-chan bool, <-chan error)

func (*KubeElection) Stop

func (e *KubeElection) Stop()

type KubeStore

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

func NewKubeStore

func NewKubeStore(kubecli *kubernetes.Clientset, podName, namespace, clusterName string) (*KubeStore, error)

func (*KubeStore) AtomicPutClusterData

func (s *KubeStore) AtomicPutClusterData(ctx context.Context, cd *cluster.ClusterData, previous *KVPair) (*KVPair, error)

func (*KubeStore) GetClusterData

func (s *KubeStore) GetClusterData(ctx context.Context) (*cluster.ClusterData, *KVPair, error)

func (*KubeStore) GetKeepersInfo

func (s *KubeStore) GetKeepersInfo(ctx context.Context) (cluster.KeepersInfo, error)

func (*KubeStore) GetProxiesInfo

func (s *KubeStore) GetProxiesInfo(ctx context.Context) (cluster.ProxiesInfo, error)

func (*KubeStore) GetSentinelsInfo

func (s *KubeStore) GetSentinelsInfo(ctx context.Context) (cluster.SentinelsInfo, error)

func (*KubeStore) PutClusterData

func (s *KubeStore) PutClusterData(ctx context.Context, cd *cluster.ClusterData) error

func (*KubeStore) SetKeeperInfo

func (s *KubeStore) SetKeeperInfo(ctx context.Context, id string, ms *cluster.KeeperInfo, ttl time.Duration) error

func (*KubeStore) SetProxyInfo

func (s *KubeStore) SetProxyInfo(ctx context.Context, pi *cluster.ProxyInfo, ttl time.Duration) error

func (*KubeStore) SetSentinelInfo

func (s *KubeStore) SetSentinelInfo(ctx context.Context, si *cluster.SentinelInfo, ttl time.Duration) error

type Store

type Store interface {
	AtomicPutClusterData(ctx context.Context, cd *cluster.ClusterData, previous *KVPair) (*KVPair, error)
	PutClusterData(ctx context.Context, cd *cluster.ClusterData) error
	GetClusterData(ctx context.Context) (*cluster.ClusterData, *KVPair, error)
	SetKeeperInfo(ctx context.Context, id string, ms *cluster.KeeperInfo, ttl time.Duration) error
	GetKeepersInfo(ctx context.Context) (cluster.KeepersInfo, error)
	SetSentinelInfo(ctx context.Context, si *cluster.SentinelInfo, ttl time.Duration) error
	GetSentinelsInfo(ctx context.Context) (cluster.SentinelsInfo, error)
	SetProxyInfo(ctx context.Context, pi *cluster.ProxyInfo, ttl time.Duration) error
	GetProxiesInfo(ctx context.Context) (cluster.ProxiesInfo, error)
}

type WriteOptions

type WriteOptions struct {
	TTL time.Duration
}

Jump to

Keyboard shortcuts

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