cluster

package
v0.0.0-...-3a937ec Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProducer

func NewProducer(kv *KV, key string) (p bus.Producer)

func NormalizeKey

func NormalizeKey(v ...string) (res string)

func TrimKeyPrefix

func TrimKeyPrefix(prefix string, key string) (res string)

Types

type Backend

type Backend interface {
	io.Closer

	Ctx() context.Context      // Backend context closes on backend is not available to accept operations
	FailCtx() context.Context  // Fail context closes then backend is failed
	ReadyCtx() context.Context // Ready context closes then backend is ready to accept operations
	Submit(ops []StoreOp)      // Submit ops to backend
	Subscribe(req []WatchRequest)
	CommitChan() chan []StoreCommit
	WatchResultsChan() chan WatchResult
	Leave() // Leave cluster
}

func DefaultBackendFactory

func DefaultBackendFactory(ctx context.Context, log *logx.Log, config Config) (c Backend, err error)

type BackendConfig

type BackendConfig struct {
	Kind    string
	ID      string
	Address string
	Chroot  string
	TTL     time.Duration
}

type BackendFactory

type BackendFactory func(ctx context.Context, log *logx.Log, config Config) (c Backend, err error)

func NewTestingBackendFactory

func NewTestingBackendFactory(backendConfig TestingBackendConfig) (f BackendFactory)

type Config

type Config struct {
	NodeID        string        `mapstructure:"node_id"`
	BackendURL    string        `mapstructure:"backend"` // kind://address/chroot
	Advertise     string        `mapstructure:"advertise"`
	TTL           time.Duration `mapstructure:"ttl"`
	RetryInterval time.Duration `mapstructure:"retry"`
}

Cluster config

func DefaultConfig

func DefaultConfig() (c Config)

func (Config) IsEqual

func (c Config) IsEqual(config Config) (res bool)

func (*Config) Unmarshal

func (c *Config) Unmarshal(readers ...io.Reader) (err error)

type ConsulBackend

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

Consul Backend

func NewConsulBackend

func NewConsulBackend(ctx context.Context, log *logx.Log, config BackendConfig) (w *ConsulBackend)

func (*ConsulBackend) Close

func (b *ConsulBackend) Close() error

func (ConsulBackend) CommitChan

func (b ConsulBackend) CommitChan() chan []StoreCommit

func (ConsulBackend) Ctx

func (b ConsulBackend) Ctx() context.Context

func (ConsulBackend) FailCtx

func (b ConsulBackend) FailCtx() context.Context

func (ConsulBackend) Leave

func (b ConsulBackend) Leave()

func (ConsulBackend) ReadyCtx

func (b ConsulBackend) ReadyCtx() context.Context

func (*ConsulBackend) Submit

func (b *ConsulBackend) Submit(op []StoreOp)

func (*ConsulBackend) Subscribe

func (b *ConsulBackend) Subscribe(req []WatchRequest)

func (ConsulBackend) WatchResultsChan

func (b ConsulBackend) WatchResultsChan() chan WatchResult

type KV

type KV struct {
	*supervisor.Control
	// contains filtered or unexported fields
}

func NewKV

func NewKV(ctx context.Context, log *logx.Log, factory BackendFactory) (b *KV)

func (*KV) Configure

func (k *KV) Configure(config Config)

func (*KV) Open

func (k *KV) Open() (err error)

func (*KV) PermanentStore

func (k *KV) PermanentStore(prefix string) (consumer bus.Consumer)

func (*KV) Producer

func (k *KV) Producer(key string) (producer bus.Producer)

func (*KV) Submit

func (k *KV) Submit(ops []StoreOp)

Submit store operations

func (*KV) SubscribeKey

func (k *KV) SubscribeKey(key string, ctx context.Context, consumer bus.Consumer)

Subscribe for changes

func (*KV) VolatileStore

func (k *KV) VolatileStore(prefix string) (consumer bus.Consumer)

type StoreCommit

type StoreCommit struct {
	ID      string
	Hash    uint64
	WithTTL bool
}

type StoreOp

type StoreOp struct {
	Message bus.Message
	WithTTL bool
}

type TestingBackend

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

Backend for testing purposes

func NewTestingBackend

func NewTestingBackend(ctx context.Context, log *logx.Log, config TestingBackendConfig) (b *TestingBackend)

func (TestingBackend) Close

func (b TestingBackend) Close() error

func (TestingBackend) CommitChan

func (b TestingBackend) CommitChan() chan []StoreCommit

func (TestingBackend) Ctx

func (b TestingBackend) Ctx() context.Context

func (TestingBackend) FailCtx

func (b TestingBackend) FailCtx() context.Context

func (TestingBackend) Leave

func (b TestingBackend) Leave()

func (TestingBackend) ReadyCtx

func (b TestingBackend) ReadyCtx() context.Context

func (*TestingBackend) Submit

func (b *TestingBackend) Submit(ops []StoreOp)

func (*TestingBackend) Subscribe

func (b *TestingBackend) Subscribe(requests []WatchRequest)

func (TestingBackend) WatchResultsChan

func (b TestingBackend) WatchResultsChan() chan WatchResult

type TestingBackendConfig

type TestingBackendConfig struct {
	Consumer    bus.Consumer                           // Track consumer
	ReadyChan   chan struct{}                          // ready channel
	CrashChan   chan struct{}                          // Crash channel
	MessageChan chan map[string]map[string]interface{} // Messages
}

type WatchRequest

type WatchRequest struct {
	Key string
	Ctx context.Context
}

type WatchResult

type WatchResult struct {
	Key  string
	Data map[string][]byte
}

type ZeroBackend

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

Zero backend used for local purposes. Zero backend is never ready.

func NewZeroBackend

func NewZeroBackend(ctx context.Context, log *logx.Log) (w *ZeroBackend)

func (ZeroBackend) Close

func (b ZeroBackend) Close() error

func (ZeroBackend) CommitChan

func (b ZeroBackend) CommitChan() chan []StoreCommit

func (ZeroBackend) Ctx

func (b ZeroBackend) Ctx() context.Context

func (ZeroBackend) FailCtx

func (b ZeroBackend) FailCtx() context.Context

func (ZeroBackend) Leave

func (b ZeroBackend) Leave()

func (ZeroBackend) ReadyCtx

func (b ZeroBackend) ReadyCtx() context.Context

func (*ZeroBackend) Submit

func (w *ZeroBackend) Submit(ops []StoreOp)

func (*ZeroBackend) Subscribe

func (w *ZeroBackend) Subscribe(req []WatchRequest)

func (ZeroBackend) WatchResultsChan

func (b ZeroBackend) WatchResultsChan() chan WatchResult

Jump to

Keyboard shortcuts

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