Documentation
¶
Overview ¶
Package olric provides distributed, in-memory and embeddable key/value store, used as a database and cache.
Index ¶
- Constants
- Variables
- func NewMemberlistConfig(env string) (*memberlist.Config, error)
- type Config
- type DMap
- func (dm *DMap) Decr(key string, delta int) (int, error)
- func (dm *DMap) Delete(key string) error
- func (dm *DMap) Destroy() error
- func (dm *DMap) Get(key string) (interface{}, error)
- func (dm *DMap) GetPut(key string, value interface{}) (interface{}, error)
- func (dm *DMap) Incr(key string, delta int) (int, error)
- func (dm *DMap) LockWithTimeout(key string, timeout time.Duration) error
- func (dm *DMap) Put(key string, value interface{}) error
- func (dm *DMap) PutEx(key string, value interface{}, timeout time.Duration) error
- func (dm *DMap) Unlock(key string) error
- type Hasher
- type NodeMetadata
- type Olric
- type OpMode
- type Serializer
Constants ¶
const ( // SyncBackupMode enables sync backup mode which means that the caller is blocked // until write/delete operation is applied by backup owners. // The default mode is SyncBackupMode SyncBackupMode = 0 // AsyncBackupMode enables async backup mode which means that write/delete operations // are done in a background task. AsyncBackupMode = 1 )
const ( // DefaultPartitionCount determines default partition count in the cluster. DefaultPartitionCount = 271 // DefaultLoadFactor is used by the consistent hashing function. Keep it small. DefaultLoadFactor = 1.25 // DefaultLogLevel determines the log level without extra configuration. It's DEBUG. DefaultLogLevel = "DEBUG" )
const ReleaseVersion string = "0.1.0"
ReleaseVersion is the current stable version of Olric
Variables ¶
var ( // ErrKeyNotFound is returned when a key could not be found. ErrKeyNotFound = errors.New("key not found") // ErrOperationTimeout is returned when an operation times out. ErrOperationTimeout = errors.New("operation timeout") // ErrInternalServerError means that something unintentionally went wrong while processing the request. ErrInternalServerError = errors.New("internal server error") )
var ErrNoSuchLock = errors.New("no such lock")
ErrNoSuchLock is returned when the requested lock does not exist
Functions ¶
func NewMemberlistConfig ¶
func NewMemberlistConfig(env string) (*memberlist.Config, error)
NewMemberlistConfig returns a new memberlist.Config from vendored version of that package. It takes an env parameter: local, lan and wan.
local: DefaultLocalConfig works like DefaultConfig, however it returns a configuration that is optimized for a local loopback environments. The default configuration is still very conservative and errs on the side of caution.
lan: DefaultLANConfig returns a sane set of configurations for Memberlist. It uses the hostname as the node name, and otherwise sets very conservative values that are sane for most LAN environments. The default configuration errs on the side of caution, choosing values that are optimized for higher convergence at the cost of higher bandwidth usage. Regardless, these values are a good starting point when getting started with memberlist.
wan: DefaultWANConfig works like DefaultConfig, however it returns a configuration that is optimized for most WAN environments. The default configuration is still very conservative and errs on the side of caution.
Types ¶
type Config ¶
type Config struct {
LogLevel string
// Name of this node in the cluster. This must be unique in the cluster. If this is not set,
// Olric will set it to the hostname of the running machine. Example: node1.my-cluster.net
//
// Name is also used by the TCP server as Addr. It should be an IP adress or domain name of the server.
Name string
OperationMode OpMode
KeepAlivePeriod time.Duration
DialTimeout time.Duration
// The list of host:port which are used by memberlist for discovery. Don't confuse it with Name.
Peers []string
// PartitionCount is 271, by default.
PartitionCount uint64
// BackupCount is 0, by default.
BackupCount int
// Default value is SyncBackupMode.
BackupMode int
// LoadFactor is used by consistent hashing function. It determines the maximum load
// for a server in the cluster. Keep it small.
LoadFactor float64
MaxValueSize int
// Default hasher is github.com/cespare/xxhash. You may want to use a different
// hasher which implements Hasher interface.
Hasher Hasher
// Default Serializer implementation uses gob for encoding/decoding.
Serializer Serializer
// TLS certificate file for TCP server. If it's empty, TLS is disabled.
CertFile string
// TLS key file for TCP server. If it's empty, TLS is disabled.
KeyFile string
// LogOutput is the writer where logs should be sent. If this is not
// set, logging will go to stderr by default. You cannot specify both LogOutput
// and Logger at the same time.
LogOutput io.Writer
// Logger is a custom logger which you provide. If Logger is set, it will use
// this for the internal logger. If Logger is not set, it will fall back to the
// behavior for using LogOutput. You cannot specify both LogOutput and Logger
// at the same time.
Logger *log.Logger
SnapshotInterval time.Duration
GCInterval time.Duration
GCDiscardRatio float64
BadgerOptions *badger.Options
// MemberlistConfig is the memberlist configuration that Olric will
// use to do the underlying membership management and gossip. Some
// fields in the MemberlistConfig will be overwritten by Olric no
// matter what:
//
// * Name - This will always be set to the same as the NodeName
// in this configuration.
//
// * Events - Olric uses a custom event delegate.
//
// * Delegate - Olric uses a custom delegate.
//
// You have to use NewMemberlistConfig to create a new one.
// Then, you may need to modify it to tune for your environment.
MemberlistConfig *memberlist.Config
}
Config is the configuration for creating a Olric instance.
type DMap ¶
type DMap struct {
// contains filtered or unexported fields
}
DMap represents a distributed map object.
func (*DMap) Decr ¶
Decr atomically decrements key by delta. The return value is the new value after being decremented or an error.
func (*DMap) Delete ¶
Delete deletes the value for the given key. Delete will not return error if key doesn't exist. It's thread-safe. It is safe to modify the contents of the argument after Delete returns.
func (*DMap) Destroy ¶
Destroy flushes the given DMap on the cluster. You should know that there is no global lock on DMaps. So if you call Put/PutEx and Destroy methods concurrently on the cluster, Put/PutEx calls may set new values to the DMap.
func (*DMap) Get ¶
Get gets the value for the given key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe. It is safe to modify the contents of the returned value. It is safe to modify the contents of the argument after Get returns.
func (*DMap) Incr ¶
Incr atomically increments key by delta. The return value is the new value after being incremented or an error.
func (*DMap) LockWithTimeout ¶
LockWithTimeout sets a lock for the given key. If the lock is still unreleased the end of given period of time, it automatically releases the lock. Acquired lock is only for the key in this map.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until timeout. The timeout is determined by http.Client which can be configured via Config structure.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*DMap) Put ¶
Put sets the value for the given key. It overwrites any previous value for that key and it's thread-safe. The key has to be string. Value type is arbitrary. It is safe to modify the contents of the arguments after Put returns but not before.
type Hasher ¶
Hasher is responsible for generating unsigned, 64 bit hash of provided byte slice. Hasher should minimize collisions (generating same hash for different byte slice) and while performance is also important fast functions are preferable (i.e. you can use FarmHash family).
func NewDefaultHasher ¶
func NewDefaultHasher() Hasher
NewDefaultHasher returns an instance of xxhash package which implements the 64-bit variant of xxHash (XXH64) as described at http://cyan4973.github.io/xxHash/.
type NodeMetadata ¶
type NodeMetadata struct {
Birthdate int64
}
TODO: NodeMetadata will be removed.
type Olric ¶
type Olric struct {
// contains filtered or unexported fields
}
Olric implements a distributed, in-memory and embeddable key/value store.
type OpMode ¶
type OpMode uint8
OpMode is the type for operation modes.
const ( // OpInMemory indicates pure in-memory operation mode. In-memory data structures // are not durable at that mode. OpInMemory OpMode = OpMode(iota) // OpInMemoryWithSnapshot indicates in-memory operation mode with snapshot support. // The in-memory data is durable at that mode. OpInMemoryWithSnapshot )
type Serializer ¶
type Serializer interface {
// Marshal encodes v and returns a byte slice and possible error.
Marshal(v interface{}) ([]byte, error)
// Unmarshal decodes the encoded data and stores the result in the value pointed to by v.
Unmarshal(data []byte, v interface{}) error
}
Serializer interface responsible for encoding/decoding values to transmit over network between Olric nodes.
func NewGobSerializer ¶
func NewGobSerializer() Serializer
NewGobSerializer returns a gob serializer. It's the default one.
func NewJSONSerializer ¶
func NewJSONSerializer() Serializer
NewJSONSerializer returns a json serializer.
func NewMsgpackSerializer ¶
func NewMsgpackSerializer() Serializer
NewMsgpackSerializer returns a msgpack serializer.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client implements a Golang client to access an Olric cluster from outside.
|
Package client implements a Golang client to access an Olric cluster from outside. |
|
cmd
|
|
|
olric-cli
command
|
|
|
olric-cli/cli
Package cli is the Olric command line interface, a simple program that allows to send commands to Olric, and read the replies sent by the server, directly from the terminal.
|
Package cli is the Olric command line interface, a simple program that allows to send commands to Olric, and read the replies sent by the server, directly from the terminal. |
|
olricd
command
|
|
|
olricd/server
Package server provides a standalone server implementation for Olric
|
Package server provides a standalone server implementation for Olric |
|
internal
|
|
|
storage
Package storage implements an off-heap data store which is memory within the runtime that is not subject to Go garbage collection.
|
Package storage implements an off-heap data store which is memory within the runtime that is not subject to Go garbage collection. |