Documentation ¶
Overview ¶
Package olric provides a distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
With Olric, you can instantly create a fast, scalable, shared pool of RAM across a cluster of computers.
Olric is designed to be a distributed cache. But it also provides Publish/Subscribe, data replication, failure detection and simple anti-entropy services. So it can be used as an ordinary key/value data store to scale your cloud application.
Index ¶
- Constants
- Variables
- type Client
- type ClusterClient
- func (cl *ClusterClient) Close(ctx context.Context) error
- func (cl *ClusterClient) Members(ctx context.Context) ([]Member, error)
- func (cl *ClusterClient) NewDMap(name string, options ...DMapOption) (DMap, error)
- func (cl *ClusterClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
- func (cl *ClusterClient) Ping(ctx context.Context, addr string) error
- func (cl *ClusterClient) PingWithMessage(ctx context.Context, addr, message string) (string, error)
- func (cl *ClusterClient) RoutingTable(ctx context.Context) (RoutingTable, error)
- func (cl *ClusterClient) Stats(ctx context.Context, options ...StatsOption) (stats.Stats, error)
- type ClusterClientOption
- type ClusterDMap
- func (dm *ClusterDMap) Decr(ctx context.Context, key string, delta int) (int, error)
- func (dm *ClusterDMap) Delete(ctx context.Context, key string) error
- func (dm *ClusterDMap) Destroy(ctx context.Context) error
- func (dm *ClusterDMap) Expire(ctx context.Context, key string, timeout time.Duration) error
- func (dm *ClusterDMap) Get(ctx context.Context, key string) (*GetResponse, error)
- func (dm *ClusterDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
- func (dm *ClusterDMap) Incr(ctx context.Context, key string, delta int) (int, error)
- func (dm *ClusterDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
- func (dm *ClusterDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
- func (dm *ClusterDMap) Name() string
- func (dm *ClusterDMap) Put(ctx context.Context, key string, value interface{}, options ...PutOption) error
- func (dm *ClusterDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
- type ClusterIterator
- type ClusterLockContext
- type ClusterTopologyEvent
- type DMap
- type DMapOption
- type EmbeddedClient
- func (e *EmbeddedClient) Close(_ context.Context) error
- func (e *EmbeddedClient) Members(ctx context.Context) ([]Member, error)
- func (e *EmbeddedClient) NewDMap(name string, options ...DMapOption) (DMap, error)
- func (e *EmbeddedClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
- func (e *EmbeddedClient) NewPubSubWithAddr(addr string) (*PubSub, error)
- func (e *EmbeddedClient) Ping(ctx context.Context, addr string) error
- func (e *EmbeddedClient) PingWithMessage(ctx context.Context, addr, message string) (string, error)
- func (e *EmbeddedClient) RoutingTable(ctx context.Context) (RoutingTable, error)
- func (e *EmbeddedClient) Stats(_ context.Context, options ...StatsOption) (stats.Stats, error)
- type EmbeddedDMap
- func (dm *EmbeddedDMap) Decr(ctx context.Context, key string, delta int) (int, error)
- func (dm *EmbeddedDMap) Delete(ctx context.Context, key string) error
- func (dm *EmbeddedDMap) Destroy(ctx context.Context) error
- func (dm *EmbeddedDMap) Expire(ctx context.Context, key string, timeout time.Duration) error
- func (dm *EmbeddedDMap) Get(ctx context.Context, key string) (*GetResponse, error)
- func (dm *EmbeddedDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
- func (dm *EmbeddedDMap) Incr(ctx context.Context, key string, delta int) (int, error)
- func (dm *EmbeddedDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
- func (dm *EmbeddedDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
- func (dm *EmbeddedDMap) Name() string
- func (dm *EmbeddedDMap) Put(ctx context.Context, key string, value interface{}, options ...PutOption) error
- func (dm *EmbeddedDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
- type EmbeddedIterator
- type EmbeddedLockContext
- type GetResponse
- func (g *GetResponse) Bool() (bool, error)
- func (g *GetResponse) Byte() ([]byte, error)
- func (g *GetResponse) Duration() (time.Duration, error)
- func (g *GetResponse) Float32() (float32, error)
- func (g *GetResponse) Float64() (float64, error)
- func (g *GetResponse) Int() (int, error)
- func (g *GetResponse) Int16() (int16, error)
- func (g *GetResponse) Int32() (int32, error)
- func (g *GetResponse) Int64() (int64, error)
- func (g *GetResponse) Int8() (int8, error)
- func (g *GetResponse) Scan(v interface{}) error
- func (g *GetResponse) String() (string, error)
- func (g *GetResponse) TTL() int64
- func (g *GetResponse) Time() (time.Time, error)
- func (g *GetResponse) Timestamp() int64
- func (g *GetResponse) Uint() (uint, error)
- func (g *GetResponse) Uint16() (uint16, error)
- func (g *GetResponse) Uint32() (uint32, error)
- func (g *GetResponse) Uint64() (uint64, error)
- func (g *GetResponse) Uint8() (uint8, error)
- type Iterator
- type LockContext
- type Member
- type Olric
- type PubSub
- func (ps *PubSub) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub
- func (ps *PubSub) PubSubChannels(ctx context.Context, pattern string) ([]string, error)
- func (ps *PubSub) PubSubNumPat(ctx context.Context) (int64, error)
- func (ps *PubSub) PubSubNumSub(ctx context.Context, channels ...string) (map[string]int64, error)
- func (ps *PubSub) Publish(ctx context.Context, channel string, message interface{}) (int64, error)
- func (ps *PubSub) Subscribe(ctx context.Context, channels ...string) *redis.PubSub
- type PubSubOption
- type PutOption
- type Route
- type RoutingTable
- type ScanOption
- type StatsOption
Constants ¶
const DefaultScanCount = 10
const PingResponse = "PONG"
const ReleaseVersion string = "0.5.0-alpha.2"
ReleaseVersion is the current stable version of Olric
Variables ¶
var ( // ErrKeyNotFound means that returned when a key could not be found. ErrKeyNotFound = errors.New("key not found") // ErrKeyFound means that the requested key found in the cluster. ErrKeyFound = errors.New("key found") // ErrWriteQuorum means that write quorum cannot be reached to operate. ErrWriteQuorum = errors.New("write quorum cannot be reached") // ErrReadQuorum means that read quorum cannot be reached to operate. ErrReadQuorum = errors.New("read quorum cannot be reached") // ErrLockNotAcquired is returned when the requested lock could not be acquired ErrLockNotAcquired = errors.New("lock not acquired") // ErrNoSuchLock is returned when the requested lock does not exist ErrNoSuchLock = errors.New("no such lock") // ErrClusterQuorum means that the cluster could not reach a healthy numbers of members to operate. ErrClusterQuorum = errors.New("cannot be reached cluster quorum to operate") // ErrKeyTooLarge means that the given key is too large to process. // Maximum length of a key is 256 bytes. ErrKeyTooLarge = errors.New("key too large") )
var ( // ErrOperationTimeout is returned when an operation times out. ErrOperationTimeout = errors.New("operation timeout") // ErrServerGone means that a cluster member is closed unexpectedly. ErrServerGone = errors.New("server is gone") )
var ErrNilResponse = errors.New("storage entry is nil")
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.5.0
type Client interface { NewDMap(name string, options ...DMapOption) (DMap, error) NewPubSub(options ...PubSubOption) (*PubSub, error) Stats(ctx context.Context, options ...StatsOption) (stats.Stats, error) Ping(ctx context.Context, addr string) error PingWithMessage(ctx context.Context, addr, message string) (string, error) RoutingTable(ctx context.Context) (RoutingTable, error) Members(ctx context.Context) ([]Member, error) Close(ctx context.Context) error }
type ClusterClient ¶ added in v0.5.0
type ClusterClient struct {
// contains filtered or unexported fields
}
func NewClusterClient ¶ added in v0.5.0
func NewClusterClient(addresses []string, options ...ClusterClientOption) (*ClusterClient, error)
func (*ClusterClient) Close ¶ added in v0.5.0
func (cl *ClusterClient) Close(ctx context.Context) error
func (*ClusterClient) Members ¶ added in v0.5.0
func (cl *ClusterClient) Members(ctx context.Context) ([]Member, error)
func (*ClusterClient) NewDMap ¶ added in v0.5.0
func (cl *ClusterClient) NewDMap(name string, options ...DMapOption) (DMap, error)
func (*ClusterClient) NewPubSub ¶ added in v0.5.0
func (cl *ClusterClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
func (*ClusterClient) Ping ¶ added in v0.5.0
func (cl *ClusterClient) Ping(ctx context.Context, addr string) error
func (*ClusterClient) PingWithMessage ¶
func (*ClusterClient) RoutingTable ¶ added in v0.5.0
func (cl *ClusterClient) RoutingTable(ctx context.Context) (RoutingTable, error)
func (*ClusterClient) Stats ¶ added in v0.5.0
func (cl *ClusterClient) Stats(ctx context.Context, options ...StatsOption) (stats.Stats, error)
type ClusterClientOption ¶ added in v0.5.0
type ClusterClientOption func(c *clusterClientConfig)
func WithConfig ¶ added in v0.5.0
func WithConfig(c *config.Client) ClusterClientOption
func WithLogger ¶ added in v0.5.0
func WithLogger(l *log.Logger) ClusterClientOption
type ClusterDMap ¶ added in v0.5.0
type ClusterDMap struct {
// contains filtered or unexported fields
}
func (*ClusterDMap) Delete ¶ added in v0.5.0
func (dm *ClusterDMap) Delete(ctx context.Context, key string) error
func (*ClusterDMap) Destroy ¶ added in v0.5.0
func (dm *ClusterDMap) Destroy(ctx context.Context) error
func (*ClusterDMap) Get ¶ added in v0.5.0
func (dm *ClusterDMap) Get(ctx context.Context, key string) (*GetResponse, error)
func (*ClusterDMap) GetPut ¶ added in v0.5.0
func (dm *ClusterDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
func (*ClusterDMap) Lock ¶ added in v0.5.0
func (dm *ClusterDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
func (*ClusterDMap) LockWithTimeout ¶ added in v0.5.0
func (dm *ClusterDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
func (*ClusterDMap) Name ¶ added in v0.5.0
func (dm *ClusterDMap) Name() string
func (*ClusterDMap) Scan ¶ added in v0.5.0
func (dm *ClusterDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
type ClusterIterator ¶ added in v0.5.0
type ClusterIterator struct {
// contains filtered or unexported fields
}
ClusterIterator implements distributed query on DMaps.
func (*ClusterIterator) Close ¶ added in v0.5.0
func (i *ClusterIterator) Close()
func (*ClusterIterator) Key ¶ added in v0.5.0
func (i *ClusterIterator) Key() string
func (*ClusterIterator) Next ¶ added in v0.5.0
func (i *ClusterIterator) Next() bool
type ClusterLockContext ¶ added in v0.5.0
type ClusterLockContext struct {
// contains filtered or unexported fields
}
type ClusterTopologyEvent ¶
type DMap ¶
type DMap interface { // Name exposes name of the DMap. Name() string // 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. Put(ctx context.Context, key string, value interface{}, options ...PutOption) error // Get gets the value for the given key. It returns ErrKeyNotFound if the DB // does not contain the key. It's thread-safe. It is safe to modify the contents // of the returned value. Get(ctx context.Context, key string) (*GetResponse, error) // 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. Delete(ctx context.Context, key string) error // Incr atomically increments key by delta. The return value is the new value // after being incremented or an error. Incr(ctx context.Context, key string, delta int) (int, error) // Decr atomically decrements key by delta. The return value is the new value // after being decremented or an error. Decr(ctx context.Context, key string, delta int) (int, error) // GetPut atomically sets key to value and returns the old value stored at key. GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error) // Expire updates the expiry for the given key. It returns ErrKeyNotFound if // the DB does not contain the key. It's thread-safe. Expire(ctx context.Context, key string, timeout time.Duration) error // Lock sets a lock for the given key. Acquired lock is only for the key in // this dmap. // // It returns immediately if it acquires the lock for the given key. Otherwise, // it waits until deadline. // // You should know that the locks are approximate, and only to be used for // non-critical purposes. Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error) // 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 dmap. // // It returns immediately if it acquires the lock for the given key. Otherwise, // it waits until deadline. // // You should know that the locks are approximate, and only to be used for // non-critical purposes. LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error) Scan(ctx context.Context, options ...ScanOption) (Iterator, error) // 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 call may set new values to the dmap. Destroy(ctx context.Context) error }
DMap describes a distributed map rc.
type DMapOption ¶ added in v0.5.0
type DMapOption func(*dmapConfig)
func StorageEntryImplementation ¶ added in v0.5.0
func StorageEntryImplementation(e func() storage.Entry) DMapOption
type EmbeddedClient ¶ added in v0.5.0
type EmbeddedClient struct {
// contains filtered or unexported fields
}
EmbeddedClient is an Olric rc implementation for embedded-member scenario.
func (*EmbeddedClient) Close ¶ added in v0.5.0
func (e *EmbeddedClient) Close(_ context.Context) error
func (*EmbeddedClient) Members ¶ added in v0.5.0
func (e *EmbeddedClient) Members(ctx context.Context) ([]Member, error)
func (*EmbeddedClient) NewDMap ¶ added in v0.5.0
func (e *EmbeddedClient) NewDMap(name string, options ...DMapOption) (DMap, error)
func (*EmbeddedClient) NewPubSub ¶ added in v0.5.0
func (e *EmbeddedClient) NewPubSub(options ...PubSubOption) (*PubSub, error)
func (*EmbeddedClient) NewPubSubWithAddr ¶
func (e *EmbeddedClient) NewPubSubWithAddr(addr string) (*PubSub, error)
func (*EmbeddedClient) Ping ¶ added in v0.5.0
func (e *EmbeddedClient) Ping(ctx context.Context, addr string) error
Ping sends a dummy protocol message to the given host. This is useful to measure RTT between hosts. It also can be used as aliveness check.
func (*EmbeddedClient) PingWithMessage ¶
PingWithMessage sends a dummy protocol message to the given host. This is useful to measure RTT between hosts. It also can be used as aliveness check.
func (*EmbeddedClient) RoutingTable ¶ added in v0.5.0
func (e *EmbeddedClient) RoutingTable(ctx context.Context) (RoutingTable, error)
func (*EmbeddedClient) Stats ¶ added in v0.5.0
func (e *EmbeddedClient) Stats(_ context.Context, options ...StatsOption) (stats.Stats, error)
Stats exposes some useful metrics to monitor an Olric node.
type EmbeddedDMap ¶ added in v0.5.0
type EmbeddedDMap struct {
// contains filtered or unexported fields
}
EmbeddedDMap is an DMap rc implementation for embedded-member scenario.
func (*EmbeddedDMap) Delete ¶ added in v0.5.0
func (dm *EmbeddedDMap) Delete(ctx context.Context, key string) error
func (*EmbeddedDMap) Destroy ¶ added in v0.5.0
func (dm *EmbeddedDMap) Destroy(ctx context.Context) error
func (*EmbeddedDMap) Get ¶ added in v0.5.0
func (dm *EmbeddedDMap) Get(ctx context.Context, key string) (*GetResponse, error)
func (*EmbeddedDMap) GetPut ¶ added in v0.5.0
func (dm *EmbeddedDMap) GetPut(ctx context.Context, key string, value interface{}) (*GetResponse, error)
func (*EmbeddedDMap) Incr ¶ added in v0.5.0
Incr atomically increments key by delta. The return value is the new value after being incremented or an error.
func (*EmbeddedDMap) Lock ¶ added in v0.5.0
func (dm *EmbeddedDMap) Lock(ctx context.Context, key string, deadline time.Duration) (LockContext, error)
Lock sets a lock for the given key. Acquired lock is only for the key in this dmap.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*EmbeddedDMap) LockWithTimeout ¶ added in v0.5.0
func (dm *EmbeddedDMap) LockWithTimeout(ctx context.Context, key string, timeout, deadline time.Duration) (LockContext, error)
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 dmap.
It returns immediately if it acquires the lock for the given key. Otherwise, it waits until deadline.
You should know that the locks are approximate, and only to be used for non-critical purposes.
func (*EmbeddedDMap) Name ¶ added in v0.5.0
func (dm *EmbeddedDMap) Name() string
func (*EmbeddedDMap) Scan ¶ added in v0.5.0
func (dm *EmbeddedDMap) Scan(ctx context.Context, options ...ScanOption) (Iterator, error)
type EmbeddedIterator ¶ added in v0.5.0
type EmbeddedIterator struct {
// contains filtered or unexported fields
}
EmbeddedIterator implements distributed query on DMaps.
func (*EmbeddedIterator) Close ¶ added in v0.5.0
func (i *EmbeddedIterator) Close()
func (*EmbeddedIterator) Key ¶ added in v0.5.0
func (i *EmbeddedIterator) Key() string
func (*EmbeddedIterator) Next ¶ added in v0.5.0
func (i *EmbeddedIterator) Next() bool
type EmbeddedLockContext ¶ added in v0.5.0
type EmbeddedLockContext struct {
// contains filtered or unexported fields
}
EmbeddedLockContext is returned by Lock and LockWithTimeout methods. It should be stored in a proper way to release the lock.
type GetResponse ¶ added in v0.5.0
type GetResponse struct {
// contains filtered or unexported fields
}
func (*GetResponse) Bool ¶ added in v0.5.0
func (g *GetResponse) Bool() (bool, error)
func (*GetResponse) Byte ¶ added in v0.5.0
func (g *GetResponse) Byte() ([]byte, error)
func (*GetResponse) Duration ¶ added in v0.5.0
func (g *GetResponse) Duration() (time.Duration, error)
func (*GetResponse) Float32 ¶ added in v0.5.0
func (g *GetResponse) Float32() (float32, error)
func (*GetResponse) Float64 ¶ added in v0.5.0
func (g *GetResponse) Float64() (float64, error)
func (*GetResponse) Int ¶ added in v0.5.0
func (g *GetResponse) Int() (int, error)
func (*GetResponse) Int16 ¶ added in v0.5.0
func (g *GetResponse) Int16() (int16, error)
func (*GetResponse) Int32 ¶ added in v0.5.0
func (g *GetResponse) Int32() (int32, error)
func (*GetResponse) Int64 ¶ added in v0.5.0
func (g *GetResponse) Int64() (int64, error)
func (*GetResponse) Int8 ¶ added in v0.5.0
func (g *GetResponse) Int8() (int8, error)
func (*GetResponse) Scan ¶ added in v0.5.0
func (g *GetResponse) Scan(v interface{}) error
func (*GetResponse) String ¶ added in v0.5.0
func (g *GetResponse) String() (string, error)
func (*GetResponse) TTL ¶ added in v0.5.0
func (g *GetResponse) TTL() int64
func (*GetResponse) Timestamp ¶ added in v0.5.0
func (g *GetResponse) Timestamp() int64
func (*GetResponse) Uint ¶ added in v0.5.0
func (g *GetResponse) Uint() (uint, error)
func (*GetResponse) Uint16 ¶ added in v0.5.0
func (g *GetResponse) Uint16() (uint16, error)
func (*GetResponse) Uint32 ¶ added in v0.5.0
func (g *GetResponse) Uint32() (uint32, error)
func (*GetResponse) Uint64 ¶ added in v0.5.0
func (g *GetResponse) Uint64() (uint64, error)
func (*GetResponse) Uint8 ¶ added in v0.5.0
func (g *GetResponse) Uint8() (uint8, error)
type LockContext ¶ added in v0.2.0
type Olric ¶ added in v0.2.0
type Olric struct {
// contains filtered or unexported fields
}
Olric implements a distributed cache and in-memory key/value data store. It can be used both as an embedded Go library and as a language-independent service.
func (*Olric) NewEmbeddedClient ¶ added in v0.5.0
func (db *Olric) NewEmbeddedClient() *EmbeddedClient
type PubSub ¶ added in v0.5.0
type PubSub struct {
// contains filtered or unexported fields
}
func (*PubSub) PSubscribe ¶ added in v0.5.0
func (*PubSub) PubSubChannels ¶ added in v0.5.0
func (*PubSub) PubSubNumPat ¶ added in v0.5.0
func (*PubSub) PubSubNumSub ¶ added in v0.5.0
type PubSubOption ¶ added in v0.5.0
type PubSubOption func(option *pubsubConfig)
func ToAddress ¶ added in v0.5.0
func ToAddress(addr string) PubSubOption
type RoutingTable ¶ added in v0.5.0
type ScanOption ¶ added in v0.5.0
type ScanOption func(*dmap.ScanConfig)
func Count ¶ added in v0.5.0
func Count(c int) ScanOption
func Match ¶ added in v0.5.0
func Match(s string) ScanOption
type StatsOption ¶ added in v0.4.0
type StatsOption func(*statsConfig)
func CollectRuntime ¶ added in v0.4.0
func CollectRuntime() StatsOption
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
olricd/server
Package server provides a standalone server implementation for Olric
|
Package server provides a standalone server implementation for Olric |
internal
|
|
discovery
Package discovery provides a basic memberlist integration.
|
Package discovery provides a basic memberlist integration. |
kvstore
Package kvstore implements a GC friendly in-memory storage engine by using built-in maps and byte slices.
|
Package kvstore implements a GC friendly in-memory storage engine by using built-in maps and byte slices. |
locker
Package locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks.
|
Package locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks. |
pkg
|
|
flog
Package flog is a simple wrapper around Golang's log package which adds verbosity support.
|
Package flog is a simple wrapper around Golang's log package which adds verbosity support. |
service_discovery
Package service_discovery provides ServiceDiscovery interface for plugins
|
Package service_discovery provides ServiceDiscovery interface for plugins |
Package stats exposes internal data structures for Stat command
|
Package stats exposes internal data structures for Stat command |