badger: Index | Files

package y

import ""


Package Files

bloom.go checksum.go encrypt.go error.go event_log.go file_dsync.go iterator.go metrics.go watermark.go y.go zstd_cgo.go


const CgoEnabled = true

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


var (
    // LSMSize has size of the LSM in bytes
    LSMSize *expvar.Map
    // VlogSize has size of the value log in bytes
    VlogSize *expvar.Map
    // PendingWrites tracks the number of pending writes.
    PendingWrites *expvar.Map

    // NumReads has cumulative number of reads
    NumReads *expvar.Int
    // NumWrites has cumulative number of writes
    NumWrites *expvar.Int
    // NumBytesRead has cumulative number of bytes read
    NumBytesRead *expvar.Int
    // NumBytesWritten has cumulative number of bytes written
    NumBytesWritten *expvar.Int
    // NumLSMGets is number of LMS gets
    NumLSMGets *expvar.Map
    // NumLSMBloomHits is number of LMS bloom hits
    NumLSMBloomHits *expvar.Map
    // NumGets is number of gets
    NumGets *expvar.Int
    // NumPuts is number of puts
    NumPuts *expvar.Int
    // NumBlockedPuts is number of blocked puts
    NumBlockedPuts *expvar.Int
    // NumMemtableGets is number of memtable gets
    NumMemtableGets *expvar.Int
    // NumCompactionTables is the number of tables being compacted
    NumCompactionTables *expvar.Int
var (
    // ErrEOF indicates an end of file when trying to read from a memory mapped file
    // and encountering the end of slice.
    ErrEOF = errors.New("ErrEOF: End of file")

    // ErrZstdCgo indicates that badger was built without cgo but ZSTD
    // compression algorithm is being used for compression. ZSTD cannot work
    // without CGO.
    ErrZstdCgo = errors.New("ErrZstdCgo: zstd compression requires building badger with cgo enabled")

    // ErrCommitAfterFinish indicates that write batch commit was called after
    // finish
    ErrCommitAfterFinish = errors.New("Batch commit not permitted after finish")
var (

    // CastagnoliCrcTable is a CRC32 polynomial table
    CastagnoliCrcTable = crc32.MakeTable(crc32.Castagnoli)
var ErrChecksumMismatch = errors.New("checksum mismatch")

ErrChecksumMismatch is returned at checksum mismatch.

var (
    NoEventLog trace.EventLog = nilEventLog{}

func AssertTrue Uses

func AssertTrue(b bool)

AssertTrue asserts that b is true. Otherwise, it would log fatal.

func AssertTruef Uses

func AssertTruef(b bool, format string, args ...interface{})

AssertTruef is AssertTrue with extra info.

func BloomBitsPerKey Uses

func BloomBitsPerKey(numEntries int, fp float64) int

BloomBitsPerKey returns the bits per key required by bloomfilter based on the false positive rate.

func BytesToU32 Uses

func BytesToU32(b []byte) uint32

BytesToU32 converts the given byte slice to uint32

func BytesToU32Slice Uses

func BytesToU32Slice(b []byte) []uint32

BytesToU32Slice converts the given byte slice to uint32 slice

func BytesToU64 Uses

func BytesToU64(b []byte) uint64

BytesToU64 converts the given byte slice to uint64

func BytesToU64Slice Uses

func BytesToU64Slice(b []byte) []uint64

BytesToU64Slice converts the given byte slice to uint64 slice

func CalculateChecksum Uses

func CalculateChecksum(data []byte, ct pb.Checksum_Algorithm) uint64

CalculateChecksum calculates checksum for data using ct checksum type.

func Check Uses

func Check(err error)

Check logs fatal if err != nil.

func Check2 Uses

func Check2(_ interface{}, err error)

Check2 acts as convenience wrapper around Check, using the 2nd argument as error.

func CompareKeys Uses

func CompareKeys(key1, key2 []byte) int

CompareKeys checks the key without timestamp and checks the timestamp if keyNoTs is same. a<timestamp> would be sorted higher than aa<timestamp> if we use All keys should have timestamp.

func Copy Uses

func Copy(a []byte) []byte

Copy copies a byte slice and returns the copied slice.

func CreateSyncedFile Uses

func CreateSyncedFile(filename string, sync bool) (*os.File, error)

CreateSyncedFile creates a new file (using O_EXCL), errors if it already existed.

func FixedDuration Uses

func FixedDuration(d time.Duration) string

FixedDuration returns a string representation of the given duration with the hours, minutes, and seconds.

func GenerateIV Uses

func GenerateIV() ([]byte, error)

GenerateIV generates IV.

func Hash Uses

func Hash(b []byte) uint32

hash implements a hashing algorithm similar to the Murmur hash.

func KeyWithTs Uses

func KeyWithTs(key []byte, ts uint64) []byte

KeyWithTs generates a new key by appending ts to key.

func NewKV Uses

func NewKV(alloc *z.Allocator) *pb.KV

func OpenExistingFile Uses

func OpenExistingFile(filename string, flags Flags) (*os.File, error)

OpenExistingFile opens an existing file, errors if it doesn't exist.

func OpenSyncedFile Uses

func OpenSyncedFile(filename string, sync bool) (*os.File, error)

OpenSyncedFile creates the file if one doesn't exist.

func OpenTruncFile Uses

func OpenTruncFile(filename string, sync bool) (*os.File, error)

OpenTruncFile opens the file with O_RDWR | O_CREATE | O_TRUNC

func ParseKey Uses

func ParseKey(key []byte) []byte

ParseKey parses the actual key from the key bytes.

func ParseTs Uses

func ParseTs(key []byte) uint64

ParseTs parses the timestamp from the key bytes.

func SafeCopy Uses

func SafeCopy(a, src []byte) []byte

SafeCopy does append(a[:0], src...).

func SameKey Uses

func SameKey(src, dst []byte) bool

SameKey checks for key equality ignoring the version timestamp suffix.

func U32SliceToBytes Uses

func U32SliceToBytes(u32s []uint32) []byte

U32SliceToBytes converts the given Uint32 slice to byte slice

func U32ToBytes Uses

func U32ToBytes(v uint32) []byte

U32ToBytes converts the given Uint32 to bytes

func U64SliceToBytes Uses

func U64SliceToBytes(u64s []uint64) []byte

U64SliceToBytes converts the given Uint64 slice to byte slice

func U64ToBytes Uses

func U64ToBytes(v uint64) []byte

U64ToBytes converts the given Uint64 to bytes

func VerifyChecksum Uses

func VerifyChecksum(data []byte, expected *pb.Checksum) error

VerifyChecksum validates the checksum for the data against the given expected checksum.

func Wrap Uses

func Wrap(err error, msg string) error

Wrap wraps errors from external lib.

func Wrapf Uses

func Wrapf(err error, format string, args ...interface{}) error

Wrapf is Wrap with extra info.

func XORBlock Uses

func XORBlock(dst, src, key, iv []byte) error

XORBlock encrypts the given data with AES and XOR's with IV. Can be used for both encryption and decryption. IV is of AES block size.

func XORBlockAllocate Uses

func XORBlockAllocate(src, key, iv []byte) ([]byte, error)

func XORBlockStream Uses

func XORBlockStream(w io.Writer, src, key, iv []byte) error

func ZSTDCompress Uses

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

ZSTDCompress compresses a block using ZSTD algorithm.

func ZSTDCompressBound Uses

func ZSTDCompressBound(srcSize int) int

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

func ZSTDDecompress Uses

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

ZSTDDecompress decompresses a block using ZSTD algorithm.

type Filter Uses

type Filter []byte

Filter is an encoded set of []byte keys.

func NewFilter Uses

func NewFilter(keys []uint32, bitsPerKey int) Filter

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 (Filter) MayContain Uses

func (f Filter) MayContain(h uint32) 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 (Filter) MayContainKey Uses

func (f Filter) MayContainKey(k []byte) bool

type Flags Uses

type Flags int
const (
    // Sync indicates that O_DSYNC should be set on the underlying file,
    // ensuring that data writes do not return until the data is flushed
    // to disk.
    Sync Flags = 1 << iota
    // ReadOnly opens the underlying file on a read-only basis.

type Iterator Uses

type Iterator interface {
    Seek(key []byte)
    Key() []byte
    Value() ValueStruct
    Valid() bool

    // All iterators should be closed so that file garbage collection works.
    Close() error

Iterator is an interface for a basic iterator.

type PageBuffer Uses

type PageBuffer struct {
    // contains filtered or unexported fields

PageBuffer consists of many pages. A page is a wrapper over []byte. PageBuffer can act as a replacement of bytes.Buffer. Instead of having single underlying buffer, it has multiple underlying buffers. Hence it avoids any copy during relocation(as happens in bytes.Buffer). PageBuffer allocates memory in pages. Once a page is full, it will allocate page with double the size of previous page. Its function are not thread safe.

func NewPageBuffer Uses

func NewPageBuffer(pageSize int) *PageBuffer

NewPageBuffer returns a new PageBuffer with first page having size pageSize.

func (*PageBuffer) Bytes Uses

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

Bytes returns whole Buffer data as single []byte.

func (*PageBuffer) Len Uses

func (b *PageBuffer) Len() int

Len returns length of PageBuffer.

func (*PageBuffer) NewReaderAt Uses

func (b *PageBuffer) NewReaderAt(offset int) *PageBufferReader

NewReaderAt returns a reader which starts reading from offset in page buffer.

func (*PageBuffer) Truncate Uses

func (b *PageBuffer) Truncate(n int)

Truncate truncates PageBuffer to length n.

func (*PageBuffer) Write Uses

func (b *PageBuffer) Write(data []byte) (int, error)

Write writes data to PageBuffer b. It returns number of bytes written and any error encountered.

func (*PageBuffer) WriteByte Uses

func (b *PageBuffer) WriteByte(data byte) error

WriteByte writes data byte to PageBuffer and returns any encountered error.

func (*PageBuffer) WriteTo Uses

func (b *PageBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo writes whole buffer to w. It returns number of bytes written and any error encountered.

type PageBufferReader Uses

type PageBufferReader struct {
    // contains filtered or unexported fields

PageBufferReader is a reader for PageBuffer.

func (*PageBufferReader) Read Uses

func (r *PageBufferReader) Read(p []byte) (int, error)

Read reads upto len(p) bytes. It returns number of bytes read and any error encountered.

type Slice Uses

type Slice struct {
    // contains filtered or unexported fields

Slice holds a reusable buf, will reallocate if you request a larger size than ever before. One problem is with n distinct sizes in random order it'll reallocate log(n) times.

func (*Slice) Resize Uses

func (s *Slice) Resize(sz int) []byte

Resize reuses the Slice's buffer (or makes a new one) and returns a slice in that buffer of length sz.

type Throttle Uses

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 Uses

func NewThrottle(max int) *Throttle

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

func (*Throttle) Do Uses

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 Uses

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 Uses

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.

type ValueStruct Uses

type ValueStruct struct {
    Meta      byte
    UserMeta  byte
    ExpiresAt uint64
    Value     []byte

    Version uint64 // This field is not serialized. Only for internal usage.

ValueStruct represents the value info that can be associated with a key, but also the internal Meta field.

func (*ValueStruct) Decode Uses

func (v *ValueStruct) Decode(b []byte)

Decode uses the length of the slice to infer the length of the Value field.

func (*ValueStruct) Encode Uses

func (v *ValueStruct) Encode(b []byte) uint32

Encode expects a slice of length at least v.EncodedSize().

func (*ValueStruct) EncodeTo Uses

func (v *ValueStruct) EncodeTo(buf *bytes.Buffer)

EncodeTo should be kept in sync with the Encode function above. The reason this function exists is to avoid creating byte arrays per key-value pair in table/builder.go.

func (*ValueStruct) EncodedSize Uses

func (v *ValueStruct) EncodedSize() uint32

EncodedSize is the size of the ValueStruct when encoded

type WaterMark Uses

type WaterMark struct {
    Name string
    // contains filtered or unexported fields

WaterMark is used to keep track of the minimum un-finished index. Typically, an index k becomes finished or "done" according to a WaterMark once Done(k) has been called

1. as many times as Begin(k) has, AND
2. a positive number of times.

An index may also become "done" by calling SetDoneUntil at a time such that it is not inter-mingled with Begin/Done calls.

Since doneUntil and lastIndex addresses are passed to sync/atomic packages, we ensure that they are 64-bit aligned by putting them at the beginning of the structure.

func (*WaterMark) Begin Uses

func (w *WaterMark) Begin(index uint64)

Begin sets the last index to the given value.

func (*WaterMark) BeginMany Uses

func (w *WaterMark) BeginMany(indices []uint64)

BeginMany works like Begin but accepts multiple indices.

func (*WaterMark) Done Uses

func (w *WaterMark) Done(index uint64)

Done sets a single index as done.

func (*WaterMark) DoneMany Uses

func (w *WaterMark) DoneMany(indices []uint64)

DoneMany works like Done but accepts multiple indices.

func (*WaterMark) DoneUntil Uses

func (w *WaterMark) DoneUntil() uint64

DoneUntil returns the maximum index that has the property that all indices less than or equal to it are done.

func (*WaterMark) Init Uses

func (w *WaterMark) Init(closer *z.Closer)

Init initializes a WaterMark struct. MUST be called before using it.

func (*WaterMark) LastIndex Uses

func (w *WaterMark) LastIndex() uint64

LastIndex returns the last index for which Begin has been called.

func (*WaterMark) SetDoneUntil Uses

func (w *WaterMark) SetDoneUntil(val uint64)

SetDoneUntil sets the maximum index that has the property that all indices less than or equal to it are done.

func (*WaterMark) WaitForMark Uses

func (w *WaterMark) WaitForMark(ctx context.Context, index uint64) error

WaitForMark waits until the given index is marked as done.

Package y imports 26 packages (graph) and is imported by 150 packages. Updated 2021-01-27. Refresh now. Tools for package owners.