Documentation ¶
Overview ¶
Package olricdb provides embeddable, in-memory and distributed key/value store.
Index ¶
- Constants
- Variables
- func NewMemberlistConfig(env string) (*memberlist.Config, error)
- type Config
- type DMap
- func (dm *DMap) Delete(key string) error
- func (dm *DMap) Destroy() error
- func (dm *DMap) Get(key string) (interface{}, 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 OlricDB
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" )
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") )
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, // OlricDB will set it to the hostname of the running machine. Example: node1.my-cluster.net // // Name is also used by the HTTP server as Addr. It should be an IP adress or domain name of the server. Name string // 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 // Default hasher is FNV64a. You may want to use a different hasher which implements // Hasher interface. Hasher Hasher // TLS certificate file for HTTP server. If it's empty, TLS is disabled. CertFile string // TLS key file for HTTP server. If it's empty, TLS is disabled. KeyFile string // A Client is an HTTP client. Its zero value (DefaultClient) is a usable client that uses DefaultTransport. Client *http.Client // HTTP server. Don't set Addr field. It's overwritten by Name field. Server *http.Server // 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 // MemberlistConfig is the memberlist configuration that OlricDB will // use to do the underlying membership management and gossip. Some // fields in the MemberlistConfig will be overwritten by OlricDB no // matter what: // // * Name - This will always be set to the same as the NodeName // in this configuration. // // * Events - OlricDB uses a custom event delegate. // // * Delegate - OlricDB 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 OlricDB instance.
type DMap ¶
type DMap struct {
// contains filtered or unexported fields
}
DMap represents a distributed map object.
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) 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. Please note that, before setting a lock for a key, you should set the key with Put method. Otherwise it returns ErrKeyNotFound error.
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).
type NodeMetadata ¶
type NodeMetadata struct {
Birthdate int64
}
TODO: NodeMetadata will be removed.
type OlricDB ¶
type OlricDB struct {
// contains filtered or unexported fields
}
OlricDB represens an member in the cluster. All functions on the OlricDB structure are safe to call concurrently.