storage

package
v0.0.0-...-f45a054 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFakePebble

func NewFakePebble() *fakePebble

func NewFakePebbleIterator

func NewFakePebbleIterator(data map[string][]byte) *fakePebbleIterator

func NewPebbleClient

func NewPebbleClient(dir string) (*pebble.DB, error)

Types

type BadgerDB

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

BadgerDB implements the DB interface using BadgerDB

func NewBadgerDB

func NewBadgerDB(dir string) (*BadgerDB, error)

NewBadgerDB creates new BadgerDB DB connection

func (*BadgerDB) Add

func (db *BadgerDB) Add(objectID string, propertyID string, data []byte) error

func (*BadgerDB) Delete

func (db *BadgerDB) Delete(objectID string, propertyID string) error

Delete objectID/propertyID from table.

func (*BadgerDB) Get

func (db *BadgerDB) Get(objectID string) (*Object, error)

Get returns an object (id + property/data map)

func (*BadgerDB) Import

func (db *BadgerDB) Import(objectID string, properties map[string][]byte) (string, error)

Import will take a map of property/data and store it as an object.

func (*BadgerDB) Update

func (db *BadgerDB) Update(objectID string, propertyID string, data []byte) error

Update an existing objectID/propertyID with new data. Given Add has become an upsert, this function can probably go.

type DB

type DB interface {

	// Add an object to the DB.
	//
	Add(objectID string, propertyID string, data []byte) error
	Delete(objectID string, propertyID string) error
	Update(objectID string, propertyID string, data []byte) error

	// Import imports an entire object (basically objectID and property collection)
	Import(objectID string, properties map[string][]byte) (string, error)

	// Get entire object. Will return all properties for an object.
	Get(objectID string) (*Object, error)
}

DB interface used to store the data *somewhere*

type DBSQLite

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

DBSQLite implements the DB interface using SQLite

func NewDBSQLite

func NewDBSQLite(filename string) (*DBSQLite, error)

NewDBSQLite creates new SQLite (modernc/sqlite) DB connection

func (*DBSQLite) Add

func (db *DBSQLite) Add(objectID string, propertyID string, data []byte) error

Add is really an upsert now. Might refactor update to be removed Currently this is NOT thread safe... so as soon as we're dealing with 2 different objects this will blow up due to transaction within transaction. Need to investigate modernc/sqlite threadsafety. If I be naive and throw a lock around this then I can see definite lag on test clients and everything gets out of sync.

Will probably move all writing out to a separate goroutine and have the various processors just dump their changes onto a bufferless channel. Goroutine does write, signals back to caller (via another channel?) that write is done. Investigate... FIXME(kpfaulkner)

func (*DBSQLite) Delete

func (db *DBSQLite) Delete(objectID string, propertyID string) error

Delete objectID/propertyID from table.

func (*DBSQLite) Get

func (db *DBSQLite) Get(objectID string) (*Object, error)

Get returns an object (id + property/data map)

func (*DBSQLite) Import

func (db *DBSQLite) Import(objectID string, properties map[string][]byte) (string, error)

Import will take a map of property/data and store it as an object.

func (*DBSQLite) Update

func (db *DBSQLite) Update(objectID string, propertyID string, data []byte) error

Update an existing objectID/propertyID with new data. Given Add has become an upsert, this function can probably go.

type NullDB

type NullDB struct {
}

Fake DB... just for testing wont do anything with the data.

func NewNullDB

func NewNullDB() (*NullDB, error)

NewNullDB creates new NullDB

func (*NullDB) Add

func (db *NullDB) Add(objectID string, propertyID string, data []byte) error

func (*NullDB) Delete

func (db *NullDB) Delete(objectID string, propertyID string) error

Delete objectID/propertyID from table.

func (*NullDB) Get

func (db *NullDB) Get(objectID string) (*Object, error)

Get returns an object (id + property/data map)

func (*NullDB) Import

func (db *NullDB) Import(objectID string, properties map[string][]byte) (string, error)

Import will take a map of property/data and store it as an object.

func (*NullDB) Update

func (db *NullDB) Update(objectID string, propertyID string, data []byte) error

Update an existing objectID/propertyID with new data. Given Add has become an upsert, this function can probably go.

type Object

type Object struct {
	ObjectID   string
	Properties map[string][]byte
}

Object represents an object in the system. Its VERY basic. ObjectID (unique identifier) Map of propertyname to bytes. The caller can make the property names whatever they want... the server does not care (well shouldn't care... TBD)

func NewObject

func NewObject(objectID string) *Object

type PebbleDB

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

BadgerDB implements the DB interface using BadgerDB

func NewPebbleDB

func NewPebbleDB(pdb PebbleMinimal) (*PebbleDB, error)

NewPebbleDB creates new BadgerDB DB connection

func (*PebbleDB) Add

func (db *PebbleDB) Add(objectID string, propertyID string, data []byte) error

func (*PebbleDB) Delete

func (db *PebbleDB) Delete(objectID string, propertyID string) error

Delete objectID/propertyID from table.

func (*PebbleDB) Get

func (db *PebbleDB) Get(objectID string) (*Object, error)

Get returns an object (id + property/data map)

func (*PebbleDB) Import

func (db *PebbleDB) Import(objectID string, properties map[string][]byte) (string, error)

Import will take a map of property/data and store it as an object.

func (*PebbleDB) Update

func (db *PebbleDB) Update(objectID string, propertyID string, data []byte) error

Update an existing objectID/propertyID with new data. Given Add has become an upsert, this function can probably go.

type PebbleIterator

type PebbleIterator interface {
	First() bool
	Valid() bool
	Next() bool
	Key() []byte
	ValueAndErr() ([]byte, error)
}

PebbleIterator... used for mocking in tests Is this a mistake?

type PebbleMinimal

type PebbleMinimal interface {
	Set(key, value []byte, opts *pebble.WriteOptions) error
	NewIter(o *pebble.IterOptions) *pebble.Iterator
}

PebbleMinimal is the minimal interface we use from Pebble Interface to help mock this out for testing.

Jump to

Keyboard shortcuts

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