olric: github.com/buraksezer/olric Index | Files | Directories

package olric

import "github.com/buraksezer/olric"

Package olric provides distributed, in-memory and embeddable key/value store, used as a database and cache.

Index

Package Files

cache.go dmap.go dmap_atomic.go dmap_delete.go dmap_destroy.go dmap_eviction.go dmap_expire.go dmap_get.go dmap_lock.go dmap_put.go dmap_query.go olric.go partition.go ping.go pipeline.go query_pipeline.go rebalancer.go routing.go stats.go

Constants

const (
    IfNotFound = int16(1) << iota
    IfFound
)
const NumParallelQuery = 2
const ReleaseVersion string = "0.2.0"

ReleaseVersion is the current stable version of Olric

Variables

var (
    // 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")
)
var (
    ErrKeyFound    = errors.New("key found")
    ErrWriteQuorum = errors.New("write quorum cannot be reached")
)
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")

    // 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")

    // ErrUnknownOperation means that an unidentified message has been received from a client.
    ErrUnknownOperation = errors.New("unknown operation")

    // ErrBadRequest denotes that request body is invalid.
    ErrBadRequest = errors.New("bad request")
)
var ErrEndOfQuery = errors.New("end of query")

ErrEndOfQuery is the error returned by Range when no more data is available. Functions should return ErrEndOfQuery only to signal a graceful end of input.

var ErrReadQuorum = errors.New("read quorum cannot be reached")

type Cursor Uses

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

Cursor implements distributed query on DMaps.

func (*Cursor) Close Uses

func (c *Cursor) Close()

Close cancels the underlying context and background goroutines stops running.

func (*Cursor) Range Uses

func (c *Cursor) Range(f func(key string, value interface{}) bool) error

Range calls f sequentially for each key and value yielded from the cursor. If f returns false, range stops the iteration.

type DMap Uses

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

DMap represents a distributed map instance.

func (*DMap) Decr Uses

func (dm *DMap) Decr(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.

func (*DMap) Delete Uses

func (dm *DMap) Delete(key string) 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.

func (*DMap) Destroy Uses

func (dm *DMap) Destroy() 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/PutEx calls may set new values to the DMap.

func (*DMap) Expire Uses

func (dm *DMap) Expire(key string, timeout time.Duration) error

Expire updates the expiry for the given key. It returns ErrKeyNotFound if the DB does not contains the key. It's thread-safe.

func (*DMap) Get Uses

func (dm *DMap) Get(key string) (interface{}, error)

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) GetPut Uses

func (dm *DMap) GetPut(key string, value interface{}) (interface{}, error)

GetPut atomically sets key to value and returns the old value stored at key.

func (*DMap) Incr Uses

func (dm *DMap) Incr(key string, delta int) (int, error)

Incr atomically increments key by delta. The return value is the new value after being incremented or an error.

func (*DMap) Lock Uses

func (dm *DMap) Lock(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 (*DMap) LockWithTimeout Uses

func (dm *DMap) LockWithTimeout(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 (*DMap) Put Uses

func (dm *DMap) Put(key string, value interface{}) error

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.

func (*DMap) PutEx Uses

func (dm *DMap) PutEx(key string, value interface{}, timeout time.Duration) error

PutEx sets the value for the given key with TTL. It overwrites any previous value for that key. 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.

func (*DMap) PutIf Uses

func (dm *DMap) PutIf(key string, value interface{}, flags int16) error

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. Flag argument currently has two different options:

IfNotFound: Only set the key if it does not already exist. It returns ErrFound if the key already exist.

IfFound: Only set the key if it already exist. It returns ErrKeyNotFound if the key does not exist.

func (*DMap) PutIfEx Uses

func (dm *DMap) PutIfEx(key string, value interface{}, timeout time.Duration, flags int16) error

PutIfEx sets the value for the given key with TTL. It overwrites any previous value for that key. 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. Flag argument currently has two different options:

IfNotFound: Only set the key if it does not already exist. It returns ErrFound if the key already exist.

IfFound: Only set the key if it already exist. It returns ErrKeyNotFound if the key does not exist.

func (*DMap) Query Uses

func (dm *DMap) Query(q query.M) (*Cursor, error)

Query runs a distributed query on a DMap instance. Olric supports a very simple query DSL and now, it only scans keys. The query DSL has very few keywords:

$onKey: Runs the given query on keys or manages options on keys for a given query.

$onValue: Runs the given query on values or manages options on values for a given query.

$options: Useful to modify data returned from a query

Keywords for $options:

$ignore: Ignores a value.

A distributed query looks like the following:

  query.M{
	  "$onKey": query.M{
		  "$regexMatch": "^even:",
		  "$options": query.M{
			  "$onValue": query.M{
				  "$ignore": true,
			  },
		  },
	  },
  }

This query finds the keys starts with "even:", drops the values and returns only keys. If you also want to retrieve the values, just remove the $options directive:

  query.M{
	  "$onKey": query.M{
		  "$regexMatch": "^even:",
	  },
  }

In order to iterate over all the keys:

  query.M{
	  "$onKey": query.M{
		  "$regexMatch": "",
	  },
  }

Query function returns a cursor which has Range and Close methods. Please take look at the Range function for further info.

type LockContext Uses

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

LockContext is returned by Lock and LockWithTimeout methods. It should be stored in a proper way to release the lock.

func (*LockContext) Unlock Uses

func (l *LockContext) Unlock() error

Unlock releases the lock.

type Olric Uses

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

Olric implements a distributed, in-memory and embeddable key/value store and cache.

func New Uses

func New(c *config.Config) (*Olric, error)

New creates a new Olric instance, otherwise returns an error.

func (*Olric) NewDMap Uses

func (db *Olric) NewDMap(name string) (*DMap, error)

NewDMap creates an returns a new DMap instance.

func (*Olric) Ping Uses

func (db *Olric) Ping(addr string) error

Ping sends a dummy protocol messsage to the given host. This is useful to measure RTT between hosts. It also can be used as aliveness check.

func (*Olric) Shutdown Uses

func (db *Olric) Shutdown(ctx context.Context) error

Shutdown stops background servers and leaves the cluster.

func (*Olric) Start Uses

func (db *Olric) Start() error

Start starts background servers and joins the cluster. You still need to call Shutdown method if Start function returns an early error.

func (*Olric) Stats Uses

func (db *Olric) Stats() (stats.Stats, error)

Stats exposes some useful metrics to monitor an Olric node.

type QueryResponse Uses

type QueryResponse map[string]interface{}

QueryResponse denotes returned data by a node for query.

Directories

PathSynopsis
clientPackage client implements a Golang client to access an Olric cluster from outside.
config
hasher
internal/bufpool
internal/discoveryPackage discovery provides a basic memberlist integration.
internal/flogPackage flog is a simple wrapper around Golang's log package which adds verbosity support.
internal/lockerPackage locker provides a mechanism for creating finer-grained locking to help free up more global locks to handle other tasks.
internal/networkPackage network provides utility functions for network-related tasks
internal/protocolPackage protocol implements Olric Binary Protocol.
internal/storagePackage storage implements a GC friendly in-memory storage engine by using map and byte array.
internal/transport
querypackage query implements data structures and helper functions for distributed query subsystem.
serializer
statsPackage stats exposes internal data structures for Stat command

Package olric imports 37 packages (graph) and is imported by 1 packages. Updated 2020-05-04. Refresh now. Tools for package owners.