Documentation ¶
Index ¶
- Constants
- Variables
- func AssertTrue(b bool)
- func AssertTruef(b bool, format string, args ...interface{})
- func BitsPerKey(numEntries int, fp float64) int
- func BytesToU32(buf []byte) uint32
- func BytesToU32Slice(b []byte) []uint32
- func BytesToU64(b []byte) uint64
- func CalcHashNum(bitsPerKey int) uint32
- func CalculateChecksum(data []byte) uint64
- func CompareKeys(key1, key2 []byte) int
- func Copy(a []byte) []byte
- func DiscardEntry(e, vs *Entry) bool
- func EstimateWalCodecSize(e *Entry) int
- func FID(name string) uint64
- func Hash(b []byte) uint32
- func IsDeletedOrExpired(meta byte, expiresAt uint64) bool
- func IsSameKey(src, dst []byte) bool
- func IsValuePtr(e *Entry) bool
- func KeyWithTs(key []byte, ts uint64) []byte
- func LoadIDMap(dir string) map[uint64]struct{}
- func ParseKey(key []byte) []byte
- func ParseTimeStamp(key []byte) uint64
- func RunCallBack(cb func())
- func SSTFullFileName(dir string, fid uint64) string
- func SafeCopy(a, src []byte) []byte
- func SyncDir(dir string) error
- func U32SliceToBytes(u32s []uint32) []byte
- func U32ToBytes(v uint32) []byte
- func U64ToBytes(v uint64) []byte
- func ValueSize(data []byte) int64
- func VerifyChecksum(data []byte, expected []byte) error
- func VlogFilePath(dirPath string, fid uint32) string
- func WalCodec(buf *bytes.Buffer, e *Entry) int
- type Arena
- type BloomFilter
- type Closer
- type Entry
- func (e *Entry) EncodedSize() uint32
- func (e *Entry) Entry() *Entry
- func (e *Entry) EstimateSize(threshold int) int
- func (e *Entry) IsDeletedOrExpired() bool
- func (e *Entry) IsZero() bool
- func (e *Entry) LogHeaderLen() int
- func (e *Entry) LogOffset() uint32
- func (e Entry) Size() int64
- func (e *Entry) WithTTL(duration time.Duration) *Entry
- type HashReader
- type Header
- type Item
- type Iterator
- type LogEntry
- type Options
- type SkipList
- type SkipListIterator
- func (s *SkipListIterator) Close() error
- func (s *SkipListIterator) Item() Item
- func (s *SkipListIterator) Key() []byte
- func (s *SkipListIterator) Next()
- func (s *SkipListIterator) Prev()
- func (s *SkipListIterator) Rewind()
- func (s *SkipListIterator) Seek(target []byte)
- func (s *SkipListIterator) SeekForPrev(target []byte)
- func (s *SkipListIterator) SeekToFirst()
- func (s *SkipListIterator) SeekToLast()
- func (s *SkipListIterator) Valid() bool
- func (s *SkipListIterator) Value() ValueStruct
- func (s *SkipListIterator) ValueUint64() uint64
- type Throttle
- type UniIterator
- type ValuePtr
- type ValueStruct
- type WalHeader
Constants ¶
const ( // MaxLevelNum _ MaxLevelNum = 7 // DefaultValueThreshold _ DefaultValueThreshold = 1024 ManifestDeletionsRewriteThreshold = 10000 ManifestDeletionsRatio = 10 ManifestFileName = "manifest" ReManifestFileName = "remanifest" // 基于可变长编码,其最可能的编码 MaxHeaderSize = 21 VlogHeaderSize = 0 MaxVlogFileSize uint32 = math.MaxUint32 Mi int64 = 1 << 20 KVWriteChCapacity = 1000 )
const ( BitDelete byte = 1 << 0 // Set if the key has been deleted. BitValuePointer byte = 1 << 1 // Set if the value is NOT stored directly next to key. )
meta
const (
NodeSize = int(unsafe.Sizeof(node{}))
)
const ( // size of vlog header. // +----------------+------------------+ // | keyID(8 bytes) | baseIV(12 bytes)| // +----------------+------------------+ ValueLogHeaderSize = 20 )
Variables ¶
var ( MagicText = [4]byte{'O', 'C', 'T', 'O'} MagicVersion = uint32(1) )
var ( ErrChecksumMismatch = errors.New("checksum mismatch") ErrEmptyKey = errors.New("Key cannot be empty") ErrTruncate = errors.New("Do truncate") ErrKeyNotExist = errors.New("key not exist") ErrKeyNotFound = errors.New("Key not found") ErrStop = errors.New("Stop") ErrDeleteVlogFile = errors.New("Delete vlog file") // compact ErrFillTables = errors.New("Unable to fill tables") ErrTxnTooBig = errors.New("Txn is too big to fit into one request") // ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite. ErrNoRewrite = errors.New("Value log GC attempt didn't result in any cleanup") // ErrInvalidRequest is returned if the user request is invalid. ErrInvalidRequest = errors.New("Invalid request") // ErrRejected is returned if a value log GC is called either while another GC is running, or // after DB::Close has been called. ErrRejected = errors.New("Value log GC request rejected") ErrBlockedWrites = errors.New("Writes are blocked, possibly due to DropAll or Close") )
var ( // CastagnoliCrcTable is a CRC32 polynomial table CastagnoliCrcTable = crc32.MakeTable(crc32.Castagnoli) )
Functions ¶
func AssertTrue ¶
func AssertTrue(b bool)
AssertTrue asserts that b is true. Otherwise, it would log fatal.
func AssertTruef ¶
AssertTruef is AssertTrue with extra info.
func BitsPerKey ¶
BitsPerKey 根据计算公式,在给定假阳性false positive和确定数据量下
func BytesToU32 ¶
func BytesToU32Slice ¶
BytesToU32Slice converts the given byte slice to uint32 slice
func BytesToU64 ¶
func CompareKeys ¶
func DiscardEntry ¶
func EstimateWalCodecSize ¶
EstimateWalCodecSize 预估当前kv 写入wal文件占用的空间大小
func IsDeletedOrExpired ¶
func IsValuePtr ¶
func ParseTimeStamp ¶
func RunCallBack ¶
func RunCallBack(cb func())
func SSTFullFileName ¶
func SyncDir ¶
SyncDir When you create or delete a file, you have to ensure the directory entry for the file is synced in order to guarantee the file is visible (if the system crashes). (See the man page for fsync, or see https://github.com/coreos/etcd/issues/6368 for an example.)
func U32SliceToBytes ¶
func VlogFilePath ¶
Types ¶
type Arena ¶
type Arena struct {
// contains filtered or unexported fields
}
Arena 内存管理模块,分配一整块内存buf,对应memetable,当此buf分配完时对应memtable-->immemtable的转换
type BloomFilter ¶
type BloomFilter struct {
Filter []byte
}
func NewBloomFilter ¶
func NewBloomFilter(keys []uint32, bitPerKey int) BloomFilter
func (BloomFilter) MayContain ¶
func (b BloomFilter) MayContain(key []byte) bool
type Closer ¶
type Closer struct { CloseSignal chan struct{} // contains filtered or unexported fields }
type Entry ¶
type Entry struct { Key []byte Value []byte ExpiresAt uint64 Meta byte Version uint64 Offset uint32 // offset in file Hlen int // Length of the header. ValThreshold int64 }
func BuildEntry ¶
func BuildEntry() *Entry
func (*Entry) EncodedSize ¶
func (*Entry) EstimateSize ¶
func (*Entry) IsDeletedOrExpired ¶
type HashReader ¶
func NewHashReader ¶
func NewHashReader(r io.Reader) *HashReader
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 Header ¶
func (*Header) Decode ¶
Decode decodes the given header from the provided byte slice. Returns the number of bytes read.
func (*Header) DecodeFrom ¶
func (h *Header) DecodeFrom(reader *HashReader) (int, error)
DecodeFrom reads the header from the hashReader. Returns the number of bytes read.
type SkipList ¶
type SkipList struct { OnClose func() // contains filtered or unexported fields }
func NewSkipList ¶
NewSkipList makes a new empty skiplist, with a given arena size
func (*SkipList) DecrRef ¶
func (s *SkipList) DecrRef()
DecrRef decrements the refcount, deallocating the Skiplist when done using it
func (*SkipList) MemSize ¶
MemSize returns the size of the Skiplist in terms of how much memory is used within its internal arena.
func (*SkipList) NewSkipListIterator ¶
NewIterator returns a skiplist iterator. You have to Close() the iterator.
func (*SkipList) Search ¶
func (s *SkipList) Search(key []byte) ValueStruct
Get gets the value associated with the key. It returns a valid value if it finds equal or earlier version of the same key.
type SkipListIterator ¶
type SkipListIterator struct {
// contains filtered or unexported fields
}
Iterator is an iterator over skiplist object. For new objects, you just need to initialize Iterator.list.
func (*SkipListIterator) Close ¶
func (s *SkipListIterator) Close() error
Close frees the resources held by the iterator
func (*SkipListIterator) Item ¶
func (s *SkipListIterator) Item() Item
func (*SkipListIterator) Key ¶
func (s *SkipListIterator) Key() []byte
Key returns the key at the current position.
func (*SkipListIterator) Next ¶
func (s *SkipListIterator) Next()
Next advances to the next position.
func (*SkipListIterator) Prev ¶
func (s *SkipListIterator) Prev()
Prev advances to the previous position.
func (*SkipListIterator) Rewind ¶
func (s *SkipListIterator) Rewind()
func (*SkipListIterator) Seek ¶
func (s *SkipListIterator) Seek(target []byte)
Seek advances to the first entry with a key >= target.
func (*SkipListIterator) SeekForPrev ¶
func (s *SkipListIterator) SeekForPrev(target []byte)
SeekForPrev finds an entry with key <= target.
func (*SkipListIterator) SeekToFirst ¶
func (s *SkipListIterator) SeekToFirst()
SeekToFirst seeks position at the first entry in list. Final state of iterator is Valid() iff list is not empty.
func (*SkipListIterator) SeekToLast ¶
func (s *SkipListIterator) SeekToLast()
SeekToLast seeks position at the last entry in list. Final state of iterator is Valid() iff list is not empty.
func (*SkipListIterator) Valid ¶
func (s *SkipListIterator) Valid() bool
Valid returns true iff the iterator is positioned at a valid node.
func (*SkipListIterator) Value ¶
func (s *SkipListIterator) Value() ValueStruct
Value returns value.
func (*SkipListIterator) ValueUint64 ¶
func (s *SkipListIterator) ValueUint64() uint64
ValueUint64 returns the uint64 value of the current node.
type Throttle ¶
type Throttle struct {
// contains filtered or unexported fields
}
Throttle allows a limited number of workers to run at a time.
func NewThrottle ¶
NewThrottle creates a new throttle with a max number of workers.
func (*Throttle) Do ¶
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 ¶
Done should be called by workers when they finish working. They can also pass the error status of work done.
type UniIterator ¶
type UniIterator struct {
// contains filtered or unexported fields
}
UniIterator is a unidirectional memtable iterator. It is a thin wrapper around Iterator. We like to keep Iterator as before, because it is more powerful and we might support bidirectional iterators in the future.
type ValuePtr ¶
func NewValuePtr ¶
type ValueStruct ¶
ValueStruct 将value与expiresAt作为一个整体
func (*ValueStruct) DecodeValue ¶
func (vs *ValueStruct) DecodeValue(buf []byte)
DecodeValue 反序列化到结构体
func (*ValueStruct) EncodeValue ¶
func (vs *ValueStruct) EncodeValue(b []byte) uint32
EncodeValue 对value进行编码,并将编码后的字节写入byte
func (*ValueStruct) EncodedSize ¶
func (vs *ValueStruct) EncodedSize() uint32
EncodedSize value只持久化具体的value值和过期时间