database

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LocksBucket is the default bucket used to store the locks.
	LocksBucket = "_locks"
)

Variables

View Source
var (
	// ErrBucketNotFound is returned when a specific bucket can't be found.
	ErrBucketNotFound = errors.New("bucket not found")
	// ErrNoBucket is returned when trying to put, get or delete a key with no
	// bucket.
	ErrNoBucket = errors.New("no bucket provided")
	// ErrIncompatibleValue is returned when attempting to put/delete/get a key
	// that is actually a bucket or a bucket that is actually a key. Basically
	// that means the bucket path + key is invalid.
	ErrIncompatibleValue = errors.New("incompatible value")
)
View Source
var ErrLockNotFound = errors.New("lock not found")

ErrLockNotFound is the error returned when a lock can't be found.

View Source
var ErrLocksBucketNotFound = errors.New("locks bucket not found")

ErrLocksBucketNotFound is the error returned when the bucket isn't found.

View Source
var ErrNotOwner = errors.New("not the lock owner")

ErrNotOwner is the error returned when ownership of the lock doesn't match.

Functions

func Traverse

func Traverse(t *bolt.Tx, buckets []string) (*bolt.Bucket, error)

Traverse will traverse the whole bucket tree defined in the buckets argument and will fail if a bucket isn't found. This function should be used to find the appropriate bucket for delete and get operations (since they should always be existing keys).

func TraverseCreate

func TraverseCreate(t *bolt.Tx, buckets []string) (*bolt.Bucket, error)

TraverseCreate will traverse the whole bucket tree defined in the buckets argument and will create the necessary buckets if they don't exist. This function will return the last bucket.

Types

type CapybaraDB

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

CapybaraDB is the struct representing a capybara database.

func NewCapybaraDB

func NewCapybaraDB(conf *cmd.Conf, l zerolog.Logger) (*CapybaraDB, error)

NewCapybaraDB creates a new instance of CapybaraDB.

func (*CapybaraDB) ClaimLock

func (cdb *CapybaraDB) ClaimLock(key, owner string, pttl *time.Duration) (*pb.Lock, bool, error)

ClaimLock can be used to claim a lock. If the lock is already owned, it will send back the lock's details. If the service creating this claim is the same as the owner (defined by the owner parameter), the lock's expiration date is delayed.

func (*CapybaraDB) Close

func (c *CapybaraDB) Close() error

Close will close the database.

func (*CapybaraDB) Delete

func (cdb *CapybaraDB) Delete(buckets []string, key string) error

Delete will attempt to delete the provided key in the given bucket path. An error is returned if the operation can't complete.

func (*CapybaraDB) DeletePath

func (cdb *CapybaraDB) DeletePath(path, sep string) error

DeletePath will delete a key given a full path to the key and a separator.

func (*CapybaraDB) Get

func (cdb *CapybaraDB) Get(buckets []string, key string) ([]byte, error)

Get returns the raw value of they key stored in the given bucket path.

func (*CapybaraDB) GetPath

func (cdb *CapybaraDB) GetPath(path, sep string) ([]byte, error)

GetPath will return the path.

func (*CapybaraDB) Put

func (cdb *CapybaraDB) Put(buckets []string, key string, value []byte) error

Put puts a value at the given key in the given bucket. The buckets will be created on the fly if need be. An error will be returned if no bucket is provided or if the path is invalid.

func (*CapybaraDB) PutPath

func (cdb *CapybaraDB) PutPath(path, sep string, value []byte) error

PutPath puts a value at the given path. The buckets will be created on the fly if need be. An error will be returned if no bucket is provided or if the path is invalid.

func (*CapybaraDB) ReleaseLock

func (cdb *CapybaraDB) ReleaseLock(key, owner string) error

ReleaseLock can be used to release (or free) a lock.

Jump to

Keyboard shortcuts

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