leveldbhelper

package
v0.0.0-...-579b097 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conf

type Conf struct {
	DBPath         string
	ExpectedFormat string
}

Conf configuration for `Provider`

`ExpectedFormat` is the expected value of the format key in the internal database. At the time of opening the db, A check is performed that either the db is empty (i.e., opening for the first time) or the value of the formatVersionKey is equal to `ExpectedFormat`. Otherwise, an error is returned. A nil value for ExpectedFormat indicates that the format is never set and hence there is no such record.

type DB

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

DB - a wrapper on an actual store

func CreateDB

func CreateDB(conf *Conf) *DB

CreateDB constructs a `DB`

func (*DB) Close

func (dbInst *DB) Close()

Close closes the underlying db

func (*DB) Delete

func (dbInst *DB) Delete(key []byte, sync bool) error

Delete deletes the given key

func (*DB) Get

func (dbInst *DB) Get(key []byte) ([]byte, error)

Get returns the value for the given key

func (*DB) GetIterator

func (dbInst *DB) GetIterator(startKey []byte, endKey []byte) iterator.Iterator

GetIterator returns an iterator over key-value store. The iterator should be released after the use. The resultset contains all the keys that are present in the db between the startKey (inclusive) and the endKey (exclusive). A nil startKey represents the first available key and a nil endKey represent a logical key after the last available key

func (*DB) IsEmpty

func (dbInst *DB) IsEmpty() (bool, error)

IsEmpty returns whether or not a database is empty

func (*DB) Open

func (dbInst *DB) Open()

Open opens the underlying db

func (*DB) Put

func (dbInst *DB) Put(key []byte, value []byte, sync bool) error

Put saves the key/value

func (*DB) WriteBatch

func (dbInst *DB) WriteBatch(batch *leveldb.Batch, sync bool) error

WriteBatch writes a batch

type DBHandle

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

DBHandle is an handle to a named db

func (*DBHandle) Close

func (h *DBHandle) Close()

Close closes the DBHandle after its db data have been deleted

func (*DBHandle) Delete

func (h *DBHandle) Delete(key []byte, sync bool) error

Delete deletes the given key

func (*DBHandle) Get

func (h *DBHandle) Get(key []byte) ([]byte, error)

Get returns the value for the given key

func (*DBHandle) GetIterator

func (h *DBHandle) GetIterator(startKey []byte, endKey []byte) (*Iterator, error)

GetIterator gets an handle to iterator. The iterator should be released after the use. The resultset contains all the keys that are present in the db between the startKey (inclusive) and the endKey (exclusive). A nil startKey represents the first available key and a nil endKey represent a logical key after the last available key

func (*DBHandle) IsEmpty

func (h *DBHandle) IsEmpty() (bool, error)

IsEmpty returns true if no data exists for the DBHandle

func (*DBHandle) NewUpdateBatch

func (h *DBHandle) NewUpdateBatch() *UpdateBatch

NewUpdateBatch returns a new UpdateBatch that can be used to update the db

func (*DBHandle) Put

func (h *DBHandle) Put(key []byte, value []byte, sync bool) error

Put saves the key/value

func (*DBHandle) WriteBatch

func (h *DBHandle) WriteBatch(batch *UpdateBatch, sync bool) error

WriteBatch writes a batch in an atomic way

type DataFormatInfo

type DataFormatInfo struct {
	FormatVerison string // version of the data format
	IsDBEmpty     bool   // set to true if the db does not contain any data
}

DataFormatInfo contains the information about the version of the data format

func RetrieveDataFormatInfo

func RetrieveDataFormatInfo(dbPath string) (*DataFormatInfo, error)

RetrieveDataFormatInfo retrieves the DataFormatInfo for the db at the supplied `dbPath`

type FileLock

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

FileLock encapsulate the DB that holds the file lock. As the FileLock to be used by a single process/goroutine, there is no need for the semaphore to synchronize the FileLock usage.

func NewFileLock

func NewFileLock(filePath string) *FileLock

NewFileLock returns a new file based lock manager.

func (*FileLock) IsLocked

func (f *FileLock) IsLocked() bool

Determine if the lock is currently held open.

func (*FileLock) Lock

func (f *FileLock) Lock() error

Lock acquire a file lock. We achieve this by opening a db for the given filePath. Internally, leveldb acquires a file lock while opening a db. If the db is opened again by the same or another process, error would be returned. When the db is closed or the owner process dies, the lock would be released and hence the other process can open the db. We exploit this leveldb functionality to acquire and release file lock as the leveldb supports this for Windows, Solaris, and Unix.

func (*FileLock) Unlock

func (f *FileLock) Unlock()

Unlock releases a previously acquired lock. We achieve this by closing the previously opened db. FileUnlock can be called multiple times.

type Iterator

type Iterator struct {
	iterator.Iterator
	// contains filtered or unexported fields
}

Iterator extends actual leveldb iterator

func (*Iterator) Key

func (itr *Iterator) Key() []byte

Key wraps actual leveldb iterator method

func (*Iterator) Seek

func (itr *Iterator) Seek(key []byte) bool

Seek moves the iterator to the first key/value pair whose key is greater than or equal to the given key. It returns whether such pair exist.

type Provider

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

Provider enables to use a single leveldb as multiple logical leveldbs

func NewProvider

func NewProvider(conf *Conf) (*Provider, error)

NewProvider constructs a Provider

func (*Provider) Close

func (p *Provider) Close()

Close closes the underlying leveldb

func (*Provider) Drop

func (p *Provider) Drop(dbName string) error

Drop drops all the data for the given dbName

func (*Provider) GetDBHandle

func (p *Provider) GetDBHandle(dbName string) *DBHandle

GetDBHandle returns a handle to a named db

func (*Provider) GetDataFormat

func (p *Provider) GetDataFormat() (string, error)

GetDataFormat returns the format of the data

func (*Provider) SetDataFormat

func (p *Provider) SetDataFormat(format string) error

type UpdateBatch

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

UpdateBatch encloses the details of multiple `updates`

func (*UpdateBatch) Delete

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

Delete deletes a Key and associated value

func (*UpdateBatch) Len

func (b *UpdateBatch) Len() int

Len returns number of records in the batch

func (*UpdateBatch) Put

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

Put adds a KV

func (*UpdateBatch) Reset

func (b *UpdateBatch) Reset()

Reset resets the batch

func (*UpdateBatch) Size

func (b *UpdateBatch) Size() int

Size returns the current size of the batch

Jump to

Keyboard shortcuts

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