storage

package
v0.0.0-...-46d7ffa Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const NODE_STATS_DB_NAME = "_node"
View Source
const STATUS_FILE = "status"
View Source
const SYNC_DELETES_COLLECTION_NAME = "_sync_deletes"
View Source
const SYSTEM_DB_NAME = "_system"
View Source
const WAL_DIR = "wal"

Variables

View Source
var (
	ErrKeyNotFound            = badger.ErrKeyNotFound
	ErrCollectionNameReserved = errors.New("this collection name cannot be used")
	ErrCollectionNotFound     = errors.New("collection not found")
)

Functions

func AppendToWal

func AppendToWal(forNodeId string, a Action, collection string, key []byte, value []byte, timestamp int64) error

func DbGarbageCollector

func DbGarbageCollector(db *badger.DB)

func DecodeValue

func DecodeValue(content []byte, writeTo interface{}) error

func EncodeValue

func EncodeValue(data interface{}) ([]byte, error)

func FromBytes

func FromBytes(i []byte, t interface{}) (err error)

func FromString

func FromString(content string, writeTo interface{}) error

func ToBytes

func ToBytes(i interface{}) (k []byte, err error)

Encodes to bynary preserving order

func ToString

func ToString(data interface{}) (string, error)

Types

type Action

type Action uint8
const (
	SET Action = iota
	DEL
)

func (Action) String

func (a Action) String() string

type Collection

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

func OpenCollection

func OpenCollection(collectionName string) (*Collection, error)

func (*Collection) BackUp

func (c *Collection) BackUp()

func (*Collection) Close

func (c *Collection) Close()

func (*Collection) Delete

func (c *Collection) Delete(k interface{}) error

func (*Collection) DeleteCollection

func (c *Collection) DeleteCollection() error

func (*Collection) DeleteKeys

func (c *Collection) DeleteKeys(keys [][]byte, updateStats func([]byte)) error

func (*Collection) DeleteRaw

func (c *Collection) DeleteRaw(k []byte) error

func (*Collection) Exists

func (c *Collection) Exists(key []byte) (bool, error)

func (*Collection) Get

func (c *Collection) Get(k interface{}, v interface{}) error

func (*Collection) GetFilteredIterator

func (c *Collection) GetFilteredIterator(from interface{}, till interface{}) (*Iterator, error)

func (*Collection) GetIterator

func (c *Collection) GetIterator() (*Iterator, error)

func (*Collection) GetIteratorFrom

func (c *Collection) GetIteratorFrom(from interface{}) (*Iterator, error)

func (*Collection) GetIteratorFromRaw

func (c *Collection) GetIteratorFromRaw(from []byte) (*Iterator, error)

func (*Collection) GetRaw

func (c *Collection) GetRaw(k []byte) ([]byte, error)

func (*Collection) LoadBackUp

func (c *Collection) LoadBackUp()

func (*Collection) Set

func (c *Collection) Set(k interface{}, v interface{}) error

func (*Collection) SetRaw

func (c *Collection) SetRaw(k []byte, v []byte) error

func (*Collection) UpsertFromStreaming

func (c *Collection) UpsertFromStreaming(data []stream.StreamEntry, skip func(string, []byte) bool, updateStats func())

type DbValue

type DbValue struct {
	Hash      uint64
	Timestamp int64
	Value     []byte
}

type Entry

type Entry struct {
	LogPosition uint64
	Collection  string
	Timestamp   int64
	Action      Action
	Key         []byte
	Value       []byte
}

type Iterator

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

Usage:

test, err := storage.OpenCollection("test")

if err != nil {
	panic(err)
}
for i := 0; i < 10; i++ {
	fmt.Println(i)
	test.Set(i, "test")
}

it, err := test.GetFilteredIterator(2, 7)
if err != nil {
	panic(err)
}
for it.HasMore() {
	var v string
	var k int
	err := it.Next(&k, &v)
	if err != nil {
		panic(err)
	}
	fmt.Println(k, "=", v)
}

it, err := test.GetIterator()
if err != nil {
	panic(err)
}
for it.HasMore() {
	var v string
	var k int
	err := it.Next(&k, &v)
	if err != nil {
		panic(err)
	}
	fmt.Println(k, "=", v)
}
it.Close()

func GetFilteredIterator

func GetFilteredIterator(db *badger.DB, from interface{}, till interface{}) (*Iterator, error)

func GetIterator

func GetIterator(db *badger.DB) (*Iterator, error)

func GetIteratorFrom

func GetIteratorFrom(db *badger.DB, from interface{}) (*Iterator, error)

func GetIteratorFromRaw

func GetIteratorFromRaw(db *badger.DB, from []byte) (*Iterator, error)

func (*Iterator) Close

func (i *Iterator) Close()

func (*Iterator) HasMore

func (i *Iterator) HasMore() bool

func (*Iterator) HasMoreWithPrefix

func (i *Iterator) HasMoreWithPrefix(prefix interface{}) bool

func (*Iterator) Next

func (i *Iterator) Next(key interface{}, value interface{}) error

func (*Iterator) NextRaw

func (i *Iterator) NextRaw() (hash uint64, key []byte, value []byte, err error)

type StorageManager

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

func InitStorageManager

func InitStorageManager() *StorageManager

func (*StorageManager) DeleteCollection

func (db *StorageManager) DeleteCollection(collectionName string) (err error)

func (*StorageManager) GetCollection

func (db *StorageManager) GetCollection(collectionName string) (*Collection, error)

func (*StorageManager) Shutdown

func (db *StorageManager) Shutdown()

type Wal

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

func InitWal

func InitWal(nodeId string) (*Wal, error)

func (*Wal) Close

func (w *Wal) Close() error

func (*Wal) Destroy

func (w *Wal) Destroy() error

func (*Wal) GetIterator

func (w *Wal) GetIterator() *WalIterator

func (*Wal) Log

func (w *Wal) Log(a Action, collection string, key []byte, value []byte, timestamp int64) error

func (*Wal) Read

func (w *Wal) Read(i uint64) (Entry, error)

func (*Wal) TruncateFront

func (w *Wal) TruncateFront(i uint64) error

type WalIterator

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

func StartScan

func StartScan(nodeId string) (*WalIterator, error)

func (*WalIterator) AllStreamed

func (it *WalIterator) AllStreamed()

WARNING, it will delete the wal for the node

func (*WalIterator) HasMore

func (it *WalIterator) HasMore() bool

func (*WalIterator) Next

func (it *WalIterator) Next() (Entry, error)

func (*WalIterator) PullNext

func (it *WalIterator) PullNext() (Entry, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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