util

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Store_Prefix_Invalid uint8 = 0
	Store_Prefix_KV      uint8 = 1
	Store_Prefix_Range   uint8 = 2
	Store_Prefix_RaftLog uint8 = 3
)
View Source
const (
	KB = 1 << (10 * iota)
	MB
	GB
)
View Source
const MinRead = 512
View Source
const TTL_COL_NAME string = "ttl"

Variables

View Source
var (
	// ErrDisposed is returned when an operation is performed on a disposed
	// queue.
	ErrDisposed = errors.New(`queue: disposed`)

	// ErrTimeout is returned when an applicable queue operation times out.
	ErrTimeout = errors.New(`queue: poll timed out`)

	// ErrEmptyQueue is returned when an non-applicable queue operation was called
	// due to the queue's empty item state
	ErrEmptyQueue = errors.New(`queue: empty queue`)
)
View Source
var (
	ErrReleased    = errors.New("fbase/util.Releaser: resource already relesed")
	ErrHasReleaser = errors.New("fbase/util.Releaser: already defined")
)

Functions

func Decode

func Decode(buf []byte, v proto.Message) error

func DecodeColumnValue

func DecodeColumnValue(buf []byte, col *metapb.Column) ([]byte, interface{}, error)

DecodeColumnValue 解码列

func DecodePrimaryKey added in v0.6.3

func DecodePrimaryKey(buf []byte, col *metapb.Column) ([]byte, []byte, error)

EncodePrimaryKey 编码主键列 不编码列ID 保持排序属性

func DecodePrimaryKey2 added in v0.6.3

func DecodePrimaryKey2(buf []byte, col *metapb.Column) ([]byte, interface{}, error)

EncodePrimaryKey 编码主键列 不编码列ID 保持排序属性

func DecodeStorePrefix

func DecodeStorePrefix(buff []byte) (prefix uint8, table_id uint64, err error)

func DecodeValue2 added in v0.6.3

func DecodeValue2(buf []byte) ([]byte, uint32, []byte, encoding.Type, error)

func Encode

func Encode(v proto.Message) ([]byte, error)

func EncodeColumnValue

func EncodeColumnValue(buf []byte, col *metapb.Column, sval []byte) ([]byte, error)

EncodeColumnValue 编码列 先列ID再列值 Note: 编码后不保持排序属性(即如果a > b, 那么编码后的字节数组 bytes.Compare(encA, encB) >0 不一定成立)

func EncodePrimaryKey

func EncodePrimaryKey(buf []byte, col *metapb.Column, sval []byte) ([]byte, error)

EncodePrimaryKey 编码主键列 不编码列ID 保持排序属性

func EncodeStorePrefix

func EncodeStorePrefix(prefix uint8, table_id uint64) []byte

func EncodeValue2 added in v0.6.3

func EncodeValue2(buf []byte, colId uint32, typ encoding.Type, sval []byte) ([]byte, error)

func ExecuteInParallel

func ExecuteInParallel(q *Queue, fn func(interface{}))

ExecuteInParallel will (in parallel) call the provided function with each item in the queue until the queue is exhausted. When the queue is exhausted execution is complete and all goroutines will be killed. This means that the queue will be disposed so cannot be used again.

func GetIpFromContext

func GetIpFromContext(ctx context.Context) string

func GetLocalIps

func GetLocalIps() []string

func Hash

func Hash(data []byte, seed uint32) uint32

Hash return hash of the given data.

func MaxInt

func MaxInt(a, b int) int

ManInt max

func MinInt

func MinInt(a, b int) int

MinInt min

func RandomBytes

func RandomBytes(r *rand.Rand, dst []byte)

RandomBytes random bytes

func ShorteNBytes

func ShorteNBytes(bytes int) string

ShorteNBytes

func SliceToString

func SliceToString(b []byte) (s string)

SliceToString slice to string with out data copy

func StringToSlice

func StringToSlice(s string) (b []byte)

StringToSlice string to slice with out data copy

Types

type BasicReleaser

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

func (*BasicReleaser) Release

func (r *BasicReleaser) Release()

func (*BasicReleaser) Released

func (r *BasicReleaser) Released() bool

func (*BasicReleaser) SetReleaser

func (r *BasicReleaser) SetReleaser(releaser Releaser)

type Buffer

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

func NewBuffer

func NewBuffer(buf []byte) *Buffer

func (*Buffer) Alloc

func (b *Buffer) Alloc(n int) []byte

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Grow

func (b *Buffer) Grow(n int)

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) Next

func (b *Buffer) Next(n int) []byte

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (c byte, err error)

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(delim byte) (line []byte, err error)

func (*Buffer) ReadFrom

func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Truncate

func (b *Buffer) Truncate(n int)

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

type BufferPool

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

BufferPool is a 'buffer pool'.

func NewBufferPool

func NewBufferPool(baseline int) *BufferPool

NewBufferPool creates a new initialized 'buffer pool'.

func (*BufferPool) Close

func (p *BufferPool) Close()

func (*BufferPool) Get

func (p *BufferPool) Get(n int) []byte

Get returns buffer with length of n.

func (*BufferPool) Put

func (p *BufferPool) Put(b []byte)

Put adds given buffer to the pool.

func (*BufferPool) String

func (p *BufferPool) String() string

type ByteSize

type ByteSize uint64

ByteSize is a retype uint64 for TOML and JSON.

func (ByteSize) MarshalJSON

func (b ByteSize) MarshalJSON() ([]byte, error)

MarshalJSON returns the size as a JSON string.

func (*ByteSize) UnmarshalJSON

func (b *ByteSize) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the bytesize.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText parses a Toml string into the bytesize.

type CRC

type CRC uint32

CRC is a CRC-32 checksum computed using Castagnoli's polynomial.

func NewCRC

func NewCRC(b []byte) CRC

NewCRC creates a new crc based on the given bytes.

func (CRC) Update

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

Update updates the crc with the given bytes.

func (CRC) Value

func (c CRC) Value() uint32

Value returns a masked crc.

type Clocker

type Clocker interface {
	Now() uint64
}

func NewIncrementSeqClock

func NewIncrementSeqClock() Clocker

type Duration

type Duration struct {
	time.Duration
}

Duration is a wrapper of time.Duration for TOML and JSON.

func NewDuration

func NewDuration(duration time.Duration) Duration

NewDuration creates a Duration from time.Duration.

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON returns the duration as a JSON string.

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the duration.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText parses a TOML string into the duration.

type Int64Slice

type Int64Slice []int64

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Sort

func (p Int64Slice) Sort()

Sort is a convenience method.

func (Int64Slice) Swap

func (p Int64Slice) Swap(i, j int)

type KeyPair

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

type KeyPairSlice

type KeyPairSlice []KeyPair

func (KeyPairSlice) Get

func (slice KeyPairSlice) Get(i int) KeyPair

func (KeyPairSlice) Len

func (slice KeyPairSlice) Len() int

func (KeyPairSlice) Less

func (slice KeyPairSlice) Less(i, j int) bool

func (KeyPairSlice) Sort

func (slice KeyPairSlice) Sort()

Sort is a convenience method.

func (KeyPairSlice) Swap

func (slice KeyPairSlice) Swap(i, j int)

type NoopReleaser

type NoopReleaser struct{}

func (NoopReleaser) Release

func (NoopReleaser) Release()

type OffsetQueue

type OffsetQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

OffsetQueue is a queue for sync.

func NewOffsetQueue

func NewOffsetQueue() *OffsetQueue

NewOffsetQueue returns a offset queue

func (*OffsetQueue) Add

func (q *OffsetQueue) Add(item interface{}) uint64

Add add a item to the queue

func (*OffsetQueue) Get

func (q *OffsetQueue) Get(offset uint64) ([]interface{}, uint64)

Get returns all the items after the offset, and remove all items before this offset

func (*OffsetQueue) GetMaxOffset

func (q *OffsetQueue) GetMaxOffset() uint64

GetMaxOffset returns the max offset in the queue

type Queue

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

Queue is the struct responsible for tracking the state of the queue.

func New

func New(hint int64) *Queue

New is a constructor for a new threadsafe queue.

func (*Queue) Dispose

func (q *Queue) Dispose() []interface{}

Dispose will dispose of this queue and returns the items disposed. Any subsequent calls to Get or Put will return an error.

func (*Queue) Disposed

func (q *Queue) Disposed() bool

Disposed returns a bool indicating if this queue has had disposed called on it.

func (*Queue) Empty

func (q *Queue) Empty() bool

Empty returns a bool indicating if this bool is empty.

func (*Queue) Get

func (q *Queue) Get(number int64, items []interface{}) (int64, error)

Get retrieves items from the queue. If there are some items in the queue, get will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue.

func (*Queue) Len

func (q *Queue) Len() int64

Len returns the number of items in this queue.

func (*Queue) Peek

func (q *Queue) Peek() (interface{}, error)

Peek returns a the first item in the queue by value without modifying the queue.

func (*Queue) Poll

func (q *Queue) Poll(number int64, items []interface{}, timeout time.Duration) (int64, error)

Poll retrieves items from the queue. If there are some items in the queue, Poll will return a number UP TO the number passed in as a parameter. If no items are in the queue, this method will pause until items are added to the queue or the provided timeout is reached. A non-positive timeout will block until items are added. If a timeout occurs, ErrTimeout is returned.

func (*Queue) Put

func (q *Queue) Put(items ...interface{}) error

Put will add the specified items to the queue.

func (*Queue) PutOrUpdate

func (q *Queue) PutOrUpdate(cmp func(interface{}, interface{}) bool, item interface{}) error

PutOrUpdate will add the specified item to the queue, update it if exists

type Range

type Range struct {
	Start []byte
	Limit []byte
}

func BytesPrefix

func BytesPrefix(prefix []byte) *Range

type ReleaseSetter

type ReleaseSetter interface {
	SetReleaser(releaser Releaser)
}

type Releaser

type Releaser interface {
	Release()
}

type StringSlice

type StringSlice []string

StringSlice is more friendly to json encode/decode

func (StringSlice) MarshalJSON

func (s StringSlice) MarshalJSON() ([]byte, error)

MarshalJSON returns the size as a JSON string.

func (*StringSlice) UnmarshalJSON

func (s *StringSlice) UnmarshalJSON(text []byte) error

UnmarshalJSON parses a JSON string into the bytesize.

Directories

Path Synopsis
Package apd implements arbitrary-precision decimals.
Package apd implements arbitrary-precision decimals.
Package assert contains functions for making assertions in unit tests From github.com/docker/docker/pkg/testutil/assert
Package assert contains functions for making assertions in unit tests From github.com/docker/docker/pkg/testutil/assert
deepcopy deep copies maps, slices, etc.
deepcopy deep copies maps, slices, etc.
Package hlc implements the Hybrid Logical Clock outlined in "Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases", available online at http://www.cse.buffalo.edu/tech-reports/2014-04.pdf.
Package hlc implements the Hybrid Logical Clock outlined in "Logical Physical Clocks and Consistent Snapshots in Globally Distributed Databases", available online at http://www.cse.buffalo.edu/tech-reports/2014-04.pdf.
structure
maps/treemap
Implements a map backed by llrb tree.
Implements a map backed by llrb tree.
trees/llrbtree
Implements Left-Leaning Red Black trees.
Implements Left-Leaning Red Black trees.

Jump to

Keyboard shortcuts

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