utils

package
v0.0.0-...-e603270 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertTrue

func AssertTrue(b bool)

AssertTrue asserts that b is true. Otherwise, it would log fatal.

func AssertTruef

func AssertTruef(b bool, format string, a ...interface{})

func Ceil

func Ceil(size uint32, align uint32) uint32

func Check

func Check(err error)

func EqualUint32

func EqualUint32(a, b []uint32) bool

func Floor

func Floor(size uint32, align uint32) uint32

func HumanReadableSize

func HumanReadableSize(t uint64) string

func HumanReadableThroughput

func HumanReadableThroughput(t float64) string

func Max

func Max(a, b int) int

func Max64

func Max64(a, b int64) int64

func Min

func Min(a, b int) int

func MustMarshal

func MustMarshal(msg proto.Message) []byte

func MustUnMarshal

func MustUnMarshal(data []byte, msg proto.Message)

func NewMemory

func NewMemory(size int) *memory

func ParseReplicationString

func ParseReplicationString(replication string) (int, int, error)

func SetRandStringBytes

func SetRandStringBytes(data []byte)

func SizeOfBlocks

func SizeOfBlocks(blocks [][]byte) uint32

func SizeVarint

func SizeVarint(x uint64) (n int)

func SplitAndTrim

func SplitAndTrim(s string, sep string) []string

Types

type CRC

type CRC uint32

func NewCRC

func NewCRC(b []byte) CRC

func (CRC) Update

func (c CRC) Update(b []byte) CRC

func (CRC) Value

func (c CRC) Value() uint32

type FileNameSplitAlogrithm

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

func (*FileNameSplitAlogrithm) Split

func (a *FileNameSplitAlogrithm) Split(start, end []byte, numSplits int) ([]Range, error)

func (*FileNameSplitAlogrithm) SplitAllRegions

func (a *FileNameSplitAlogrithm) SplitAllRegions(numSplits int) ([]Range, error)

type HexStringSplitAlgorithm

type HexStringSplitAlgorithm struct{}

func NewHexStringSplitAlgorithm

func NewHexStringSplitAlgorithm() *HexStringSplitAlgorithm

func (*HexStringSplitAlgorithm) Split

func (algo *HexStringSplitAlgorithm) Split(start, end []byte, numSplits int) ([]Range, error)

split's code is from https://github.com/apache/hbase/blob/35aa57e4452c6f0a7f5037371edca64163913345/hbase-server/src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java start and end must be hex string

func (*HexStringSplitAlgorithm) SplitAllRegions

func (algo *HexStringSplitAlgorithm) SplitAllRegions(numSplits int) ([]Range, error)

type HistogramStatus

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

func NewLantencyStatus

func NewLantencyStatus(start int64, end int64) *HistogramStatus

func (*HistogramStatus) Histgram

func (ls *HistogramStatus) Histgram(percentiles []float64, w io.Writer) []int64

func (*HistogramStatus) Record

func (ls *HistogramStatus) Record(n int64) error

type Index

type Index map[string]sets.String

Index maps the indexed value to a set of keys in the store that match on that value

type IndexFunc

type IndexFunc func(obj interface{}) ([]string, error)

IndexFunc knows how to compute the set of indexed values for an object.

type Indexer

type Indexer interface {
	Store
	// Index returns the stored objects whose set of indexed values
	// intersects the set of indexed values of the given object, for
	// the named index
	Index(indexName string, obj interface{}) ([]interface{}, error)
	// IndexKeys returns the storage keys of the stored objects whose
	// set of indexed values for the named index includes the given
	// indexed value
	IndexKeys(indexName, indexedValue string) ([]string, error)
	// ListIndexFuncValues returns all the indexed values of the given index
	ListIndexFuncValues(indexName string) []string
	// ByIndex returns the stored objects whose set of indexed values
	// for the named index includes the given indexed value
	ByIndex(indexName, indexedValue string) ([]interface{}, error)
	// GetIndexer return the indexers
	GetIndexers() Indexers

	// AddIndexers adds more indexers to this store.  If you call this after you already have data
	// in the store, the results are undefined.
	AddIndexers(newIndexers Indexers) error
}

func NewIndexer

func NewIndexer(keyFunc KeyFunc, indexers Indexers) Indexer

NewIndexer returns an Indexer implemented simply with a map and a lock.

type Indexers

type Indexers map[string]IndexFunc

Indexers maps a name to an IndexFunc

type Indices

type Indices map[string]Index

Indices maps a name to an Index

type KeyError

type KeyError struct {
	Obj interface{}
	Err error
}

KeyError will be returned any time a KeyFunc gives an error; it includes the object at fault.

func (KeyError) Error

func (k KeyError) Error() string

Error gives a human-readable description of the error.

func (KeyError) Unwrap

func (k KeyError) Unwrap() error

Unwrap implements errors.Unwrap

type KeyFunc

type KeyFunc func(obj interface{}) (string, error)

KeyFunc knows how to make a key from an object. Implementations should be deterministic.

type LockedSource

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

thread-safe rand

func (*LockedSource) Int63

func (r *LockedSource) Int63() int64

func (*LockedSource) Seed

func (r *LockedSource) Seed(seed int64)

type PrefixSplitAlgorithm

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

func NewPrefixSplitAlgorithm

func NewPrefixSplitAlgorithm(prefixs [][]byte, numSplits int, endfix SplitAlgorithm) *PrefixSplitAlgorithm

func (*PrefixSplitAlgorithm) Split

func (algo *PrefixSplitAlgorithm) Split(start, end []byte, numSplits int) ([]Range, error)

func (*PrefixSplitAlgorithm) SplitAllReginos

func (algo *PrefixSplitAlgorithm) SplitAllReginos(numSplits int) ([]Range, error)

type RandomTicker

type RandomTicker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

RandomTicker is similar to time.Ticker but ticks at random intervals between the min and max duration values (stored internally as int64 nanosecond counts).

func NewRandomTicker

func NewRandomTicker(min, max time.Duration) *RandomTicker

NewRandomTicker returns a pointer to an initialized instance of the RandomTicker. Min and max are durations of the shortest and longest allowed ticks. Ticker will run in a goroutine until explicitly stopped.

func (*RandomTicker) Stop

func (rt *RandomTicker) Stop()

Stop terminates the ticker goroutine and closes the C channel.

type Range

type Range struct {
	StartKey []byte
	EndKey   []byte
}

func (Range) String

func (r Range) String() string

type Result

type Result struct {
	Percetage float64
	Lantency  float64
}

type SafeMutex

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

SafeMutex can be used in place of sync.RWMutex. It allows code to assert whether the mutex is locked.

func (*SafeMutex) AlreadyLocked

func (s *SafeMutex) AlreadyLocked() bool

AlreadyLocked returns true if safe mutex is already being held.

func (*SafeMutex) AssertLock

func (s *SafeMutex) AssertLock()

AssertLock asserts whether the lock is being held.

func (*SafeMutex) AssertRLock

func (s *SafeMutex) AssertRLock()

AssertRLock asserts whether the reader lock is being held.

func (*SafeMutex) Lock

func (s *SafeMutex) Lock()

Lock locks the safe mutex.

func (*SafeMutex) RLock

func (s *SafeMutex) RLock()

RLock holds the reader lock.

func (*SafeMutex) RUnlock

func (s *SafeMutex) RUnlock()

RUnlock releases the reader lock.

func (*SafeMutex) Unlock

func (s *SafeMutex) Unlock()

Unlock unlocks the safe mutex.

type SplitAlgorithm

type SplitAlgorithm interface {
	Split(start, end []byte, numSplits int) ([]Range, error)
	SplitAllRegions(numSplits int) ([]Range, error)
}

type Stopper

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

Stopper is a manager struct for managing worker goroutines.

func NewStopper

func NewStopper() *Stopper

NewStopper return a new Stopper instance.

func (*Stopper) Close

func (s *Stopper) Close()

Close closes the internal shouldStopc chan struct{} to signal all worker goroutines that they should stop.

func (*Stopper) Ctx

func (s *Stopper) Ctx() context.Context

func (*Stopper) RunWorker

func (s *Stopper) RunWorker(f func())

RunWorker creates a new goroutine and invoke the f func in that new worker goroutine.

func (*Stopper) ShouldStop

func (s *Stopper) ShouldStop() <-chan struct{}

ShouldStop returns a chan struct{} used for indicating whether the Stop() function has been called on Stopper.

func (*Stopper) Stop

func (s *Stopper) Stop()

Stop signals all managed worker goroutines to stop and wait for them to actually stop.

func (*Stopper) Wait

func (s *Stopper) Wait()

Wait waits on the internal sync.WaitGroup. It only return when all managed worker goroutines are ready to return and called sync.WaitGroup.Done() on the internal sync.WaitGroup.

type Store

type Store interface {

	// Add adds the given object to the accumulator associated with the given object's key
	Add(obj interface{}) error

	// Update updates the given object in the accumulator associated with the given object's key
	Update(obj interface{}) error

	// Delete deletes the given object from the accumulator associated with the given object's key
	Delete(obj interface{}) error

	// List returns a list of all the currently non-empty accumulators
	List() []interface{}

	// ListKeys returns a list of all the keys currently associated with non-empty accumulators
	ListKeys() []string

	// Get returns the accumulator associated with the given object's key
	Get(obj interface{}) (item interface{}, exists bool, err error)

	// GetByKey returns the accumulator associated with the given key
	GetByKey(key string) (item interface{}, exists bool, err error)

	// Replace will delete the contents of the store, using instead the
	// given list. Store takes ownership of the list, you should not reference
	// it after calling this function.
	Replace([]interface{}, string) error

	// Resync is meaningless in the terms appearing here but has
	// meaning in some implementations that have non-trivial
	// additional behavior (e.g., DeltaFIFO).
	Resync() error
}

Store is a generic object storage and processing interface. A Store holds a map from string keys to accumulators, and has operations to add, update, and delete a given object to/from the accumulator currently associated with a given key. A Store also knows how to extract the key from a given object, so many operations are given only the object.

In the simplest Store implementations each accumulator is simply the last given object, or empty after Delete, and thus the Store's behavior is simple storage.

Reflector knows how to watch a server and update a Store. This package provides a variety of implementations of Store.

func NewStore

func NewStore(keyFunc KeyFunc) Store

NewStore returns a Store implemented simply with a map and a lock.

type ThreadSafeStore

type ThreadSafeStore interface {
	Add(key string, obj interface{})
	Update(key string, obj interface{})
	Delete(key string)
	Get(key string) (item interface{}, exists bool)
	List() []interface{}
	ListKeys() []string
	Replace(map[string]interface{}, string)
	Index(indexName string, obj interface{}) ([]interface{}, error)
	IndexKeys(indexName, indexKey string) ([]string, error)
	ListIndexFuncValues(name string) []string
	ByIndex(indexName, indexKey string) ([]interface{}, error)
	GetIndexers() Indexers

	// AddIndexers adds more indexers to this store.  If you call this after you already have data
	// in the store, the results are undefined.
	AddIndexers(newIndexers Indexers) error
	// Resync is a no-op and is deprecated
	Resync() error
}

ThreadSafeStore is an interface that allows concurrent indexed access to a storage backend. It is like Indexer but does not (necessarily) know how to extract the Store key from a given object.

TL;DR caveats: you must not modify anything returned by Get or List as it will break the indexing feature in addition to not being thread safe.

The guarantees of th`read safety provided by List/Get are only valid if the caller treats returned items as read-only. For example, a pointer inserted in the store through `Add` will be returned as is by `Get`. Multiple clients might invoke `Get` on the same key and modify the pointer in a non-thread-safe way. Also note that modifying objects stored by the indexers (if any) will *not* automatically lead to a re-index. So it's not a good idea to directly modify the objects returned by Get/List, in general.

func NewThreadSafeStore

func NewThreadSafeStore(indexers Indexers, indices Indices) ThreadSafeStore

NewThreadSafeStore creates a new instance of ThreadSafeStore.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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