Documentation
¶
Index ¶
- Variables
- func CompareKV(a []byte, b []byte) int
- func CompareNitro(this unsafe.Pointer, that unsafe.Pointer) int
- func CompareSnapshot(this, that unsafe.Pointer) int
- func Debug(flag bool)
- func ItemSize(p unsafe.Pointer) int
- func KVFromBytes(bs []byte) (k, v []byte)
- func KVToBytes(k, v []byte) []byte
- func MemoryInUse() (sz int64)
- func SnapshotSize(p unsafe.Pointer) int
- type Config
- type FileReader
- type FileType
- type FileWriter
- type Item
- type ItemCallback
- type ItemEntry
- type Iterator
- func (it *Iterator) Close()
- func (it *Iterator) Get() []byte
- func (it *Iterator) GetNode() *skiplist.Node
- func (it *Iterator) Next()
- func (it *Iterator) Refresh()
- func (it *Iterator) Seek(bs []byte)
- func (it *Iterator) SeekFirst()
- func (it *Iterator) SetRefreshRate(rate int)
- func (it *Iterator) Valid() bool
- type KeyCompare
- type Nitro
- func (m *Nitro) Close()
- func (m *Nitro) DecodeItem(buf []byte, r io.Reader) (*Item, error)
- func (m *Nitro) DumpStats() string
- func (m *Nitro) EncodeItem(itm *Item, buf []byte, w io.Writer) error
- func (m *Nitro) GC()
- func (m *Nitro) GetSnapshots() []*Snapshot
- func (m *Nitro) ItemsCount() int64
- func (m *Nitro) LoadFromDisk(dir string, concurr int, callb ItemCallback) (*Snapshot, error)
- func (m *Nitro) MemoryInUse() int64
- func (m *Nitro) NewIterator(snap *Snapshot) *Iterator
- func (m *Nitro) NewSnapshot() (*Snapshot, error)
- func (m *Nitro) NewWriter() *Writer
- func (m *Nitro) StoreToDisk(dir string, snap *Snapshot, concurr int, itmCallback ItemCallback) (err error)
- func (m *Nitro) Visitor(snap *Snapshot, callb VisitorCallback, shards int, concurrency int) error
- type NodeList
- type Snapshot
- type VisitorCallback
- type Writer
- func (w *Writer) Delete(bs []byte) (success bool)
- func (w *Writer) Delete2(bs []byte) (n *skiplist.Node, success bool)
- func (w *Writer) DeleteNode(x *skiplist.Node) (success bool)
- func (w *Writer) GetNode(bs []byte) *skiplist.Node
- func (w *Writer) Put(bs []byte)
- func (w *Writer) Put2(bs []byte) (n *skiplist.Node)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMaxSnapshotsLimitReached means 32 bit integer overflow of snap number ErrMaxSnapshotsLimitReached = fmt.Errorf("Maximum snapshots limit reached") // ErrShutdown means an operation on a shutdown Nitro instance ErrShutdown = fmt.Errorf("Nitro instance has been shutdown") )
var (
// DiskBlockSize - backup file reader and writer
DiskBlockSize = 512 * 1024
)
Functions ¶
func CompareNitro ¶
CompareNitro implements comparator for Nitro instances based on its id
func CompareSnapshot ¶
CompareSnapshot implements comparator for snapshots based on snapshot number
func Debug ¶
func Debug(flag bool)
Debug enables debug mode Additional details will be logged in the statistics
func ItemSize ¶
ItemSize returns total bytes consumed by item representation
func KVFromBytes ¶
KVFromBytes extracts key-value pair from item bytes returned by iterator
func KVToBytes ¶
KVToBytes encodes key-value pair to item bytes which can be passed to the Put() and Delete() methods.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config - Nitro instance configuration
func (*Config) SetKeyComparator ¶
func (cfg *Config) SetKeyComparator(cmp KeyCompare)
SetKeyComparator provides key comparator for the Nitro item data
func (*Config) UseDeltaInterleaving ¶
func (cfg *Config) UseDeltaInterleaving()
UseDeltaInterleaving option enables to avoid additional memory required during disk backup as due to locking of older snapshots. This non-intrusive backup mode eliminates the need for locking garbage collectable old snapshots. But, it may use additional amount of disk space for backup.
type FileReader ¶
FileReader represents backup file reader
type FileWriter ¶
FileWriter represents backup file writer
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents nitro item header The item data is followed by the header. Item data is a block of bytes. The user can store key and value into a block of bytes and provide custom key comparator.
type ItemCallback ¶
type ItemCallback func(*ItemEntry)
ItemCallback implements callback used for backup file to Nitro restore API
type ItemEntry ¶
type ItemEntry struct {
// contains filtered or unexported fields
}
ItemEntry is a wrapper item struct used by backup file to Nitro restore callback
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator implements Nitro snapshot iterator
func (*Iterator) Get ¶
Get eturns the current item data from the iterator.
func (*Iterator) GetNode ¶
GetNode eturns the current skiplist node which holds current item.
func (*Iterator) Refresh ¶
func (it *Iterator) Refresh()
Refresh is a helper API to call refresh accessor tokens manually This would enable SMR to reclaim objects faster if an iterator is alive for a longer duration of time.
func (*Iterator) Seek ¶
Seek to a specified key or the next bigger one if an item with key does not exist.
func (*Iterator) SeekFirst ¶
func (it *Iterator) SeekFirst()
SeekFirst moves cursor to the beginning
func (*Iterator) SetRefreshRate ¶
SetRefreshRate sets automatic refresh frequency. By default, it is unlimited If this is set, the iterator SMR accessor will be refreshed after every `rate` items.
type KeyCompare ¶
KeyCompare implements item data key comparator
type Nitro ¶
type Nitro struct { Config // contains filtered or unexported fields }
Nitro instance
func NewWithConfig ¶
NewWithConfig creates a new Nitro instance based on provided configuration.
func (*Nitro) DecodeItem ¶
DecodeItem decodes encoded [2 byte len][item_bytes] format.
func (*Nitro) EncodeItem ¶
EncodeItem encodes in [2 byte len][item_bytes] format.
func (*Nitro) GetSnapshots ¶
GetSnapshots returns the list of current live snapshots This API is mainly for debugging purpose
func (*Nitro) ItemsCount ¶
ItemsCount returns the number of items in the Nitro instance
func (*Nitro) LoadFromDisk ¶
LoadFromDisk restores Nitro from a disk backup
func (*Nitro) MemoryInUse ¶
MemoryInUse returns total memory used by the Nitro instance.
func (*Nitro) NewIterator ¶
NewIterator creates an iterator for a Nitro snapshot
func (*Nitro) NewSnapshot ¶
NewSnapshot creates a new Nitro snapshot. This is a thread-unsafe API. While this API is invoked, no other Nitro writer should concurrently call any public APIs such as Put*() and Delete*().
func (*Nitro) StoreToDisk ¶
func (m *Nitro) StoreToDisk(dir string, snap *Snapshot, concurr int, itmCallback ItemCallback) (err error)
StoreToDisk backups Nitro snapshot to disk Concurrent threads are used to perform backup and concurrency can be specified.
func (*Nitro) Visitor ¶
Visitor implements concurrent Nitro snapshot visitor This API divides the range of keys in a snapshot into `shards` range partitions Number of concurrent worker threads used can be specified.
type NodeList ¶
type NodeList struct {
// contains filtered or unexported fields
}
NodeList is a linked list of skiplist nodes
func NewNodeList ¶
NewNodeList creates new node list
func (*NodeList) Head ¶
Head returns head node from the list
func (*NodeList) Keys ¶
Keys returns all keys from the node list
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot describes Nitro immutable snapshot
func (*Snapshot) Close ¶
func (s *Snapshot) Close()
Close is the snapshot descructor Once a thread has finished using a snapshot, it can be destroyed by calling Close(). Internal garbage collector takes care of freeing the items.
func (Snapshot) Count ¶
Count returns the number of items in the Nitro snapshot
func (*Snapshot) Decode ¶
Decode implements binary decoder for snapshot metadata
func (*Snapshot) Encode ¶
Encode implements Binary encoder for snapshot metadata
func (*Snapshot) NewIterator ¶
NewIterator creates a new snapshot iterator
type VisitorCallback ¶
VisitorCallback implements Nitro snapshot visitor callback
type Writer ¶
type Writer struct { *Nitro // contains filtered or unexported fields }
Writer provides a handle for concurrent access Nitro writer is thread-unsafe and should initialize separate Nitro writers to perform concurrent writes from multiple threads.
func (*Writer) Delete ¶
Delete an item Delete always succeed if an item exists.
func (*Writer) Delete2 ¶
Delete2 is same as Delete(). Additionally returns the deleted item's node
func (*Writer) DeleteNode ¶
DeleteNode deletes an item by specifying its skiplist Node. Using this API can avoid a O(logn) lookup during Delete().
func (*Writer) GetNode ¶
GetNode implements lookup of an item and return its skiplist Node This API enables to lookup an item without using a snapshot handle.
func (*Writer) Put ¶
Put implements insert of an item into Intro Put fails if an item already exists