leveldb

package
v0.0.0-...-cd2696f Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2013 License: BSD-2-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package leveldb provides implementation of LevelDB key/value database.

Create or open a database:

stor, err := storage.OpenFile("path/to/db")
...
db, err := leveldb.Open(stor, &opt.Options{Flag: opt.OFCreateIfMissing})
...

Read or modify the database content:

ro := &opt.ReadOptions{}
wo := &opt.WriteOptions{}
data, err := db.Get([]byte("key"), ro)
...
err = db.Put([]byte("key"), []byte("value"), wo)
...
err = db.Delete([]byte("key"), wo)
...

Iterate over database content:

iter := db.NewIterator(ro)
for iter.Next() {
	key := iter.Key()
	value := iter.Value()
	...
}
err = iter.Error()
...

Batch writes:

batch := new(leveldb.Batch)
batch.Put([]byte("foo"), []byte("value"))
batch.Put([]byte("bar"), []byte("another value"))
batch.Delete([]byte("baz"))
err = db.Write(batch, wo)
...

Use bloom filter:

o := &opt.Options{
	Flag:   opt.OFCreateIfMissing,
	Filter: filter.NewBloomFilter(10),
}
db, err := leveldb.Open(stor, o)
...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

Batch represent a write batch.

func (*Batch) Delete

func (b *Batch) Delete(key []byte)

Delete put given key to the batch for delete operation.

func (*Batch) Put

func (b *Batch) Put(key, value []byte)

Put put given key/value to the batch for insert operation.

func (*Batch) Reset

func (b *Batch) Reset()

Reset reset contents of the batch.

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB represent a database session.

func Open

func Open(p storage.Storage, o *opt.Options) (db *DB, err error)

Open open or create database from given storage.

func Recover

func Recover(p storage.Storage, o *opt.Options) (db *DB, err error)

Recover recover database with missing or corrupted manifest file. It will ignore any manifest files, valid or not.

func (*DB) Close

func (d *DB) Close() error

Close closes the database. Snapshot and iterator are invalid after this call

func (*DB) CompactRange

func (d *DB) CompactRange(r Range) error

CompactRange compact the underlying storage for the key range.

In particular, deleted and overwritten versions are discarded, and the data is rearranged to reduce the cost of operations needed to access the data. This operation should typically only be invoked by users who understand the underlying implementation.

Range.Start==nil is treated as a key before all keys in the database. Range.Limit==nil is treated as a key after all keys in the database. Therefore calling with Start==nil and Limit==nil will compact entire database.

func (*DB) Delete

func (d *DB) Delete(key []byte, wo *opt.WriteOptions) error

Delete remove the database entry (if any) for "key". It is not an error if "key" did not exist in the database.

func (*DB) Get

func (d *DB) Get(key []byte, ro *opt.ReadOptions) (value []byte, err error)

Get get value for given key of the latest snapshot of database.

func (*DB) GetApproximateSizes

func (d *DB) GetApproximateSizes(rr []Range) (sizes Sizes, err error)

GetApproximateSizes calculate approximate sizes of given ranges.

Note that the returned sizes measure file system space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size.

The results may not include the sizes of recently written data.

func (*DB) GetOptionsSetter

func (d *DB) GetOptionsSetter() opt.OptionsSetter

GetOptionsSetter return OptionsSetter for this database. OptionsSetter allows safely set options of an opened database.

func (*DB) GetProperty

func (d *DB) GetProperty(prop string) (value string, err error)

GetProperty used to query exported database state.

Valid property names include:

"leveldb.num-files-at-level<N>" - return the number of files at level <N>,
   where <N> is an ASCII representation of a level number (e.g. "0").
"leveldb.stats" - returns a multi-line string that storribes statistics
   about the internal operation of the DB.
"leveldb.sstables" - returns a multi-line string that storribes all
   of the sstables that make up the db contents.

func (*DB) GetSnapshot

func (d *DB) GetSnapshot() (snap *Snapshot, err error)

GetSnapshot return a handle to the current DB state. Iterators created with this handle will all observe a stable snapshot of the current DB state. The caller must call *Snapshot.Release() when the snapshot is no longer needed.

func (*DB) NewIterator

func (d *DB) NewIterator(ro *opt.ReadOptions) iterator.Iterator

NewIterator return an iterator over the contents of the latest snapshot of database. The result of NewIterator() is initially invalid (caller must call Next or one of Seek method, ie First, Last or Seek).

func (*DB) Put

func (d *DB) Put(key, value []byte, wo *opt.WriteOptions) error

Put set the database entry for "key" to "value".

func (*DB) Write

func (d *DB) Write(b *Batch, wo *opt.WriteOptions) (err error)

Write apply the specified batch to the database.

type Range

type Range struct {
	// Start key, include in the range
	Start []byte

	// Limit, not include in the range
	Limit []byte
}

Range represent key range.

type Reader

type Reader interface {
	Get(key []byte, ro *opt.ReadOptions) (value []byte, err error)
	NewIterator(ro *opt.ReadOptions) iterator.Iterator
}

Reader is the interface that wraps basic Get and NewIterator methods. This interface implemented by both *DB and *Snapshot.

type Sizes

type Sizes []uint64

func (Sizes) Sum

func (p Sizes) Sum() (n uint64)

Sum return sum of the sizes.

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot represent a database snapshot.

func (*Snapshot) Get

func (p *Snapshot) Get(key []byte, ro *opt.ReadOptions) (value []byte, err error)

Get get value for given key of this snapshot of database.

func (*Snapshot) NewIterator

func (p *Snapshot) NewIterator(ro *opt.ReadOptions) iterator.Iterator

NewIterator return an iterator over the contents of this snapshot of database.

func (*Snapshot) Release

func (p *Snapshot) Release()

Release release the snapshot. The caller must not use the snapshot after this call.

Directories

Path Synopsis
Package block allows read and write sorted key/value.
Package block allows read and write sorted key/value.
Package cache provides interface and implementation of a cache algorithms.
Package cache provides interface and implementation of a cache algorithms.
Package comparer provides interface and implementation for ordering sets of data.
Package comparer provides interface and implementation for ordering sets of data.
Package errors implements functions to manipulate errors.
Package errors implements functions to manipulate errors.
Package filter provides interface and implementation of probabilistic data structure.
Package filter provides interface and implementation of probabilistic data structure.
Package hash provides hashing utilities used by leveldb.
Package hash provides hashing utilities used by leveldb.
Package iterator provides interface and implementation to traverse over contents of a database.
Package iterator provides interface and implementation to traverse over contents of a database.
Package journal allows read and write sequence of data block.
Package journal allows read and write sequence of data block.
Package memdb provide in-memory key/value database implementation.
Package memdb provide in-memory key/value database implementation.
Package opt provides sets of options used by LevelDB.
Package opt provides sets of options used by LevelDB.
Package storage provides storage abstraction for LevelDB.
Package storage provides storage abstraction for LevelDB.
Package table allows read and write sorted key/value.
Package table allows read and write sorted key/value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL