utils

package
v0.0.0-...-4c0c530 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: BSD-3-Clause Imports: 31 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"
)
View Source
const MaxCodecSize = 100_000_000

Variables

View Source
var (
	ErrIncorrectGenesisChainTxType = errors.New("incorrect genesis chain tx type")
)
View Source
var ErrNotFound = errors.New("not found")

Functions

func CacheKey

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

func CommonAddressHexRepair

func CommonAddressHexRepair(address *common.Address) string

func ErrIsDuplicateEntryError

func ErrIsDuplicateEntryError(err error) bool

func ErrIsLockError

func ErrIsLockError(err error) bool

func ForceParseTimeParam

func ForceParseTimeParam(dsn string) (string, error)

func KeyFromParts

func KeyFromParts(parts ...string) string

func NewAVMCodec

func NewAVMCodec(networkID uint32) (codec.Manager, error)

Types

type Cache

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

func NewCache

func NewCache() Cache

type CacheJob

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

type Cacheable

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

Cacheable is a keyed CacheableFn

type CacheableFn

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

CacheableFn is a function whose output can safely be cached

type Cacher

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

type Collector

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

func NewCollectors

func NewCollectors(collectors ...Collector) Collector

func NewCounterIncCollect

func NewCounterIncCollect(key string) Collector

func NewCounterObserveMillisCollect

func NewCounterObserveMillisCollect(key string) Collector

func NewHistogramCollect

func NewHistogramCollect(key string) Collector

func NewSuccessFailCounterAdd

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

func NewSuccessFailCounterInc

func NewSuccessFailCounterInc(keySuccess string, keyFail string) Collector

type Conn

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

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

func New

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

New creates a new DB for the given config

func (*Conn) Close

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

func (*Conn) NewSession

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

func (*Conn) NewSessionForEventReceiver

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

func (*Conn) SetConnMaxIdleTime

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

func (*Conn) SetConnMaxLifetime

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

func (*Conn) SetMaxIdleConns

func (c *Conn) SetMaxIdleConns(n int)

func (*Conn) SetMaxOpenConns

func (c *Conn) SetMaxOpenConns(n int)

type Connections

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

func NewDBFromConfig

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

func (Connections) Close

func (c Connections) Close() error

func (Connections) DB

func (c Connections) DB() *Conn

func (Connections) Stream

func (c Connections) Stream() *EventRcvr

type CounterID

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

func NewCounterID

func NewCounterID() *CounterID

func (*CounterID) Add

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

type DelayCache struct {
	Cache  Cacher
	Worker Worker
}

func NewDelayCache

func NewDelayCache(cache Cacher) *DelayCache

func (*DelayCache) Processor

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

type EventRcvr

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

func (*EventRcvr) NewJob

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

func (*EventRcvr) SetLog

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

type ExecIface

type ExecIface interface {
	Exec()
}

type GenesisContainer

type GenesisContainer struct {
	NetworkID          uint32
	SwapChainGenesisTx *platformvm.Tx
	SwapChainID        ids.ID
	AxcAssetID         ids.ID
	GenesisBytes       []byte
}

func NewGenesisContainer

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

type IndexedList

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

func NewIndexedList

func NewIndexedList(maxSize int) IndexedList

type LCache

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

func NewTTLMap

func NewTTLMap() *LCache

func (*LCache) Get

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

func (*LCache) Put

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

func (*LCache) Stop

func (m *LCache) Stop()

type ListenCloser

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

ListenCloser listens for messages until it's asked to close

type Metrics

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

func (*Metrics) CounterAdd

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

func (*Metrics) CounterInc

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

func (*Metrics) CounterInit

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

func (*Metrics) HistogramInit

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

func (*Metrics) HistogramObserve

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

func (*Metrics) Init

func (m *Metrics) Init()

type RetrySleeper

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

func NewRetrySleeper

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

func (*RetrySleeper) Inc

func (r *RetrySleeper) Inc()

type Running

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

func NewRunning

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