util

package
v2.4.0-rc.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

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
	PerBlockCrcSize  = 4
	ExtentSize       = BlockCount * BlockSize
	PacketHeaderSize = 57
	BlockHeaderSize  = 4096
)
View Source
const (
	ConnectIdleTime = 30
)
View Source
const (
	DefaultSmuxPortShift = 500
)
View Source
const (
	DefaultTinySizeLimit = 1 * MB // TODO explain tiny extent?
)

Variables

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

Functions

func DailTimeOut added in v1.4.0

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

func DefaultSmuxConfig

func DefaultSmuxConfig() *smux.Config

func FilterSmuxAcceptError

func FilterSmuxAcceptError(err error) error

filter smux accept error

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 Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func RandomString added in v1.5.0

func RandomString(length int, seed RandomSeed) string

func ShiftAddrPort

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

addr = ip:port afterShift = ip:(port+shift)

func SubString added in v1.5.0

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

func VerifySmuxPoolConfig

func VerifySmuxPoolConfig(cfg *SmuxConnPoolConfig) error

Types

type ConnectPool

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

func NewConnectPool

func NewConnectPool() (cp *ConnectPool)

func NewConnectPoolWithTimeout

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

func (*ConnectPool) Close

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)

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 MultipartID

type MultipartID string

func CreateMultipartID

func CreateMultipartID(mpId uint64) MultipartID

func MultipartIDFromString

func MultipartIDFromString(src string) MultipartID

func (MultipartID) PartitionID

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

func (MultipartID) String

func (id MultipartID) String() string

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

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 SmuxConnPoolConfig

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

func DefaultSmuxConnPoolConfig

func DefaultSmuxConnPoolConfig() *SmuxConnPoolConfig

type SmuxConnPoolStat

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

type SmuxConnectPool

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

func NewSmuxConnectPool

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

func (*SmuxConnectPool) Close

func (cp *SmuxConnectPool) Close()

func (*SmuxConnectPool) GetConnect

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

func (*SmuxConnectPool) GetStat

func (cp *SmuxConnectPool) GetStat() *SmuxConnPoolStat

func (*SmuxConnectPool) PutConnect

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

type SmuxPool

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

func NewSmuxPool

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

func (*SmuxPool) GetConnect

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

func (*SmuxPool) GetStat

func (p *SmuxPool) GetStat() *SmuxPoolStat

func (*SmuxPool) MarkClosed

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

func (*SmuxPool) NewStream

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

func (*SmuxPool) PutStreamObjectToPool

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

func (*SmuxPool) ReleaseAll

func (p *SmuxPool) ReleaseAll()

type SmuxPoolStat

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.

Jump to

Keyboard shortcuts

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