common

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_UINT8  = ^uint8(0)
	MAX_UINT16 = ^uint16(0)
	MAX_UINT32 = ^uint32(0)
	MAX_UINT64 = ^uint64(0)
)
View Source
const (
	TmpSuffix  = ".tmp"
	LockSuffix = ".lock"
)
View Source
const (
	K uint64 = 1024
	M uint64 = 1024 * 1024
	G        = K * M
)
View Source
const (
	UNLIMIT uint64 = ^uint64(0)
)

Variables

View Source
var (
	ErrIntervalNotContinous = errors.New("interval not continuous")
	ErrIntervalInvalid      = errors.New("invalid interval")
)
View Source
var (
	ErrRangeNotContinous = errors.New("tae: range not continuous")
	ErrRangeInvalid      = errors.New("tae: invalid range")
)
View Source
var AnyField = zap.Any
View Source
var (
	ErrClose = errors.New("closed")
)
View Source
var (
	GlobalSeqNum uint64 = 0
)
View Source
var (
	PageSizes = []uint64{
		64,
		128,
		256,
		512,
		1 * K,
		4 * K,
		8 * K,
		16 * K,
		32 * K,
		64 * K,
		128 * K,
		256 * K,
		512 * K,
		M,
		2 * M,
		4 * M,
	}
)

Here we defined different page sizes, and each size has a certain pool managing all pages in that size.

View Source
var StringerField = zap.Stringer

Functions

func BM32Window

func BM32Window(bm *roaring.Bitmap, start, end int) *roaring.Bitmap

func BM64Window

func BM64Window(bm *roaring64.Bitmap, start, end int) *roaring64.Bitmap

func ContextField

func ContextField(format string, a ...any) zap.Field

func CountField

func CountField(val int) zap.Field

func DoRetry

func DoRetry(op RetryOp, ctx context.Context) (err error)

func DurationField

func DurationField(val time.Duration) zap.Field

func EntityField

func EntityField(val any) zap.Field

func ErrorField

func ErrorField(val error) zap.Field

func ExceptionField

func ExceptionField(val any) zap.Field

func FormatFiled

func FormatFiled(key string, format string, a ...any) zap.Field

func GetGlobalSeqNum

func GetGlobalSeqNum() uint64

func IDArraryString

func IDArraryString(ids []ID) string

func IDField

func IDField(val int) zap.Field
func LoopDLink(head *DLNode, fn func(node *DLNode) bool, reverse bool)

func MakeFilename

func MakeFilename(dirname string, ft FileT, name string, isTmp bool) string

func MakeLockFileName

func MakeLockFileName(dirname, name string) string

func MockRWFile

func MockRWFile() *rwFile

func NameSpaceField

func NameSpaceField(val string) zap.Field

func NextGlobalSeqNum

func NextGlobalSeqNum() uint64

func OperandField

func OperandField(val any) zap.Field

func OperandNameSpace

func OperandNameSpace() zap.Field

func OperationField

func OperationField(val string) zap.Field

func ReadString

func ReadString(r io.Reader) (str string, n int64, err error)

func ReasonField

func ReasonField(val string) zap.Field

func RepeatStr

func RepeatStr(str string, times int) string

func ReprerField

func ReprerField(key string, val Reprer) zap.Field

func TimestampField

func TimestampField(val any) zap.Field

func ToH

func ToH(size uint64) string

func WriteString

func WriteString(str string, w io.Writer) (n int64, err error)

Types

type Closable

type Closable interface {
	IsClosed() bool
	TryClose() bool
}

type ClosedInterval

type ClosedInterval struct {
	Start, End uint64
}

func (*ClosedInterval) Append

func (i *ClosedInterval) Append(id uint64) error

func (*ClosedInterval) AtomicUpdateEnd

func (i *ClosedInterval) AtomicUpdateEnd(v uint64)

func (*ClosedInterval) Contains

func (i *ClosedInterval) Contains(o ClosedInterval) bool

func (*ClosedInterval) GT

func (*ClosedInterval) IsCoveredByInt

func (i *ClosedInterval) IsCoveredByInt(idx uint64) bool

func (*ClosedInterval) LT

func (*ClosedInterval) String

func (i *ClosedInterval) String() string

func (*ClosedInterval) TryMerge

func (i *ClosedInterval) TryMerge(o ClosedInterval) bool

type ClosedIntervals

type ClosedIntervals struct {
	Intervals []*ClosedInterval
}

func NewClosedIntervals

func NewClosedIntervals() *ClosedIntervals

func NewClosedIntervalsByInt

func NewClosedIntervalsByInt(i uint64) *ClosedIntervals

func NewClosedIntervalsByInterval

func NewClosedIntervalsByInterval(i *ClosedInterval) *ClosedIntervals

func NewClosedIntervalsByIntervals

func NewClosedIntervalsByIntervals(i *ClosedIntervals) *ClosedIntervals

func NewClosedIntervalsBySlice

func NewClosedIntervalsBySlice(array []uint64) *ClosedIntervals

func (*ClosedIntervals) Contains

func (intervals *ClosedIntervals) Contains(o ClosedIntervals) bool

func (*ClosedIntervals) ContainsInterval

func (intervals *ClosedIntervals) ContainsInterval(oIntervals ClosedInterval) bool

func (*ClosedIntervals) Equal

func (intervals *ClosedIntervals) Equal(o *ClosedIntervals) bool

Equal is for test

func (*ClosedIntervals) GetCardinality

func (intervals *ClosedIntervals) GetCardinality() int

func (*ClosedIntervals) IsCoveredByInt

func (intervals *ClosedIntervals) IsCoveredByInt(i uint64) bool

func (*ClosedIntervals) ReadFrom

func (intervals *ClosedIntervals) ReadFrom(r io.Reader) (n int64, err error)

func (*ClosedIntervals) TryMerge

func (intervals *ClosedIntervals) TryMerge(o ClosedIntervals)

func (*ClosedIntervals) WriteTo

func (intervals *ClosedIntervals) WriteTo(w io.Writer) (n int64, err error)

type ClosedState

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

func (*ClosedState) IsClosed

func (c *ClosedState) IsClosed() bool

func (*ClosedState) TryClose

func (c *ClosedState) TryClose() bool

type DLNode

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

func FindHead

func FindHead(n *DLNode) *DLNode

func InsertDLNode

func InsertDLNode(payload NodePayload, head *DLNode) (node, nhead, ntail *DLNode)

func (*DLNode) Compare

func (l *DLNode) Compare(o *DLNode) int

func (*DLNode) GetNext

func (l *DLNode) GetNext() *DLNode

func (*DLNode) GetPayload

func (l *DLNode) GetPayload() NodePayload

func (*DLNode) GetPrev

func (l *DLNode) GetPrev() *DLNode

func (*DLNode) Sort

func (l *DLNode) Sort() (*DLNode, *DLNode)

type FileInfo

type FileInfo interface {
	Name() string
	Size() int64
	OriginSize() int64
	CompressAlgo() int
}

FileInfo contains the basic info for a file.

type FileT

type FileT int
const (
	FTLock FileT = iota
)

type FileType

type FileType uint8
const (
	InvalidFile FileType = iota
	MemFile
	DiskFile
)

type ID

type ID struct {
	// Internal table id
	TableID uint64
	// Internal segment id
	SegmentID uint64
	// Internal block id
	BlockID uint64
	// Internal column part id
	PartID uint32
	// Column index for the column part above
	Idx uint16
	// Iter is used for MVCC
	Iter uint8
}

ID is the general identifier type shared by different types like table, segment, block, etc.

We could wrap info from upper level via ID, for instance, get the table id, segment id, and the block id for one block by ID.AsBlockID, which made the resource management easier.

func (*ID) AsBlockID

func (id *ID) AsBlockID() ID

func (*ID) AsSegmentID

func (id *ID) AsSegmentID() ID

func (*ID) BlockString

func (id *ID) BlockString() string

func (*ID) IsSameBlock

func (id *ID) IsSameBlock(o ID) bool

func (*ID) IsSameSegment

func (id *ID) IsSameSegment(o ID) bool

func (*ID) NextBlock

func (id *ID) NextBlock() ID

func (*ID) NextSegment

func (id *ID) NextSegment() ID

func (*ID) SegmentString

func (id *ID) SegmentString() string

func (*ID) String

func (id *ID) String() string

func (*ID) TableString

func (id *ID) TableString() string

type IRWFile

type IRWFile interface {
	io.Writer
	IVFile
}

type IRef

type IRef interface {
	RefCount() int64
	Ref()
	Unref()
}

IRef is the general representation of the resources that should be managed with a reference count. Once the reference count reached 0, the OnZeroCB would be called.

type ISLLNode

type ISLLNode interface {
	IRef
}

type ISSLLNode

type ISSLLNode interface {
	Insert(ISSLLNode)
	GetNext() ISSLLNode
	SetNext(ISSLLNode)
	ReleaseNextNode() ISSLLNode
	ReleaseFollowing() ISSLLNode
}

type IVFile

type IVFile interface {
	io.Reader
	Ref()
	Unref()
	RefCount() int64
	Stat() FileInfo
	GetFileType() FileType
}

IVFile is the general in-memory representation of resources like segment, block, index, column part, etc. that managed by buffer manager.

func MockCompressedFile

func MockCompressedFile(size int64, osize int64) IVFile

func NewMemFile

func NewMemFile(size int64) IVFile

type IdAllocator

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

func (*IdAllocator) Alloc

func (id *IdAllocator) Alloc() uint64

func (*IdAllocator) Get

func (id *IdAllocator) Get() uint64

func (*IdAllocator) Set

func (id *IdAllocator) Set(val uint64)

type IdAlloctor

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

func NewIdAlloctor

func NewIdAlloctor(from uint64) *IdAlloctor

func (*IdAlloctor) Alloc

func (alloc *IdAlloctor) Alloc() uint64

func (*IdAlloctor) Get

func (alloc *IdAlloctor) Get() uint64

func (*IdAlloctor) SetStart

func (alloc *IdAlloctor) SetStart(start uint64)
type Link struct {
	// contains filtered or unexported fields
}

func (*Link) Delete

func (l *Link) Delete(n *DLNode)

func (*Link) Depth

func (l *Link) Depth() int

func (*Link) GetHead

func (l *Link) GetHead() *DLNode

func (*Link) GetTail

func (l *Link) GetTail() *DLNode

func (*Link) Insert

func (l *Link) Insert(payload NodePayload) *DLNode

func (*Link) Loop

func (l *Link) Loop(fn func(n *DLNode) bool, reverse bool)

func (*Link) Update

func (l *Link) Update(n *DLNode)

type LinkIt

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

func NewLinkIt

func NewLinkIt(linkLocker *sync.RWMutex, link *Link, reverse bool) *LinkIt

func (*LinkIt) Get

func (it *LinkIt) Get() *DLNode

func (*LinkIt) Next

func (it *LinkIt) Next()

func (*LinkIt) Valid

func (it *LinkIt) Valid() bool

type MemNode

type MemNode struct {
	Buf []byte
	// contains filtered or unexported fields
}

func (*MemNode) GetBuf

func (n *MemNode) GetBuf() []byte

func (*MemNode) IsQuota

func (n *MemNode) IsQuota() bool

func (*MemNode) PageIdx

func (n *MemNode) PageIdx() int

func (*MemNode) Pos

func (n *MemNode) Pos() int

func (*MemNode) Size

func (n *MemNode) Size() int

type Mempool

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

Mempool wraps an easy-to-use memory pool for the AOE storage.

It manages memory through different granularity.

var (
	// GPool is the global mem pool used by AOE storage.
	// It's initialized automatically during init phase.
	GPool *Mempool
)

func NewMempool

func NewMempool(capacity uint64) *Mempool

func (*Mempool) Alloc

func (mp *Mempool) Alloc(size uint64) *MemNode

func (*Mempool) ApplyQuota

func (mp *Mempool) ApplyQuota(size uint64) *MemNode

func (*Mempool) Capacity

func (mp *Mempool) Capacity() uint64

func (*Mempool) Free

func (mp *Mempool) Free(n *MemNode)

func (*Mempool) String

func (mp *Mempool) String() string

func (*Mempool) Usage

func (mp *Mempool) Usage() uint64

type NodePayload

type NodePayload interface {
	Compare(NodePayload) int
}

type OnZeroCB

type OnZeroCB func()

type PPLevel

type PPLevel int8
const (
	PPL0 PPLevel = iota
	PPL1
	PPL2
	PPL3
)

type Range

type Range struct {
	Left  uint64 `json:"l"`
	Right uint64 `json:"r"`
}

func (*Range) Append

func (r *Range) Append(right uint64) error

func (*Range) CanCover

func (r *Range) CanCover(o *Range) bool

func (*Range) ClosedIn

func (r *Range) ClosedIn(id uint64) bool

func (*Range) CommitLeft

func (r *Range) CommitLeft(left uint64) bool

func (*Range) GT

func (r *Range) GT(id uint64) bool

func (*Range) LT

func (r *Range) LT(id uint64) bool

func (*Range) String

func (r *Range) String() string

func (*Range) Union

func (r *Range) Union(o *Range) error

func (*Range) Valid

func (r *Range) Valid() bool

type RefHelper

type RefHelper struct {
	Refs     int64
	OnZeroCB OnZeroCB
}

func (*RefHelper) Ref

func (helper *RefHelper) Ref()

func (*RefHelper) RefCount

func (helper *RefHelper) RefCount() int64

func (*RefHelper) Unref

func (helper *RefHelper) Unref()

type Reprer

type Reprer interface {
	Repr() string
}

type RetryOp

type RetryOp = func() error

type RowGen

type RowGen interface {
	HasNext() bool
	Next() uint32
}

type SLLNode

type SLLNode struct {
	RefHelper
	*sync.RWMutex
	Next ISLLNode
}

SLLNode represent a single node in linked list. It is thread-safe.

func NewSLLNode

func NewSLLNode(mu *sync.RWMutex) *SLLNode

func (*SLLNode) GetNextNode

func (l *SLLNode) GetNextNode() ISLLNode

func (*SLLNode) Insert

func (l *SLLNode) Insert(n ISLLNode)

func (*SLLNode) ReleaseNextNode

func (l *SLLNode) ReleaseNextNode()

func (*SLLNode) SetNextNode

func (l *SLLNode) SetNextNode(next ISLLNode)

func (*SLLNode) SetNextNodeNoLock

func (l *SLLNode) SetNextNodeNoLock(next ISLLNode)

type SSLLNode

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

func NewSSLLNode

func NewSSLLNode() *SSLLNode

func (*SSLLNode) GetNext

func (n *SSLLNode) GetNext() ISSLLNode

func (*SSLLNode) Insert

func (n *SSLLNode) Insert(nn ISSLLNode)

func (*SSLLNode) ReleaseFollowing

func (n *SSLLNode) ReleaseFollowing() ISSLLNode

func (*SSLLNode) ReleaseNextNode

func (n *SSLLNode) ReleaseNextNode() ISSLLNode

func (*SSLLNode) SetNext

func (n *SSLLNode) SetNext(next ISSLLNode)

Jump to

Keyboard shortcuts

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