util

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 29 Imported by: 15

Documentation

Index

Constants

View Source
const (
	MEMINFO = "/proc/meminfo"
	PRO_MEM = "/proc/%d/status"
)
View Source
const (
	KB = 1 << (10 * iota)
	MB
	GB
	TB
	PB
	DefaultDataPartitionSize = 120 * GB
	TaskWorkerInterval       = 1
)
View Source
const (
	BlockCount          = 1024
	BlockSize           = 65536 * 2
	ReadBlockSize       = BlockSize
	RepairReadBlockSize = 512 * util.KB
	PerBlockCrcSize     = 4
	ExtentSize          = BlockCount * BlockSize
	PacketHeaderSize    = 57
	BlockHeaderSize     = 4096
	SyscallTryMaxTimes  = 3
	PacketHeaderVerSize = 65
)
View Source
const (
	PageSize          = 4 * util.KB
	FallocFLKeepSize  = 1
	FallocFLPunchHole = 2
)
View Source
const (
	AclListIP  = 0
	AclAddIP   = 1
	AclDelIP   = 2
	AclCheckIP = 3
)
View Source
const (
	UidLimitList = 0
	UidAddLimit  = 1
	UidDelLimit  = 2
	UidGetLimit  = 3
)
View Source
const (
	ConnectIdleTime = 30
)
View Source
const (
	DefaultSmuxPortShift = 500
)
View Source
const (
	DefaultTinySizeLimit = 1 * MB // TODO explain tiny extent?
)
View Source
const MaxNameLen = 4096

MaxSendfdLen is the maximum length of the name of a file descriptor being sent using SendFd. The name of the file handle returned by RecvFd will never be larger than this value.

Variables

View Source
var ErrNoValidMaster = errors.New("no valid master")
View Source
var ErrTooMuchSmuxStreams = errors.New("too much smux streams")

Functions

func Any2String added in v1.34.0

func Any2String(value interface{}) string

Any2String format any value to string.

func CalcAuthKey added in v1.34.0

func CalcAuthKey(key string) (authKey string)

func DailTimeOut added in v1.4.0

func DailTimeOut(target string, timeout time.Duration) (c *net.TCPConn, err error)

func DefaultSmuxConfig added in v1.34.0

func DefaultSmuxConfig() *smux.Config

func FilterSmuxAcceptError added in v1.34.0

func FilterSmuxAcceptError(err error) error

FilterSmuxAcceptError filter smux accept error

func GenerateKey added in v1.34.0

func GenerateKey(volName string, ino uint64, offset uint64) string

func GenerateRepVolKey added in v1.34.0

func GenerateRepVolKey(volName string, ino uint64, dpId uint64, extentId uint64, offset uint64) string

func GetIp added in v1.34.0

func GetIp(addr string) (ip string)

func GetMemInfo

func GetMemInfo() (total, used uint64, err error)

GetMemInfo returns the memory information.

func GetProcessMemory added in v1.1.0

func GetProcessMemory(pid int) (used uint64, err error)

func IsIPV4

func IsIPV4(val interface{}) bool

IsIPV4 returns if it is IPV4 address.

func IsIPV4Addr added in v1.34.0

func IsIPV4Addr(ipAddr string) bool

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func OneDaySec added in v1.34.0

func OneDaySec() int64

func ParseAddrToIpAddr added in v1.34.0

func ParseAddrToIpAddr(addr string) (ipAddr string, success bool)

func ParseDomainAddrToIpAddr added in v1.34.0

func ParseDomainAddrToIpAddr(domainAddr string) (ipAddr string, success bool)

func ParseIpAddrToDomainAddr added in v1.34.0

func ParseIpAddrToDomainAddr(ipAddr string) (domainAddr string)

func RandomString added in v1.5.0

func RandomString(length int, seed RandomSeed) string

func RecvFd added in v1.34.0

func RecvFd(socket *os.File) (*os.File, error)

RecvFd waits for a file descriptor to be sent over the given AF_UNIX socket. The file name of the remote file descriptor will be recreated locally (it is sent as non-auxiliary data in the same payload).

func SendFd added in v1.34.0

func SendFd(socket *os.File, name string, fd uintptr) error

SendFd sends a file descriptor over the given AF_UNIX socket. In addition, the file.Name() of the given file will also be sent as non-auxiliary data in the same payload (allowing to send contextual information for a file descriptor).

func SendFds added in v1.34.0

func SendFds(socket *os.File, msg []byte, fds ...int) error

SendFds sends a list of files descriptor and msg over the given AF_UNIX socket.

func ShiftAddrPort added in v1.34.0

func ShiftAddrPort(addr string, shift int) (afterShift string)

ShiftAddrPort changes the addr(ip:port) to afterShift(ip:(port+shift)).

func String2Any added in v1.34.0

func String2Any(str string, pvalue interface{}) error

Any2String parse string to pointer of value.

func SubString added in v1.5.0

func SubString(sourceString string, begin, end int) string

func VerifySmuxPoolConfig added in v1.34.0

func VerifySmuxPoolConfig(cfg *SmuxConnPoolConfig) error

Types

type BloomFilter added in v1.34.0

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

func NewBloomFilter added in v1.34.0

func NewBloomFilter(size uint64, hashFunc ...func(data []byte) uint64) *BloomFilter

func (*BloomFilter) Add added in v1.34.0

func (bf *BloomFilter) Add(data []byte)

func (*BloomFilter) Contains added in v1.34.0

func (bf *BloomFilter) Contains(data []byte) bool

type ConnectPool

type ConnectPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewConnectPool

func NewConnectPool() (cp *ConnectPool)

func NewConnectPoolWithTimeout added in v1.34.0

func NewConnectPoolWithTimeout(idleConnTimeout time.Duration, connectTimeout int64) (cp *ConnectPool)

func (*ConnectPool) Close added in v1.34.0

func (cp *ConnectPool) Close()

func (*ConnectPool) GetConnect

func (cp *ConnectPool) GetConnect(targetAddr string) (c *net.TCPConn, err error)

func (*ConnectPool) PutConnect

func (cp *ConnectPool) PutConnect(c *net.TCPConn, forceClose bool)

func (*ConnectPool) PutConnectEx added in v1.34.0

func (cp *ConnectPool) PutConnectEx(c *net.TCPConn, err error)

func (*ConnectPool) ReleaseAll added in v1.34.0

func (cp *ConnectPool) ReleaseAll(addr net.Addr)

type Future added in v1.34.0

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

Future the future

func NewFuture added in v1.34.0

func NewFuture() *Future

func (*Future) AsyncResponse added in v1.34.0

func (f *Future) AsyncResponse() (respCh <-chan interface{}, errCh <-chan error)

AsyncResponse export channels

func (*Future) Respond added in v1.34.0

func (f *Future) Respond(resp interface{}, err error)

func (*Future) Response added in v1.34.0

func (f *Future) Response() (resp interface{}, err error)

Response wait response

type MasterHelper

type MasterHelper interface {
	AddNode(address string)
	Nodes() []string
	Leader() string
	Request(method, path string, param, header map[string]string, body []byte) (data []byte, err error)
}

MasterHelper defines the helper struct to manage the master.

func NewMasterHelper

func NewMasterHelper() MasterHelper

NewMasterHelper returns a new MasterHelper instance.

type MultiVersionSeq added in v1.34.0

type MultiVersionSeq uint64

type MultipartID added in v1.34.0

type MultipartID string

func CreateMultipartID added in v1.34.0

func CreateMultipartID(mpId uint64) MultipartID

func MultipartIDFromString added in v1.34.0

func MultipartIDFromString(src string) MultipartID

func (MultipartID) PartitionID added in v1.34.0

func (id MultipartID) PartitionID() (pID uint64, found bool)

func (MultipartID) String added in v1.34.0

func (id MultipartID) String() string

type Null added in v1.34.0

type Null struct{}

type Object

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

type Pool

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

func NewPool

func NewPool(min, max int, timeout, connectTimeout int64, target string) (p *Pool)

func (*Pool) GetConnectFromPool

func (p *Pool) GetConnectFromPool() (c *net.TCPConn, err error)

func (*Pool) NewConnect

func (p *Pool) NewConnect(target string) (c *net.TCPConn, err error)

func (*Pool) PutConnectObjectToPool

func (p *Pool) PutConnectObjectToPool(o *Object)

func (*Pool) ReleaseAll added in v1.34.0

func (p *Pool) ReleaseAll()

type RandomSeed added in v1.5.0

type RandomSeed byte
const (
	Numeric RandomSeed = 1 << iota
	LowerLetter
	UpperLetter
)

func (RandomSeed) Runes added in v1.5.0

func (s RandomSeed) Runes() []rune

type RecycleTimer added in v1.34.0

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

func NewRecycleTimer added in v1.34.0

func NewRecycleTimer(interval time.Duration, recyclePercent float64, minRecycleLimit uint64) (r *RecycleTimer, err error)

func (*RecycleTimer) SetPanicHook added in v1.34.0

func (r *RecycleTimer) SetPanicHook(handle func(r interface{}))

func (*RecycleTimer) SetStatHook added in v1.34.0

func (r *RecycleTimer) SetStatHook(handle func(totalPercent float64, currentProcess uint64, currentGoHeap uint64))

func (*RecycleTimer) Stop added in v1.34.0

func (r *RecycleTimer) Stop()

type Set added in v1.34.0

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSet added in v1.34.0

func NewSet() *Set

func (*Set) Add added in v1.34.0

func (s *Set) Add(val string)

func (*Set) Clear added in v1.34.0

func (s *Set) Clear()

func (*Set) Has added in v1.34.0

func (s *Set) Has(key string) bool

func (*Set) Len added in v1.34.0

func (s *Set) Len() int

func (*Set) Range added in v1.34.0

func (s *Set) Range(fun func(key interface{}) bool)

func (*Set) Remove added in v1.34.0

func (s *Set) Remove(val string)

type SmuxConnPoolConfig added in v1.34.0

type SmuxConnPoolConfig struct {
	*smux.Config
	TotalStreams      int
	StreamsPerConn    int
	ConnsPerAddr      int
	PoolCapacity      int
	DialTimeout       time.Duration
	StreamIdleTimeout int64
}

func DefaultSmuxConnPoolConfig added in v1.34.0

func DefaultSmuxConnPoolConfig() *SmuxConnPoolConfig

type SmuxConnPoolStat added in v1.34.0

type SmuxConnPoolStat struct {
	TotalStreams         int                      `json:"totalStreams"`
	TotalStreamsReported int                      `json:"totalStreamsInflight"`
	Pools                map[string]*SmuxPoolStat `json:"pools"`
	TotalSessions        int                      `json:"totalSessions"`
	Bucket               int                      `json:"bucket"`
}

type SmuxConnectPool added in v1.34.0

type SmuxConnectPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSmuxConnectPool added in v1.34.0

func NewSmuxConnectPool(cfg *SmuxConnPoolConfig) (cp *SmuxConnectPool)

func (*SmuxConnectPool) Close added in v1.34.0

func (cp *SmuxConnectPool) Close()

func (*SmuxConnectPool) GetConnect added in v1.34.0

func (cp *SmuxConnectPool) GetConnect(targetAddr string) (c *smux.Stream, err error)

func (*SmuxConnectPool) GetStat added in v1.34.0

func (cp *SmuxConnectPool) GetStat() *SmuxConnPoolStat

func (*SmuxConnectPool) PutConnect added in v1.34.0

func (cp *SmuxConnectPool) PutConnect(stream *smux.Stream, forceClose bool)

type SmuxPool added in v1.34.0

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

func NewSmuxPool added in v1.34.0

func NewSmuxPool(cfg *SmuxConnPoolConfig, target string, streamBucket *simpleTokenBucket) (p *SmuxPool)

func (*SmuxPool) GetConnect added in v1.34.0

func (p *SmuxPool) GetConnect() (*smux.Stream, error)

func (*SmuxPool) GetStat added in v1.34.0

func (p *SmuxPool) GetStat() *SmuxPoolStat

func (*SmuxPool) MarkClosed added in v1.34.0

func (p *SmuxPool) MarkClosed(s *smux.Stream)

func (*SmuxPool) NewStream added in v1.34.0

func (p *SmuxPool) NewStream() (stream *smux.Stream, err error)

func (*SmuxPool) PutStreamObjectToPool added in v1.34.0

func (p *SmuxPool) PutStreamObjectToPool(obj *streamObject)

func (*SmuxPool) ReleaseAll added in v1.34.0

func (p *SmuxPool) ReleaseAll()

type SmuxPoolStat added in v1.34.0

type SmuxPoolStat struct {
	Addr                    string         `json:"addr"`
	InflightStreams         int            `json:"inflightStreams"`
	InflightStreamsReported int            `json:"inflightStreamReported"`
	TotalSessions           int            `json:"totalSessions"`
	StreamsPerSession       map[string]int `json:"streamsPerSession"`
}

Directories

Path Synopsis
Package btree implements in-memory B-Trees of arbitrary degree.
Package btree implements in-memory B-Trees of arbitrary degree.
Package ratelimit RateLimit Algorithm Based on Token Bucket
Package ratelimit RateLimit Algorithm Based on Token Bucket
mocktest
raftstore
Package raftstoremock is a generated GoMock package.
Package raftstoremock is a generated GoMock package.

Jump to

Keyboard shortcuts

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