utils

package
v0.0.0-...-6aa601a Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Overview

Package utils contains helper functions and structs used by dragonboat's examples.

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 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 []*pb.Block) 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 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 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 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 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 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) 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.

Jump to

Keyboard shortcuts

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