Documentation ¶
Index ¶
- Variables
- func IsRollbackError(err error) bool
- type Collection
- func (c *Collection) Close()
- func (c *Collection) Compact() error
- func (c *Collection) CompactFunc(f func(key, value string) (string, string, bool)) error
- func (c *Collection) Destroy() error
- func (c *Collection) NewCursor() (*Cursor, error)
- func (c *Collection) OK() bool
- func (c *Collection) Stats() Stats
- func (c *Collection) Update(wb *WriteBatch) (int64, error)
- func (c *Collection) Version() int64
- type Cursor
- type RollbackError
- type Stats
- type WriteBatch
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDoesNotExist is returned when a collection's data file // doesn't exist. ErrDoesNotExist = errors.New("lm2: does not exist") // ErrInternal is returned when the internal state of the collection // is invalid. The collection should be closed and reopened. ErrInternal = errors.New("lm2: internal error") // ErrKeyNotFound is returned when a Cursor.Get() doesn't find // the requested key. ErrKeyNotFound = errors.New("lm2: key not found") )
Functions ¶
func IsRollbackError ¶
IsRollbackError returns true if err is a RollbackError.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection represents an ordered linked list map.
func NewCollection ¶
func NewCollection(file string, cacheSize int) (*Collection, error)
NewCollection creates a new collection with a data file at file. cacheSize represents the size of the collection cache.
func OpenCollection ¶
func OpenCollection(file string, cacheSize int) (*Collection, error)
OpenCollection opens a collection with a data file at file. cacheSize represents the size of the collection cache. ErrDoesNotExist is returned if file does not exist.
func (*Collection) Close ¶
func (c *Collection) Close()
Close closes a collection and all of its resources.
func (*Collection) Compact ¶
func (c *Collection) Compact() error
Compact rewrites a collection to clean up deleted records and optimize data layout on disk. NOTE: The collection is closed after compaction, so you'll have to reopen it.
func (*Collection) CompactFunc ¶
CompactFunc compacts with a custom compaction function. f is called with each key-value pair, and it should return the new key and value for that record if they should be changed, and whether to keep the record. Returning false will skip the record. NOTE: The collection is closed after compaction, so you'll have to reopen it.
func (*Collection) Destroy ¶ added in v1.2.1
func (c *Collection) Destroy() error
Destroy closes the collection and removes its associated data files.
func (*Collection) NewCursor ¶
func (c *Collection) NewCursor() (*Cursor, error)
NewCursor returns a new cursor with a snapshot view of the current collection state.
func (*Collection) OK ¶
func (c *Collection) OK() bool
OK returns true if the internal state of the collection is valid. If false is returned you should close and reopen the collection.
func (*Collection) Stats ¶ added in v1.0.0
func (c *Collection) Stats() Stats
Stats returns collection statistics.
func (*Collection) Update ¶
func (c *Collection) Update(wb *WriteBatch) (int64, error)
Update atomically and durably applies a WriteBatch (a set of updates) to the collection. It returns the new version (on success) and an error. The error may be a RollbackError; use IsRollbackError to check.
func (*Collection) Version ¶ added in v0.1.3
func (c *Collection) Version() int64
Version returns the last committed version.
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor represents a snapshot cursor.
func (*Cursor) Get ¶
Get gets a single key using the cursor. This is just a helper function that seeks and finds a key for you. ErrKeyNotFound is returned as the error when the key is not found.
func (*Cursor) Key ¶
Key returns the key of the current record. It returns an empty string if the cursor is not valid.
func (*Cursor) Next ¶
Next moves the cursor to the next record. It returns true if it lands on a valid record.
func (*Cursor) Seek ¶
Seek positions the cursor at the last key less than or equal to the provided key.
type RollbackError ¶
RollbackError is the error type returned after rollbacks.
func (RollbackError) Error ¶
func (e RollbackError) Error() string
type WriteBatch ¶
type WriteBatch struct {
// contains filtered or unexported fields
}
WriteBatch represents a set of modifications.
func (*WriteBatch) AllowOverwrite ¶
func (wb *WriteBatch) AllowOverwrite(allow bool)
AllowOverwrite determines whether keys will be overwritten. If allow is false and an existing key is being set, updates will be rolled back.
func (*WriteBatch) Delete ¶
func (wb *WriteBatch) Delete(key string)
Delete marks a key for deletion.
func (*WriteBatch) Set ¶
func (wb *WriteBatch) Set(key, value string)
Set adds key => value to the WriteBatch. Note: If a key is passed to Delete and Set, then the Set will be ignored.
func (*WriteBatch) SetSecureDelete ¶
func (wb *WriteBatch) SetSecureDelete(secureDelete bool)
SetSecureDelete determines whether record values are cleared with zero bytes when deleted.