dmap

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DeleteHits is the number of deletion requests resulting in an item being removed.
	DeleteHits = stats.NewInt64Counter()

	// DeleteMisses is the number of deletion requests for missing keys.
	DeleteMisses = stats.NewInt64Counter()
)
View Source
var (
	// ErrKeyNotFound is returned when a key could not be found.
	ErrKeyNotFound  = errors.New("key not found")
	ErrDMapNotFound = errors.New("dmap not found")
	ErrServerGone   = errors.New("server is gone")
)
View Source
var (
	// GetMisses is the number of entries that have been requested and not found
	GetMisses = stats.NewInt64Counter()

	// GetHits is the number of entries that have been requested and found present
	GetHits = stats.NewInt64Counter()

	// EvictedTotal is the number of entries removed from cache to free memory for new entries.
	EvictedTotal = stats.NewInt64Counter()
)
View Source
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")
)
View Source
var (
	ErrKeyFound      = errors.New("key found")
	ErrWriteQuorum   = errors.New("write quorum cannot be reached")
	ErrKeyTooLarge   = errors.New("key too large")
	ErrEntryTooLarge = errors.New("entry too large for the configured table size")
)
View Source
var EntriesTotal = stats.NewInt64Counter()

EntriesTotal is the total number of entries(including replicas) stored during the life of this instance.

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

ErrReadQuorum means that read quorum cannot be reached to operate.

Functions

func NewService

func NewService(e *environment.Environment) (service.Service, error)

Types

type DMap

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

DMap implements a single-hop distributed hash table.

func (*DMap) Decr

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

func (*DMap) Delete

func (dm *DMap) Delete(ctx context.Context, keys ...string) (int, 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

func (dm *DMap) Destroy(ctx context.Context) 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, Put with EX and Destroy methods concurrently on the cluster, Put and Put with EX calls may set new values to the DMap.

func (*DMap) Expire

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

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

func (*DMap) Get

func (dm *DMap) Get(ctx context.Context, key string) (storage.Entry, 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.

func (*DMap) GetPut

func (dm *DMap) GetPut(ctx context.Context, key string, value interface{}) (storage.Entry, error)

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

func (*DMap) Incr

func (dm *DMap) Incr(ctx context.Context, 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) IncrByFloat added in v0.5.0

func (dm *DMap) IncrByFloat(ctx context.Context, key string, delta float64) (float64, error)

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

func (*DMap) Lease added in v0.5.0

func (dm *DMap) Lease(ctx context.Context, key string, token []byte, timeout time.Duration) error

Lease takes key and token and tries to update the expiry with duration. It redirects the request to the partition owner, if required.

func (*DMap) Lock

func (dm *DMap) Lock(ctx context.Context, key string, timeout, deadline time.Duration) ([]byte, error)

Lock prepares a token and env, then calls tryLock

func (*DMap) Name

func (dm *DMap) Name() string

Name exposes name of the DMap.

func (*DMap) Put

func (dm *DMap) Put(ctx context.Context, key string, value interface{}, cfg *PutConfig) 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 a string. value type is arbitrary. It is safe to modify the contents of the arguments after Put returns but not before.

func (*DMap) Scan added in v0.5.0

func (dm *DMap) Scan(partID, cursor uint64, sc *ScanConfig) ([]string, uint64, error)

func (*DMap) Unlock added in v0.5.0

func (dm *DMap) Unlock(ctx context.Context, key string, token []byte) error

Unlock takes key and token and tries to unlock the key. It redirects the request to the partition owner, if required.

type Entry

type Entry struct {
	Key       string
	Value     interface{}
	TTL       int64
	Timestamp int64
}

Entry is a DMap entry with its metadata.

type PutConfig added in v0.5.0

type PutConfig struct {
	HasEX         bool
	EX            time.Duration
	HasPX         bool
	PX            time.Duration
	HasEXAT       bool
	EXAT          time.Duration
	HasPXAT       bool
	PXAT          time.Duration
	HasNX         bool
	HasXX         bool
	OnlyUpdateTTL bool
}

type ScanConfig added in v0.5.0

type ScanConfig struct {
	HasCount bool
	Count    int
	HasMatch bool
	Match    string
	Replica  bool
}

type ScanOption added in v0.5.0

type ScanOption func(*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 Service

type Service struct {
	sync.RWMutex // protects dmaps map
	// contains filtered or unexported fields
}

func (*Service) NewDMap

func (s *Service) NewDMap(name string) (*DMap, error)

NewDMap creates and returns a new DMap instance. It checks member count quorum and bootstrapping status before creating a new DMap.

func (*Service) RegisterHandlers added in v0.5.0

func (s *Service) RegisterHandlers()

func (*Service) Shutdown

func (s *Service) Shutdown(ctx context.Context) error

func (*Service) Start

func (s *Service) Start() error

Start starts the distributed map service.

Jump to

Keyboard shortcuts

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