package module
Version: v2.2.6+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0


lm2 CircleCI GoDoc

lm2 (listmap2) is an ordered key-value storage library.

It provides

  • Ordered key-value data model
  • Append-only modifications
  • Fully durable, atomic writes
  • Cursors with snapshot reads

Because it is append-only, records are never actually deleted. You will have to rewrite a collection to reclaim space.



Projects that use lm2

  • Transverse uses lm2 to store metadata, and uses lm2 through the Rig for synchronous replication.
  • Cistern uses lm2 for storing events.




This section is empty.


View Source
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")


func IsRollbackError

func IsRollbackError(err error) bool

IsRollbackError returns true if err is a RollbackError.


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

func (c *Collection) CompactFunc(f func(key, value string) (string, string, bool)) error

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) Err added in v1.4.0

func (c *Cursor) Err() error

Err returns the error encountered during iteration, if any.

func (*Cursor) Get

func (c *Cursor) Get(key string) (string, error)

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

func (c *Cursor) Key() string

Key returns the key of the current record. It returns an empty string if the cursor is not valid.

func (*Cursor) Next

func (c *Cursor) Next() bool

Next moves the cursor to the next record. It returns true if it lands on a valid record.

func (*Cursor) Seek

func (c *Cursor) Seek(key string)

Seek positions the cursor at the last key less than or equal to the provided key.

func (*Cursor) Valid

func (c *Cursor) Valid() bool

Valid returns true if the cursor's Key() and Value() methods can be called. It returns false if the cursor isn't at a valid record position.

func (*Cursor) Value

func (c *Cursor) Value() string

Value returns the value of the current record. It returns an empty string if the cursor is not valid.

type RollbackError

type RollbackError struct {
	DuplicateKey  bool
	ConflictedKey string
	Err           error

RollbackError is the error type returned after rollbacks.

func (RollbackError) Error

func (e RollbackError) Error() string

type Stats added in v1.0.0

type Stats struct {
	RecordsWritten uint64
	RecordsRead    uint64
	CacheHits      uint64
	CacheMisses    uint64

Stats holds collection statistics.

type WriteBatch

type WriteBatch struct {
	// contains filtered or unexported fields

WriteBatch represents a set of modifications.

func NewWriteBatch

func NewWriteBatch() *WriteBatch

NewWriteBatch returns a new WriteBatch.

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.


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL