dbadapter

package
v0.0.0-...-d018c20 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicOperator

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

Operator used for basic key value operations.

func NewBasicOperator

func NewBasicOperator(conn *grpc.ClientConn, timeout time.Duration) *BasicOperator

func (*BasicOperator) DeleteField

func (b *BasicOperator) DeleteField(key string) error

Delete field on database.

key: key to delete the value on. returns: error if request fails.

func (*BasicOperator) DeleteRange

func (b *BasicOperator) DeleteRange(prefix string) error

Delete a range of fields based on a prefix.

prefix: prefix for keys to be deleted. returns: error if request fails.

func (*BasicOperator) GetField

func (b *BasicOperator) GetField(key string) (*string, error)

Get field from database.

key: key to retrieve. returns: value or nil if the value was not found. returns: error if request fails.

func (*BasicOperator) GetRange

func (b *BasicOperator) GetRange(prefix string) (*map[string][]byte, error)

Get a range of fields based on a prefix.

prefix: prefix for keys to be returned. returns: keyvalue-map containing all keys & values that were found for the prefix. returns: error if request fails.

func (*BasicOperator) SetField

func (b *BasicOperator) SetField(key string, value string, leaseId int64) error

Set field to database.

key: key to set the value on. value: value to set. returns: error if request fails.

type DatabaseAdapter

type DatabaseAdapter struct {
	Basic *BasicOperator
	Watch *WatchOperator
	Lease *LeaseOperator
	// contains filtered or unexported fields
}

Object used to interact with the main database bus. It abstracts connection to the kv database used as communication bus & datastore for internal components.

func NewDatabaseAdapter

func NewDatabaseAdapter(uri string, caCerts string, inSecure bool, timeout time.Duration) (*DatabaseAdapter, error)

Initializes DatabaseAdapter, creating the underlying grpc channel. Expects a root cert in the system truststore to verify the certificate provided by the database. @param uri database uri in format "host:port". @param caCerts pem root ca used verify the remote cert. If "" the system trust store is used. @param inSecure option to create insecure connection (no tls). @param timeout context timeout used for requests; if the timeout runs out requests are cancelled.

func (*DatabaseAdapter) Close

func (d *DatabaseAdapter) Close() error

Close underlying connection. The function is idempotent, meaning further calls to Close will not result in an error.

type LeaseOperator

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

Operator used to perform operations.

func NewLeaseOperator

func NewLeaseOperator(conn *grpc.ClientConn, timeout time.Duration) *LeaseOperator

func (*LeaseOperator) GrantLease

func (l *LeaseOperator) GrantLease(ttl int64) (int64, error)

Grants a lease that can be associated with keys.

ttl: ttl in seconds until the lease is revoked (aka all its keys are deleted). returns: lease id that can be used to attach the lease. returns: error if request fails.

func (*LeaseOperator) KeepAliveLease

func (l *LeaseOperator) KeepAliveLease(id int64, interval time.Duration, parentCtx context.Context) error

Register a keepalive loop, that continuously renews the ttl on the lease. This function will block. It runs until the stream gets closed or an error occurs.

id: lease id of the target lease. interval: keep-alive request interval. parentCtx: context used to spawn the stream context from, it can be used to stop the stream. returns: error if the stream fails or the lease was not found. If stream is closed via parentCtx or io.EOF is emitted, nil is returned.

func (*LeaseOperator) RevokeLease

func (l *LeaseOperator) RevokeLease(id int64) error

Revokes a lease, deleting all associated keys immediately.

id: lease id of the lease that should be revoked. returns: error if request fails.

type WatchOperator

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

Operator used for streamed asynchron watch operations.

func NewWatchOperator

func NewWatchOperator(conn *grpc.ClientConn, timeout time.Duration) *WatchOperator

func (*WatchOperator) WatchField

func (w *WatchOperator) WatchField(key string, callback func([]byte, []byte) bool, done func(error)) (context.CancelFunc, error)

Register a field to watch for updates. This function will not block. The worker runs until an error occurs or the context is canceled.

key: key for the field to watch. callback: callback executed when the field changes; provides the new key & new value; return false to cancel context. done; callback executed when the watcher is done (stopped due to context cancellation or failure). returns: cancel function to cancel context -> stopping the watcher. returns: error if creation of the watcher fails.

Jump to

Keyboard shortcuts

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