habolt

package module
v0.0.0-...-1c8c94f Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2018 License: MPL-2.0 Imports: 22 Imported by: 0

README

High Availability Bolt Key-Value Store

Bolt with High-Availability

  • hashicorp/serf
  • hashicorp/raft

Documentation

Index

Constants

View Source
const (
	// DEBUG log level
	DEBUG = 0
	// INFO log level
	INFO = 1
	// WARNING log level
	WARNING = 2
	// ERROR log level
	ERROR = 3
)

Variables

View Source
var (
	// ErrMissingPath for a wrong configuration
	ErrMissingPath = errors.New("NewStaticStore missing Path")
	// ErrKeyNotFound for a given key which does not exist
	ErrKeyNotFound = errors.New("DB Key not found")
)

Functions

This section is empty.

Types

type HaAddress

type HaAddress struct {
	Address string
	Port    uint16
}

HaAddress is a helper struct to define our listening ip:port addresses between Serf & Raft

func NewAddress

func NewAddress(addr string, port int) *HaAddress

NewAddress create a new HaAddress with an ip string and a port int

func NewListen

func NewListen(listen string, autoIp ...bool) (*HaAddress, error)

NewListen create a new HaAddress thanks an "ip:port" string

func (*HaAddress) Md5

func (hal *HaAddress) Md5() string

Md5 return a MD5 hash of the string "Address:Port"

func (*HaAddress) Raft

func (hal *HaAddress) Raft() *HaAddress

Raft convert our HaAddress for Raft (Port + 1)

func (*HaAddress) String

func (hal *HaAddress) String() string

type HaOutput

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

HaOutput implements "io.Writer" interface to filter output content.

func NewOutput

func NewOutput(l int) *HaOutput

NewOutput create a new HaOutput with the log level defined in parameter

func NewOutputStr

func NewOutputStr(s string) (*HaOutput, error)

NewOutputStr create a new HaOutput thanks a log level string ("debug", "warning", "error", "info")

func (*HaOutput) Level

func (hao *HaOutput) Level(l int)

Level change the current log level with value in parameter

func (*HaOutput) Write

func (hao *HaOutput) Write(p []byte) (n int, err error)

Write filter the parameter and output it if needed

type HaStore

type HaStore struct {
	Bind      *HaAddress
	Advertise *HaAddress
	// contains filtered or unexported fields
}

HaStore is a wrapper of our StaticStore with Serf & Raft running to replicate all data between nodes.

func NewHaStore

func NewHaStore(bindAddr, advAddr *HaAddress, opts *Options) (*HaStore, error)

NewHaStore create a new HaStore, "bindAddr" will be the local IP:PORT listening address "advAddr" will be the advertised IP:PORT address (for NAT Traversal)

func (*HaStore) Addresses

func (has *HaStore) Addresses() ([]HaAddress, error)

Addresses retrieved the list of addresses in our Raft cluster

func (*HaStore) Close

func (has *HaStore) Close() error

Close to close the embeded Store

func (*HaStore) Delete

func (has *HaStore) Delete(key string) error

Delete forware the "key"/"value" as an UserEvent to our Serf cluster This event will be catched by the Leader of the Raft server to apply it everywhere

func (*HaStore) Get

func (has *HaStore) Get(key string, value interface{}) error

Get retreive a specific value in our Store thanks its key.

func (*HaStore) List

func (has *HaStore) List(values interface{}, patterns ...string) error

List retreive all values in our Store, you could filter by keys with wildcard patterns (i.e. "prefix_*")

func (*HaStore) ListRaw

func (has *HaStore) ListRaw() (map[string]string, error)

ListRaw retreive all key-values as a string without any modification

func (*HaStore) LogLevel

func (has *HaStore) LogLevel(level int)

LogLevel to change the log level value (LVL_INFO by DEFAULT)

func (*HaStore) Logger

func (has *HaStore) Logger() *log.Logger

Logger return the logger of our Store (to implements Store interface)

func (*HaStore) Set

func (has *HaStore) Set(key string, value interface{}) error

Set forward the "key"/"value" as an UserEvent to our Serf cluster This event will be catched by the Leader of the Raft server to apply it everywhere

func (*HaStore) Start

func (has *HaStore) Start(peers ...string) error

Start run the Serf & Raft communication and event handlers You could pass some node's addresses "ip:port" in parameters to join an existing cluster

type Options

type Options struct {
	// Path is the file path to the BoltDB to use
	Path string

	// BoltDB file mode
	FileMode os.FileMode

	// Bucket to create at the beginning
	Bucket string

	// BoltOptions contains any specific BoltDB options you might
	// want to specify [e.g. open timeout]
	BoltOptions *bolt.Options

	// NoSync causes the database to skip fsync calls after each
	// write to the log. This is unsafe, so it should be used
	// with caution.
	NoSync bool

	// Where our default Logger will output logs
	LogOutput io.Writer

	// Logger to use everywhere, if nil a new log.Logger will be defined with LogOutput
	Logger *log.Logger
}

Options contains all the configuraiton used to open the BoltDB

type StaticStore

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

StaticStore is a wrapper of BoltDB which implements our Store interface

func NewStaticStore

func NewStaticStore(options *Options) (*StaticStore, error)

NewStaticStore uses the supplied options to open the BoltDB and prepare it for use as a raft backend.

func (*StaticStore) Addresses

func (s *StaticStore) Addresses() ([]HaAddress, error)

Addresses return slice which contains a signe entry : "GetPrivateIP" from go-sockaddr

func (*StaticStore) BindTo

func (s *StaticStore) BindTo(addr *HaAddress)

BindTo change the behavior of "Addresses" function to return another IP address

func (*StaticStore) Close

func (s *StaticStore) Close() error

Close is used to gracefully close the DB connection.

func (*StaticStore) Delete

func (s *StaticStore) Delete(key string) error

Delete removes the "key" in BoltDB

func (*StaticStore) Get

func (s *StaticStore) Get(key string, value interface{}) error

Get retreive the value associated to the "key" in BoltDB and "json.Unmashal" it to "value"

func (*StaticStore) List

func (s *StaticStore) List(values interface{}, patterns ...string) error

List retreive all values in our BoltDB, evertyhing will be "unmarshal" thanks a JSON format BoltDB keys could be filtering thanks wildcard patterns

func (*StaticStore) ListRaw

func (s *StaticStore) ListRaw() (map[string]string, error)

ListRaw retrive all "key"/"value" with any modification

func (*StaticStore) LogLevel

func (s *StaticStore) LogLevel(level int)

LogLevel change the level of logs, only available with our HabOuput

func (*StaticStore) Logger

func (s *StaticStore) Logger() *log.Logger

Logger return the log.Logger object

func (*StaticStore) Set

func (s *StaticStore) Set(key string, value interface{}) error

Set "json.Mashal" the "value" and store it in BoltDB with the specified "key"

func (*StaticStore) Sync

func (s *StaticStore) Sync() error

Sync performs an fsync on the database file handle. This is not necessary under normal operation unless NoSync is enabled, in which this forces the database file to sync against the disk.

type Store

type Store interface {
	Close() error
	ListRaw() (map[string]string, error)
	List(interface{}, ...string) error
	Get(string, interface{}) error
	Set(string, interface{}) error
	Delete(string) error
	Addresses() ([]HaAddress, error)
	Logger() *log.Logger
	LogLevel(int)
}

Store interface to define useful functions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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