utils

package
v1.9.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DriverMysql = "mysql"
	DriverNone  = ""
)
View Source
const (
	DeadlockDBErrorMessage = "Deadlock found when trying to get lock; try restarting transaction"
	TimeoutDBErrorMessage  = "Lock wait timeout exceeded; try restarting transaction"
)
View Source
const (
	WorkerQueueSize   = 10
	WorkerThreadCount = 1
)
View Source
const (
	CacheSeparator = "|"
)
View Source
const (
	KeyValueBootstrap = "bootstrap"
)

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

func CacheKey added in v1.6.2

func CacheKey(networkID uint32, parts ...string) string

func CommonAddressHexRepair added in v1.2.3

func CommonAddressHexRepair(address *common.Address) string

func ErrIsDuplicateEntryError added in v1.6.2

func ErrIsDuplicateEntryError(err error) bool

func ErrIsLockError added in v1.6.2

func ErrIsLockError(err error) bool

func ForceParseTimeParam added in v1.6.2

func ForceParseTimeParam(dsn string) (string, error)

func KeyFromParts added in v1.6.2

func KeyFromParts(parts ...string) string

Types

type Cache added in v1.6.2

type Cache interface {
	Get(context.Context, string) ([]byte, error)
	Set(context.Context, string, []byte, time.Duration) error
}

func NewCache added in v1.6.2

func NewCache() Cache

type CacheJob added in v1.6.2

type CacheJob struct {
	Key  string
	Body *[]byte
	TTL  time.Duration
}

type Cacheable added in v1.6.2

type Cacheable struct {
	Key         []string
	CacheableFn CacheableFn
	TTL         time.Duration
}

Cacheable is a keyed CacheableFn

type CacheableFn added in v1.6.2

type CacheableFn func(context.Context) (interface{}, error)

CacheableFn is a function whose output can safely be cached

type Cacher added in v1.6.2

type Cacher interface {
	Get(context.Context, string) ([]byte, error)
	Set(context.Context, string, []byte, time.Duration) error
}

type Collector added in v1.6.2

type Collector interface {
	Error()
	Collect() error
}

func NewCollectors added in v1.6.2

func NewCollectors(collectors ...Collector) Collector

func NewCounterIncCollect added in v1.6.2

func NewCounterIncCollect(key string) Collector

func NewCounterObserveMillisCollect added in v1.6.2

func NewCounterObserveMillisCollect(key string) Collector

func NewHistogramCollect added in v1.6.2

func NewHistogramCollect(key string) Collector

func NewSuccessFailCounterAdd added in v1.6.2

func NewSuccessFailCounterAdd(keySuccess string, keyFail string, count float64) Collector

func NewSuccessFailCounterInc added in v1.6.2

func NewSuccessFailCounterInc(keySuccess string, keyFail string) Collector

type Conn added in v1.6.2

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

Conn is a wrapper around a dbr connection and a health stream

func New added in v1.6.2

func New(eventer *EventRcvr, conf cfg.DB, ro bool) (*Conn, error)

New creates a new DB for the given config

func (*Conn) Close added in v1.6.2

func (c *Conn) Close(context.Context) error

func (*Conn) NewSession added in v1.6.2

func (c *Conn) NewSession(name string, timeout time.Duration) (*dbr.Session, error)

func (*Conn) NewSessionForEventReceiver added in v1.6.2

func (c *Conn) NewSessionForEventReceiver(er dbr.EventReceiver) *dbr.Session

func (*Conn) SetConnMaxIdleTime added in v1.6.2

func (c *Conn) SetConnMaxIdleTime(d time.Duration)

func (*Conn) SetConnMaxLifetime added in v1.6.2

func (c *Conn) SetConnMaxLifetime(d time.Duration)

func (*Conn) SetMaxIdleConns added in v1.6.2

func (c *Conn) SetMaxIdleConns(n int)

func (*Conn) SetMaxOpenConns added in v1.6.2

func (c *Conn) SetMaxOpenConns(n int)

type Connections added in v1.6.2

type Connections struct {
	Eventer *EventRcvr
	// contains filtered or unexported fields
}

func NewDBFromConfig added in v1.6.2

func NewDBFromConfig(conf cfg.Services, ro bool) (*Connections, error)

func (Connections) Close added in v1.6.2

func (c Connections) Close() error

func (Connections) DB added in v1.6.2

func (c Connections) DB() *Conn

func (Connections) Stream added in v1.6.2

func (c Connections) Stream() *EventRcvr

type CounterID

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

func NewCounterID

func NewCounterID() *CounterID

func (*CounterID) Add added in v1.1.3

func (c *CounterID) Add(v string, delta int64)

func (*CounterID) Clone

func (c *CounterID) Clone() map[string]int64

func (*CounterID) Inc

func (c *CounterID) Inc(v string)

type DelayCache added in v1.6.2

type DelayCache struct {
	Cache  Cacher
	Worker Worker
}

func NewDelayCache added in v1.6.2

func NewDelayCache(cache Cacher) *DelayCache

func (*DelayCache) Processor added in v1.6.2

func (c *DelayCache) Processor(_ int, job interface{})

type EventRcvr added in v1.6.2

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

func (*EventRcvr) NewJob added in v1.6.2

func (e *EventRcvr) NewJob(s string) dbr.EventReceiver

func (*EventRcvr) SetLog added in v1.6.2

func (e *EventRcvr) SetLog(logger logging.Logger)

type ExecIface added in v1.6.2

type ExecIface interface {
	Exec()
}

type GenesisContainer added in v1.6.2

type GenesisContainer struct {
	NetworkID       uint32
	XChainGenesisTx *txs.Tx
	XChainID        ids.ID
	AvaxAssetID     ids.ID
	GenesisBytes    []byte
}

func NewGenesisContainer added in v1.6.2

func NewGenesisContainer(networkID uint32) (*GenesisContainer, error)

type IndexedList added in v1.6.2

type IndexedList interface {
	PushFront(key, val interface{})
	Exists(key interface{}) bool
}

func NewIndexedList added in v1.6.2

func NewIndexedList(maxSize int) IndexedList

type LCache added in v1.6.2

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

func NewTTLMap added in v1.6.2

func NewTTLMap() *LCache

func (*LCache) Get added in v1.6.2

func (m *LCache) Get(k string) ([]byte, bool)

func (*LCache) Put added in v1.6.2

func (m *LCache) Put(k string, v []byte, ttl time.Duration)

func (*LCache) Stop added in v1.6.2

func (m *LCache) Stop()

type ListenCloser added in v1.1.3

type ListenCloser interface {
	Listen() error
	Close() error
}

ListenCloser listens for messages until it's asked to close

type Metrics added in v1.6.2

type Metrics struct {
	// contains filtered or unexported fields
}
var (
	Prometheus Metrics
)

func (*Metrics) CounterAdd added in v1.6.2

func (m *Metrics) CounterAdd(name string, v float64) error

func (*Metrics) CounterInc added in v1.6.2

func (m *Metrics) CounterInc(name string) error

func (*Metrics) CounterInit added in v1.6.2

func (m *Metrics) CounterInit(name string, help string)

func (*Metrics) HistogramInit added in v1.6.2

func (m *Metrics) HistogramInit(name string, help string, buckets []float64)

func (*Metrics) HistogramObserve added in v1.6.2

func (m *Metrics) HistogramObserve(name string, v float64) error

func (*Metrics) Init added in v1.6.2

func (m *Metrics) Init()

type RetrySleeper added in v1.3.2

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

func NewRetrySleeper added in v1.3.2

func NewRetrySleeper(retries uint64, sleepDuration time.Duration, sleepDurationMax time.Duration) *RetrySleeper

func (*RetrySleeper) Inc added in v1.3.2

func (r *RetrySleeper) Inc()

type Running added in v1.3.2

type Running interface {
	Close()
	IsStopped() bool
}

func NewRunning added in v1.3.2

func NewRunning() Running

type Worker

type Worker interface {
	Enque(job interface{})
	TryEnque(job interface{})
	Finish(sleepTime time.Duration)
	JobCnt() int64
	IsFinished() bool
}

func NewWorker

func NewWorker(queueSize int, queueCnt int, processor func(int, interface{})) Worker

Jump to

Keyboard shortcuts

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