package y

Import Path
	github.com/dgraph-io/badger/v4/y (on go.dev)

Dependency Relation
	imports 27 packages, and imported by 4 packages


Package-Level Type Names (total 10)
/* sort by: | */
Filter is an encoded set of []byte keys. MayContain returns whether the filter may contain given key. False positives are possible, where it returns true for keys not in the original set. ( Filter) MayContainKey(k []byte) bool func NewFilter(keys []uint32, bitsPerKey int) Filter
func OpenExistingFile(filename string, flags Flags) (*os.File, error) const ReadOnly const Sync
Iterator is an interface for a basic iterator. All iterators should be closed so that file garbage collection works. ( Iterator) Key() []byte ( Iterator) Next() ( Iterator) Rewind() ( Iterator) Seek(key []byte) ( Iterator) Valid() bool ( Iterator) Value() ValueStruct *github.com/dgraph-io/badger/v4/skl.UniIterator *github.com/dgraph-io/badger/v4/table.ConcatIterator *github.com/dgraph-io/badger/v4/table.Iterator *github.com/dgraph-io/badger/v4/table.MergeIterator Iterator : github.com/prometheus/common/expfmt.Closer Iterator : io.Closer func github.com/dgraph-io/badger/v4/table.NewMergeIterator(iters []Iterator, reverse bool) Iterator func github.com/dgraph-io/badger/v4/table.NewMergeIterator(iters []Iterator, reverse bool) Iterator
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. Bytes returns whole Buffer data as single []byte. Len returns length of PageBuffer. NewReaderAt returns a reader which starts reading from offset in page buffer. Truncate truncates PageBuffer to length n. Write writes data to PageBuffer b. It returns number of bytes written and any error encountered. WriteByte writes data byte to PageBuffer and returns any encountered error. WriteTo writes whole buffer to w. It returns number of bytes written and any error encountered. *PageBuffer : github.com/apache/arrow-go/v18/internal/hashing.ByteSlice *PageBuffer : github.com/miekg/dns.Writer *PageBuffer : github.com/quic-go/quic-go/quicvarint.Writer *PageBuffer : internal/bisect.Writer *PageBuffer : io.ByteWriter *PageBuffer : io.Writer *PageBuffer : io.WriterTo func NewPageBuffer(pageSize int) *PageBuffer
PageBufferReader is a reader for PageBuffer. Read reads upto len(p) bytes. It returns number of bytes read and any error encountered. *PageBufferReader : io.Reader func (*PageBuffer).NewReaderAt(offset int) *PageBufferReader
Capture captures the current number of sent bytes. This number should be monotonically increasing. Rate returns the average rate of transmission smoothed out by the number of samples. func NewRateMonitor(numSamples int) *RateMonitor
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. Resize reuses the Slice's buffer (or makes a new one) and returns a slice in that buffer of length sz.
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. 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. Done should be called by workers when they finish working. They can also pass the error status of work done. 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. func NewThrottle(max int) *Throttle
ValueStruct represents the value info that can be associated with a key, but also the internal Meta field. ExpiresAt uint64 Meta byte UserMeta byte Value []byte // This field is not serialized. Only for internal usage. Decode uses the length of the slice to infer the length of the Value field. Encode expects a slice of length at least v.EncodedSize(). 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. EncodedSize is the size of the ValueStruct when encoded func Iterator.Value() ValueStruct func github.com/dgraph-io/badger/v4/skl.(*Iterator).Value() ValueStruct func github.com/dgraph-io/badger/v4/skl.(*Skiplist).Get(key []byte) ValueStruct func github.com/dgraph-io/badger/v4/skl.(*UniIterator).Value() ValueStruct func github.com/dgraph-io/badger/v4/table.(*ConcatIterator).Value() ValueStruct func github.com/dgraph-io/badger/v4/table.(*Iterator).Value() (ret ValueStruct) func github.com/dgraph-io/badger/v4/table.(*Iterator).ValueCopy() (ret ValueStruct) func github.com/dgraph-io/badger/v4/table.(*MergeIterator).Value() ValueStruct func github.com/dgraph-io/badger/v4/skl.(*Skiplist).Put(key []byte, v ValueStruct) func github.com/dgraph-io/badger/v4/table.(*Builder).Add(key []byte, value ValueStruct, valueLen uint32) func github.com/dgraph-io/badger/v4/table.(*Builder).AddStaleKey(key []byte, v ValueStruct, valueLen uint32)
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. Name string Begin sets the last index to the given value. BeginMany works like Begin but accepts multiple indices. Done sets a single index as done. DoneMany works like Done but accepts multiple indices. DoneUntil returns the maximum index that has the property that all indices less than or equal to it are done. Init initializes a WaterMark struct. MUST be called before using it. LastIndex returns the last index for which Begin has been called. SetDoneUntil sets the maximum index that has the property that all indices less than or equal to it are done. WaitForMark waits until the given index is marked as done.
Package-Level Functions (total 67)
AssertTrue asserts that b is true. Otherwise, it would log fatal.
AssertTruef is AssertTrue with extra info.
BloomBitsPerKey returns the bits per key required by bloomfilter based on the false positive rate.
BytesToU16 converts the given byte slice to uint16
BytesToU32 converts the given byte slice to uint32
BytesToU32Slice converts the given byte slice to uint32 slice
BytesToU64 converts the given byte slice to uint64
BytesToU64Slice converts the given byte slice to uint64 slice
CalculateChecksum calculates checksum for data using ct checksum type.
Check logs fatal if err != nil.
Check2 acts as convenience wrapper around Check, using the 2nd argument as error.
func CombineErrors(one, other error) error
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 bytes.compare All keys should have timestamp.
Copy copies a byte slice and returns the copied slice.
CreateSyncedFile creates a new file (using O_EXCL), errors if it already existed.
FixedDuration returns a string representation of the given duration with the hours, minutes, and seconds.
GenerateIV generates IV.
hash implements a hashing algorithm similar to the Murmur hash.
IBytesToString converts size in bytes to human readable format. The code is taken from humanize library and changed to provide value upto custom decimal precision. IBytesToString(12312412, 1) -> 11.7 MiB
KeyWithTs generates a new key by appending ts to key.
func LSMSizeGet(enabled bool, key string) expvar.Var
func LSMSizeSet(enabled bool, key string, val expvar.Var)
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 NewKV(alloc *z.Allocator) *pb.KV
NewPageBuffer returns a new PageBuffer with first page having size pageSize.
func NewRateMonitor(numSamples int) *RateMonitor
NewThrottle creates a new throttle with a max number of workers.
func NumBytesReadsLSMAdd(enabled bool, val int64)
func NumBytesReadsVlogAdd(enabled bool, val int64)
func NumBytesWrittenToL0Add(enabled bool, val int64)
func NumBytesWrittenUserAdd(enabled bool, val int64)
func NumBytesWrittenVlogAdd(enabled bool, val int64)
func NumCompactionTablesAdd(enabled bool, val int64)
func NumGetsAdd(enabled bool, val int64)
func NumGetsWithResultsAdd(enabled bool, val int64)
func NumIteratorsCreatedAdd(enabled bool, val int64)
func NumLSMBloomHitsAdd(enabled bool, key string, val int64)
func NumLSMGetsAdd(enabled bool, key string, val int64)
func NumMemtableGetsAdd(enabled bool, val int64)
func NumPutsAdd(enabled bool, val int64)
func NumReadsVlogAdd(enabled bool, val int64)
func NumWritesVlogAdd(enabled bool, val int64)
OpenExistingFile opens an existing file, errors if it doesn't exist.
OpenSyncedFile creates the file if one doesn't exist.
OpenTruncFile opens the file with O_RDWR | O_CREATE | O_TRUNC
ParseKey parses the actual key from the key bytes.
ParseTs parses the timestamp from the key bytes.
func PendingWritesSet(enabled bool, key string, val expvar.Var)
SafeCopy does append(a[:0], src...).
SameKey checks for key equality ignoring the version timestamp suffix.
U16ToBytes converts the given Uint16 to bytes
U32SliceToBytes converts the given Uint32 slice to byte slice
U32ToBytes converts the given Uint32 to bytes
U64SliceToBytes converts the given Uint64 slice to byte slice
U64ToBytes converts the given Uint64 to bytes
VerifyChecksum validates the checksum for the data against the given expected checksum.
func VlogSizeGet(enabled bool, key string) expvar.Var
func VlogSizeSet(enabled bool, key string, val expvar.Var)
Wrap wraps errors from external lib.
Wrapf is Wrap with extra info.
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(src, key, iv []byte) ([]byte, error)
func XORBlockStream(w io.Writer, src, key, iv []byte) error
ZSTDCompress compresses a block using ZSTD algorithm.
ZSTDCompressBound returns the worst case size needed for a destination buffer. Klauspost ZSTD library does not provide any API for Compression Bound. This calculation is based on the DataDog ZSTD library. See https://pkg.go.dev/github.com/DataDog/zstd#CompressBound
ZSTDDecompress decompresses a block using ZSTD algorithm.
Package-Level Variables (total 5)
CastagnoliCrcTable is a CRC32 polynomial table
ErrChecksumMismatch is returned at checksum mismatch.
ErrCommitAfterFinish indicates that write batch commit was called after finish
ErrEOF indicates an end of file when trying to read from a memory mapped file and encountering the end of slice.
Package-Level Constants (total 3)
const BADGER_METRIC_PREFIX = "badger_"
ReadOnly opens the underlying file on a read-only basis.
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.