common

package
v0.8.16 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TxnFailedPrefix is the prefix message for all transaction failure errors.
	TxnFailedPrefix = "txn failed"
)

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

ErrNotFound means an object was not found.

View Source
var MaxMessageSize = 512 * 1024 * 1024

MaxMessageSize for both grpc and etcd communications for driver and rex communications

View Source
var Version = "undefined"

Version contains the cogs version string

Functions

func Delete

func Delete(obj Object) error

Delete deletes an object from the datastore.

func DeleteObjects

func DeleteObjects(objs []Object) error

DeleteObjects deletes a set of objects from the datastore.

func EnsureEtcd

func EnsureEtcd(etcdp **clientv3.Client) error

EnsureEtcd Make sure we always have an etcd connection

func Error

func Error(message string) error

Error creates an error, and logs it righteously

func ErrorE

func ErrorE(message string, err error) error

ErrorE encapsulates err in a structured log and return an abstracted high-level error with message as the payload

func ErrorEF

func ErrorEF(message string, err error, fields log.Fields) error

ErrorEF encapsulates fields and err in a structured log and return an abstracted high-level error with message as the payload

func ErrorF

func ErrorF(message string, fields log.Fields) error

ErrorF encapsulates fields in a structured log and return an abstracted high-level error with message as the payload

func EtcdClient

func EtcdClient() (*clientv3.Client, error)

EtcdClient read the specific configuration files to initiate etcd connection

func EtcdConnect

func EtcdConnect() (*clientv3.Client, error)

EtcdConnect Try to get a etcd client- assumption EtcdClient is async until used

func FromJSON

func FromJSON(o Object, b []byte)

FromJSON reads reads on object from byte array encoded json. If the object is a protobuf, then protobuf is used instead.

func GetIntLike

func GetIntLike(x interface{}) (int, error)

GetIntLike is needed for data that gets cross-serialized and the number format is uncertain. This function works for both float64 and int underlying data types.

func IsTxnFailed

func IsTxnFailed(err error) bool

IsTxnFailed detects if an error is a transaction failure error.

func RUC

func RUC(o Object, update func(o Object)) error

RUC performs a read-update-commit on the provided object using the specified update function.

func Read

func Read(obj Object) error

Read reads an object from the datastore

func ReadNew

func ReadNew(obj Object) error

ReadNew reads an object form the datastore, and does not throw an error if the object is not found.

func ReadObjects

func ReadObjects(objs []Object) (int, error)

ReadObjects reads a set of objects from the datastore in a one-shot transaction.

func ReadRevision

func ReadRevision(obj Object) (revision int64, err error)

ReadRevision reads an object, and returns the etcd key revision for that object

func ReadWait

func ReadWait(obj Object, timer *ReadTimer) error

ReadWait attempts to read an object repeatedly until a timeout threshold is reached defined by timer. If timer is nil the defaults of 30 seconds with a retry period of 250 milliseconds is applied

func ReadWaitObjects added in v0.8.2

func ReadWaitObjects(objs []Object, timer *ReadTimer) error

ReadWaitObjects is readwait for many objects we check that the number of reads is equal to the number of objects (which is what ErrNotFound was doing anyway

func RunObjectTx

func RunObjectTx(otx ObjectTx) error

RunObjectTx runs an object transaction.

func RunObjectTxPrefix

func RunObjectTxPrefix(puts []Object, deletePrefix string) error

RunObjectTxPrefix a bastaradization of RunObjectTx, making it so put is still object array, but delete is a prefix for the txn

func SetEtcdConfig

func SetEtcdConfig(cfg *ServiceConfig)

SetEtcdConfig sets the global etcd configuration settings

func TbModel

func TbModel() *xir.Net

TODO get from MinIO, and watch for changes

func ToJSON

func ToJSON(o Object) string

ToJSON marshals an object to JSON form. If the object is a protobuf, protobuf is used instead.

func Touch

func Touch(obj Object) error

Touch update the key, but not value in data store

func TouchObjects

func TouchObjects(objs []Object) error

TouchObjects updates multiple keys

func TxnFailed

func TxnFailed(message string) error

TxnFailed an error message for transaction failures with the proper formatting.

func Warn

func Warn(message string)

Warn acts like Error, but doesnt return anything

func WarnE

func WarnE(message string, err error)

WarnE includes an error message which is treated as not

func WarnEF

func WarnEF(message string, err error, fields log.Fields)

WarnF includes an encapsulated field to the warning message

func WarnF

func WarnF(message string, fields log.Fields)

WarnF includes an encapsulated field to the warning message

func WithEtcd

func WithEtcd(f func(*clientv3.Client) error) error

WithEtcd executes a function against an etcd client with a managed connection lifetime.

func WithMinEtcd

func WithMinEtcd(f func(*clientv3.Client) (interface{}, error)) (interface{}, error)

WithMinEtcd executes a function against an etcd client with a managed connection lifetime.

func Write

func Write(obj Object, opts ...etcd.OpOption) error

Write persists an object to the datastore.

func WriteObjects

func WriteObjects(objs []Object, fresh bool, opts ...etcd.OpOption) error

WriteObjects writes objects to the datastore in a single shot transaction. If fresh is true, then all objects must be the most recent version, or the write will fail.

Types

type AlertConfig added in v0.8.15

type AlertConfig struct {
	Address  string
	Port     int
	Username string
	Password string
	Type     string
}

type CountSet

type CountSet struct {
	Name   string `json:"name"`
	Size   int    `json:"size,omitempty"`
	Values []int  `json:"values"`
	Offset int    `json:"offset"`
	// contains filtered or unexported fields
}

A CountSet is a dense counter. When the counter is incremented the lowest unused index is returned. When an index is deleted, it's available for use again.

func (CountSet) Add

func (cs CountSet) Add() (int, CountSet, error)

Add increments the counter and returns the created index value.

func (*CountSet) GetVersion

func (c *CountSet) GetVersion() int64

GetVersion returns the current datastore version of the object

func (*CountSet) Key

func (c *CountSet) Key() string

Key returns the datastore key for this object.

func (CountSet) Next

func (cs CountSet) Next() (int, int)

Next returns the nex available index.

func (CountSet) Remove

func (cs CountSet) Remove(i int) CountSet

Remove removes an index from the counter, freeing it for future use.

func (*CountSet) SetVersion

func (c *CountSet) SetVersion(v int64)

SetVersion sets the current datastore version of the object

func (*CountSet) Value

func (c *CountSet) Value() interface{}

Value returns this object as an interface{}

type Object

type Object interface {
	Key() string
	GetVersion() int64
	SetVersion(int64)
	Value() interface{}
}

Object defines an interface for cogs datastore objects.

type ObjectTx

type ObjectTx struct {
	Put    []Object
	Delete []Object
}

ObjectTx encapsulates a set of put and delete operations into a single transaction.

type ReadTimer

type ReadTimer struct {
	Period  time.Duration
	Timeout time.Duration
}

ReadTimer tracks timing information about a read.

type ServiceConfig

type ServiceConfig struct {
	Address string
	Port    int
	TLS     *TLSConfig
}

ServiceConfig encapsulates information for communicating with services.

func (*ServiceConfig) Endpoint

func (s *ServiceConfig) Endpoint() string

Endpoint returns the endpoint string of a service config.

type TLSConfig

type TLSConfig struct {
	Cacert string
	Cert   string
	Key    string
}

TLSConfig defines a TLS configuration for communicating with a service.

Jump to

Keyboard shortcuts

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