internel

package
v0.0.0-...-5a55052 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEBUG level = iota
	INFO
	WARNING
	ERROR
	SLICENCE
)
View Source
const CgoEnabled = true

CgoEnabled is used to check if CGO is enabled while building badger.

View Source
const (
	MaxNodeSize = int(unsafe.Sizeof(node{}))
)
View Source
const RW_ = 0666

Variables

View Source
var CastagnoliCrcTable = crc32.MakeTable(crc32.Castagnoli)

Functions

func BloomBitsPerKey

func BloomBitsPerKey(numEntries int, fp float64) int

func BytesToU32

func BytesToU32(b []byte) uint32

BytesToU32 converts the given byte slice to uint32

func BytesToU32Slice

func BytesToU32Slice(b []byte) []uint32

BytesToU32Slice converts the given byte slice to uint32 slice

func BytesToU64

func BytesToU64(b []byte) uint64

BytesToU64 converts the given byte slice to uint64

func BytesToU64Slice

func BytesToU64Slice(b []byte) []uint64

BytesToU64Slice converts the given byte slice to uint64 slice

func DefaultLogger

func DefaultLogger(level level) *defaultLog

func FastRand

func FastRand() uint32

func Hash

func Hash(b []byte) uint32

Hash implements a hashing algorithm similar to the Murmur hash.

func Max

func Max(a, b int) int

func Min

func Min(a, b int) int

func U32SliceToBytes

func U32SliceToBytes(u32s []uint32) []byte

U32SliceToBytes converts the given Uint32 slice to byte slice

func U32ToBytes

func U32ToBytes(v uint32) []byte

U32ToBytes converts the given Uint32 to bytes

func U64SliceToBytes

func U64SliceToBytes(u64s []uint64) []byte

U64SliceToBytes converts the given Uint64 slice to byte slice

func U64ToBytes

func U64ToBytes(v uint64) []byte

U64ToBytes converts the given Uint64 to bytes

func VerifyCheckSum

func VerifyCheckSum(data []byte, checksum []byte) bool

func ZSTDCompress

func ZSTDCompress(dst, src []byte, compressionLevel int) ([]byte, error)

ZSTDCompress compresses a block using ZSTD algorithm.

func ZSTDCompressBound

func ZSTDCompressBound(srcSize int) int

ZSTDCompressBound returns the worst case size needed for a destination buffer.

func ZSTDDecompress

func ZSTDDecompress(dst, src []byte) ([]byte, error)

ZSTDDecompress decompresses a block using ZSTD algorithm.

Types

type Arena

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

func NewArena

func NewArena(n uint32) *Arena

type BloomFilter

type BloomFilter []byte

func NewBloomFilter

func NewBloomFilter(keys []uint32, bitsPerKey int) BloomFilter

NewFilter returns a new Bloom filter that encodes a set of []byte keys with the given number of bits per key, approximately.

A good bitsPerKey value is 10, which yields a filter with ~ 1% false positive rate.

func (BloomFilter) MayContain

func (bf BloomFilter) MayContain(key []byte) bool

MayContain returns whether the filter may contain given key. False positives are possible, where it returns true for keys not in the original set.

func (BloomFilter) MayContainHash

func (bf BloomFilter) MayContainHash(hash uint32) bool

type CloseHandler

type CloseHandler func()

type Closer

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

Closer holds the two things we need to close a goroutine and wait for it to finish: a chan to tell the goroutine to shut down, and a WaitGroup with which to wait for it to finish shutting down.

func NewCloser

func NewCloser(init int) *Closer

NewCloser constructs a new Closer, with an initial count on the WaitGroup.

func (*Closer) AddRunning

func (c *Closer) AddRunning(delta int)

AddRunning Add()'s delta to the WaitGroup.

func (*Closer) Ctx

func (c *Closer) Ctx() context.Context

Ctx can be used to get a context, which would automatically get cancelled when Signal is called.

func (*Closer) Done

func (c *Closer) Done()

Done calls Done() on the WaitGroup.

func (*Closer) HasBeenClosed

func (c *Closer) HasBeenClosed() <-chan struct{}

HasBeenClosed gets signaled when Signal() is called.

func (*Closer) Signal

func (c *Closer) Signal()

Signal signals the HasBeenClosed signal.

func (*Closer) SignalAndWait

func (c *Closer) SignalAndWait()

SignalAndWait calls Signal(), then Wait().

func (*Closer) Wait

func (c *Closer) Wait()

Wait waits on the WaitGroup. (It waits for NewCloser's initial value, AddRunning, and Done calls to balance out.)

type Comparator

type Comparator func([]byte, []byte) int

type DirLockGuard

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

dirLockGuard holds a lock on a directory and a pid file inside.

func AcquireDirLock

func AcquireDirLock(dir string, pidFileName string) (*DirLockGuard, error)

AcquireDirLock gets a lock on the directory (using flock). It will also write our pid to dir/pidFileName for convenience.

func (*DirLockGuard) Release

func (g *DirLockGuard) Release() error

Release deletes the pid file and releases lock on the directory.

type HashReader

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

func NewHashReader

func NewHashReader(r io.Reader) *HashReader

func (*HashReader) BytesRead

func (t *HashReader) BytesRead() int

func (*HashReader) Read

func (t *HashReader) Read(p []byte) (int, error)

Read reads len(p) bytes from the reader. Returns the number of bytes read, error on failure.

func (*HashReader) ReadByte

func (t *HashReader) ReadByte() (byte, error)

ReadByte reads exactly one byte from the reader. Returns error on failure.

func (*HashReader) Sum32

func (t *HashReader) Sum32() uint32

Sum32 returns the sum32 of the underlying hash.

type Iterator

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

func (*Iterator) Close

func (i *Iterator) Close() error

func (*Iterator) Key

func (i *Iterator) Key() []byte

func (*Iterator) Next

func (i *Iterator) Next()

func (*Iterator) Prev

func (i *Iterator) Prev()

func (*Iterator) Seek

func (i *Iterator) Seek(target []byte)

func (*Iterator) SeekToFirst

func (i *Iterator) SeekToFirst()

func (*Iterator) SeekToLast

func (i *Iterator) SeekToLast()

func (*Iterator) Valid

func (i *Iterator) Valid() bool

func (*Iterator) Value

func (i *Iterator) Value() []byte

type Logger

type Logger interface {
	Errorf(string, ...interface{})
	Warningf(string, ...interface{})
	Infof(string, ...interface{})
	Debugf(string, ...interface{})
}

type MmapFile

type MmapFile struct {
	Data    []byte
	Fd      *os.File
	NewFile bool // if a file is created when it open, this is true
}

func OpenMmapFile

func OpenMmapFile(filename string, flag int, max int) (*MmapFile, error)

func OpenMmapFileWithFD

func OpenMmapFileWithFD(fd *os.File, flag int, max int) (*MmapFile, error)

func (*MmapFile) Close

func (m *MmapFile) Close() error

func (*MmapFile) CloseWithTruncate

func (m *MmapFile) CloseWithTruncate(size int64) error

func (*MmapFile) Delete

func (m *MmapFile) Delete() error

func (*MmapFile) NewReader

func (m *MmapFile) NewReader(offset int) io.Reader

func (*MmapFile) Sync

func (m *MmapFile) Sync() error

func (*MmapFile) Truncate

func (m *MmapFile) Truncate(size int64) error

type Skiplist

type Skiplist struct {
	Hanlder CloseHandler
	// contains filtered or unexported fields
}

func NewSkiplist

func NewSkiplist(arenaSize uint32, cmp Comparator) *Skiplist

func (*Skiplist) Deref

func (s *Skiplist) Deref()

func (*Skiplist) Empty

func (s *Skiplist) Empty() bool

func (*Skiplist) Get

func (s *Skiplist) Get(key []byte) ([]byte, []byte)

func (*Skiplist) Iterator

func (s *Skiplist) Iterator() *Iterator

func (*Skiplist) Put

func (s *Skiplist) Put(key, value []byte)

func (*Skiplist) Ref

func (s *Skiplist) Ref()

func (*Skiplist) Size

func (s *Skiplist) Size() uint32

type Throttle

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

Throttle allows a limited number of workers to run at a time. It also provides a mechanism to check for errors encountered by workers and wait for them to finish.

func NewThrottle

func NewThrottle(max int) *Throttle

NewThrottle creates a new throttle with a max number of workers.

func (*Throttle) Do

func (t *Throttle) Do() error

Do should be called by workers before they start working. It blocks if there are already maximum number of workers working. If it detects an error from previously Done workers, it would return it.

func (*Throttle) Done

func (t *Throttle) Done(err error)

Done should be called by workers when they finish working. They can also pass the error status of work done.

func (*Throttle) Finish

func (t *Throttle) Finish() error

Finish waits until all workers have finished working. It would return any error passed by Done. If Finish is called multiple time, it will wait for workers to finish only once(first time). From next calls, it will return same error as found on first call.

Jump to

Keyboard shortcuts

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