util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UseSliceCount encode bitmap as Slice
	UseSliceCount = uint64(5)
)

Variables

View Source
var (
	// ErrNotLeader error not leader
	ErrNotLeader = errors.New("election: not leader")
	// ErrNotBootstrapped not bootstrapped
	ErrNotBootstrapped = errors.New("prophet: not bootstrapped")

	// ErrReq invalid request
	ErrReq = errors.New("invalid req")
	// ErrStaleResource  stale resource
	ErrStaleResource = errors.New("stale resource")
	// ErrTombstoneContainer t ombstone container
	ErrTombstoneContainer = errors.New("container is tombstone")

	// ErrSchedulerExisted error with scheduler is existed
	ErrSchedulerExisted = errors.New("scheduler is existed")
	// ErrSchedulerNotFound error with scheduler is not found
	ErrSchedulerNotFound = errors.New("scheduler is not found")
)
View Source
var GetPrefixRangeEnd = clientv3.GetPrefixRangeEnd

GetPrefixRangeEnd get prefix range end

Functions

func AddEtcdMember

func AddEtcdMember(client *clientv3.Client, urls []string) (*clientv3.MemberAddResponse, error)

AddEtcdMember add a member to etcd

func CheckClusterID

func CheckClusterID(localClusterID types.ID, um types.URLsMap) error

CheckClusterID checks etcd cluster ID, returns an error if mismatch. This function will never block even quorum is not satisfied.

func DecodeGroupKey added in v0.2.0

func DecodeGroupKey(key string) uint64

DecodeGroupKey decode group key, returns group id

func DefaultTimeoutWheel

func DefaultTimeoutWheel() *timewheel.TimeoutWheel

DefaultTimeoutWheel returns default timeout wheel

func EmptyPeer

func EmptyPeer(value metapb.Replica) bool

EmptyPeer returns a peer is a empty peer

func EncodeGroupKey added in v0.2.0

func EncodeGroupKey(group uint64, rules []metapb.ScheduleGroupRule, labels []metapb.Pair) string

EncodeGroupKey encode group key

func FindPeer

func FindPeer(peers []*metapb.Replica, containerID uint64) (metapb.Replica, bool)

FindPeer find peer at the spec container

func GeometricMean

func GeometricMean(input Float64Data) (float64, error)

GeometricMean gets the geometric mean for a slice of numbers

func GetCurrentClusterMembers

func GetCurrentClusterMembers(client *clientv3.Client) (*clientv3.MemberListResponse, error)

GetCurrentClusterMembers returns etcd current members

func GetEtcdResp

func GetEtcdResp(client *clientv3.Client, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

GetEtcdResp returns etcd resp

func GetEtcdValue

func GetEtcdValue(client *clientv3.Client, key string, opts ...clientv3.OpOption) ([]byte, int64, error)

GetEtcdValue returns value from etcd storage

func HarmonicMean

func HarmonicMean(input Float64Data) (float64, error)

HarmonicMean gets the harmonic mean for a slice of numbers

func IsNotLeaderError

func IsNotLeaderError(err string) bool

IsNotLeaderError is not leader error

func LeaderTxn

func LeaderTxn(client *clientv3.Client, leaderKey, leaderValue string, cs ...clientv3.Cmp) clientv3.Txn

LeaderTxn returns leader txn

func ListEtcdMembers

func ListEtcdMembers(client *clientv3.Client) (*clientv3.MemberListResponse, error)

ListEtcdMembers returns etcd members

func Max

func Max(input Float64Data) (max float64, err error)

Max finds the highest number in a slice

func MaxUint64

func MaxUint64(a, b uint64) uint64

MaxUint64 max uint64

func Mean

func Mean(input Float64Data) (float64, error)

Mean gets the average of a slice of numbers

func Median

func Median(input Float64Data) (median float64, err error)

Median gets the median number in a slice of numbers

func Min

func Min(input Float64Data) (min float64, err error)

Min finds the lowest number in a set of data

func MinBalanceDiff

func MinBalanceDiff(count uint64) float64

MinBalanceDiff returns the minimal diff to do balance. The formula is based on experience to let the diff increase alone with the count slowly.

func MinDuration

func MinDuration(a, b time.Duration) time.Duration

MinDuration min duration

func MinUint64

func MinUint64(a, b uint64) uint64

MinUint64 min uint64

func Mode

func Mode(input Float64Data) (mode []float64, err error)

Mode gets the mode of a slice of numbers

func MustMarshalBM64

func MustMarshalBM64(bm *roaring64.Bitmap) []byte

MustMarshalBM64 must marshal BM

func MustMarshalBM64To

func MustMarshalBM64To(bm *roaring64.Bitmap, buf *bytes.Buffer)

MustMarshalBM64To must marshal BM

func MustUnmarshalBM64

func MustUnmarshalBM64(data []byte) *roaring64.Bitmap

MustUnmarshalBM64 parse a bitmap

func MustUnmarshalBM64To

func MustUnmarshalBM64To(data []byte, bm *roaring64.Bitmap)

MustUnmarshalBM64To parse a bitmap

func ParseUrls

func ParseUrls(s string) ([]url.URL, error)

ParseUrls parse url

func PopulationVariance

func PopulationVariance(input Float64Data) (pvar float64, err error)

PopulationVariance finds the amount of variance within a population

func PutEtcdWithTTL

func PutEtcdWithTTL(ctx context.Context, c *clientv3.Client, key string, value string, ttlSeconds int64) (*clientv3.PutResponse, error)

PutEtcdWithTTL put (key, value) into etcd with a ttl of ttlSeconds

func StandardDeviation

func StandardDeviation(input Float64Data) (sdev float64, err error)

StandardDeviation the amount of variation in the dataset

func StandardDeviationPopulation

func StandardDeviationPopulation(input Float64Data) (sdev float64, err error)

StandardDeviationPopulation finds the amount of variation from the population

func Sum

func Sum(input Float64Data) (sum float64, err error)

Sum adds all the numbers of a slice together

func Txn

func Txn(client *clientv3.Client) clientv3.Txn

Txn returns etcd txn

Types

type Float64Data

type Float64Data []float64

Float64Data is a named type for []float64 with helper methods

func (Float64Data) Get

func (f Float64Data) Get(i int) float64

Get item in slice

func (Float64Data) Len

func (f Float64Data) Len() int

Len returns length of slice

func (Float64Data) Less

func (f Float64Data) Less(i, j int) bool

Less returns if one number is less than another

func (Float64Data) Max

func (f Float64Data) Max() (float64, error)

Max returns the maximum number in the data

func (Float64Data) Mean

func (f Float64Data) Mean() (float64, error)

Mean returns the mean of the data

func (Float64Data) Median

func (f Float64Data) Median() (float64, error)

Median returns the median of the data

func (Float64Data) Min

func (f Float64Data) Min() (float64, error)

Min returns the minimum number in the data

func (Float64Data) Mode

func (f Float64Data) Mode() ([]float64, error)

Mode returns the mode of the data

func (Float64Data) Sum

func (f Float64Data) Sum() (float64, error)

Sum returns the total of all the numbers in the data

func (Float64Data) Swap

func (f Float64Data) Swap(i, j int)

Swap switches out two numbers in slice

type TTLString

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

TTLString is simple TTL saves key string and value.

func NewStringTTL

func NewStringTTL(ctx context.Context, gcInterval, ttl time.Duration) *TTLString

NewStringTTL creates a new TTLString cache.

func (TTLString) Clear

func (c TTLString) Clear()

Clear removes all items in the ttl cache.

func (*TTLString) Get

func (c *TTLString) Get(id string) (interface{}, bool)

Get return the value by key id

func (TTLString) Len

func (c TTLString) Len() int

Len returns current cache size.

func (*TTLString) Pop

func (c *TTLString) Pop() (string, interface{}, bool)

Pop one key/value that is not expired

func (*TTLString) Put

func (c *TTLString) Put(key string, value interface{})

Put put the string key with the value

func (*TTLString) PutWithTTL

func (c *TTLString) PutWithTTL(key string, value interface{}, ttl time.Duration)

PutWithTTL puts an item into cache with specified TTL.

type TTLUint64

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

TTLUint64 is simple TTL saves only uint64s.

func NewIDTTL

func NewIDTTL(ctx context.Context, gcInterval, ttl time.Duration) *TTLUint64

NewIDTTL creates a new TTLUint64 cache.

func (TTLUint64) Clear

func (c TTLUint64) Clear()

Clear removes all items in the ttl cache.

func (*TTLUint64) Exists

func (c *TTLUint64) Exists(id uint64) bool

Exists checks if an ID exists in cache.

func (*TTLUint64) Get

func (c *TTLUint64) Get(id uint64) (interface{}, bool)

Get return the value by key id

func (*TTLUint64) GetAllID

func (c *TTLUint64) GetAllID() []uint64

GetAllID returns all ids.

func (TTLUint64) Len

func (c TTLUint64) Len() int

Len returns current cache size.

func (*TTLUint64) Put

func (c *TTLUint64) Put(id uint64, value interface{})

Put saves an ID in cache.

func (*TTLUint64) PutWithTTL

func (c *TTLUint64) PutWithTTL(key uint64, value interface{}, ttl time.Duration)

PutWithTTL puts an item into cache with specified TTL.

func (*TTLUint64) Remove

func (c *TTLUint64) Remove(key uint64)

Remove remove key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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