kvdbproxy

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package kvdbproxy implements proxy for a kvdbsync with ability to skip selected change events.

The primary use case is:

  • a plugin watches configuration in key-value datastore and processes the changes in a "standard" way
  • a part of the configuration is processed "alternatively" and it is persisted into key-value datastore afterwards
  • the change events caused by persisting need to be ignored since the change is already applied

The limitations:

  • it is not possible to define multiple ignored events for the key.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is default instance of Plugin.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	infra.PluginDeps

	KVDB kvsyncDelegate
}

Deps group the dependencies of the Plugin

type KvdbsyncMock

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

KvdbsyncMock mocks the behavior of kvdbproxy plugin for test purposes

func (*KvdbsyncMock) AddIgnoreEntry

func (kv *KvdbsyncMock) AddIgnoreEntry(key string, op datasync.Op)

AddIgnoreEntry is a mock function that currently does nothing.

func (*KvdbsyncMock) Delete

func (kv *KvdbsyncMock) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)

Delete mocks the delete operation. If the key matches a prefix that is watched it generates a change event.

func (*KvdbsyncMock) Put

func (kv *KvdbsyncMock) Put(key string, data proto.Message, opts ...datasync.PutOption) error

Put mocks the put operation. If the key matches a prefix that is watched it generates a change event.

func (*KvdbsyncMock) Watch

func (kv *KvdbsyncMock) Watch(resyncName string, changeChan chan datasync.ChangeEvent,
	resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error)

Watch mocks the watch operation. It stores the changeChan and keyPrefixes for the subsequent asserts. Other arguments are ignored.

type Option

type Option func(*Plugin)

Option is a function that acts on a Plugin to inject Dependencies or configuration

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

type Plugin

type Plugin struct {
	Deps
	sync.Mutex
	// contains filtered or unexported fields
}

Plugin implements proxy for a kvdbsync with ability to skip selected change events. The primary use case is:

  • a plugin watches configuration in key-value datastore and processes the changes in a "standard" way
  • a part of the configuration is processed "alternatively" and it is persisted into key-value datastore afterwards
  • the change events caused by persisting need to be ignored since the change is already applied

The limitations:

  • it is not possible to define multiple ignored events for the key.

func NewPlugin

func NewPlugin(opts ...Option) *Plugin

NewPlugin creates a new Plugin with the provides Options

func (*Plugin) AddIgnoreEntry

func (plugin *Plugin) AddIgnoreEntry(key string, op datasync.Op)

AddIgnoreEntry adds the entry into ignore list. The first change event matching the given key and operation is skipped. Once the event is skipped the entry is removed from the list.

func (*Plugin) Close

func (plugin *Plugin) Close() error

Close cleans up the resources allocated by the plugin

func (*Plugin) DelIgnoreEntry

func (plugin *Plugin) DelIgnoreEntry(key string)

DelIgnoreEntry removes the entry from ignore list. E.g.: The method might be used if the call that was supposed to generate the change failed.

func (*Plugin) Delete

func (plugin *Plugin) Delete(key string, opts ...datasync.DelOption) (existed bool, err error)

Delete deletes data from a datastore using the injected kvdbsync plugin.

func (*Plugin) Init

func (plugin *Plugin) Init() error

Init initializes internal members of the plugin.

func (*Plugin) Put

func (plugin *Plugin) Put(key string, data proto.Message, opts ...datasync.PutOption) error

Put puts data into a datastore using the injected kvdbsync plugin.

func (*Plugin) Watch

func (plugin *Plugin) Watch(resyncName string, changeChan chan datasync.ChangeEvent,
	resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error)

Watch forwards the subscription request to the injected kvdbsync plugin. The change events are filtered based on the plugin ignore list. The resync events are untouched.

type Proxy

type Proxy interface {
	// AddIgnoreEntry adds the entry into ignore list. The first change event matching the given key and operation
	// is skipped. Once the event is skipped the entry is removed from the list.
	AddIgnoreEntry(key string, op datasync.Op)

	// Watch forwards the subscription request to the injected kvdbsync plugin. The change events
	// are filtered based on the plugin ignore list. The resync events are untouched.
	Watch(resyncName string, changeChan chan datasync.ChangeEvent,
		resyncChan chan datasync.ResyncEvent, keyPrefixes ...string) (datasync.WatchRegistration, error)

	// Put puts data into a datastore using the injected kvdbsync plugin.
	Put(key string, data proto.Message, opts ...datasync.PutOption) error

	// Delete deletes data from a datastore using the injected kvdbsync plugin.
	Delete(key string, opts ...datasync.DelOption) (existed bool, err error)
}

Proxy forwards calls to a kvdbsync plugin. It allows to filter changeEvents that come from the plugin.

func NewKvdbsyncMock

func NewKvdbsyncMock() Proxy

NewKvdbsyncMock creates new instance of KvdbsyncMock

Jump to

Keyboard shortcuts

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