Documentation
¶
Index ¶
- Constants
- Variables
- func RegisterType(t *Type)
- func ValidateBackup(r io.Reader) error
- type DB
- func (d *DB) BackupTo(w io.Writer) error
- func (d *DB) Close() error
- func (d *DB) DebugDump(w io.Writer)
- func (d *DB) Delete(id []byte) error
- func (d *DB) Get(id []byte, target any) error
- func (d *DB) GetRaw(id []byte) (json.RawMessage, error)
- func (d *DB) GetStatus() Status
- func (d *DB) Has(id []byte) (bool, error)
- func (d *DB) NewIterator(start, limit []byte) Iterator
- func (d *DB) NewIteratorPrefix(pfx []byte) Iterator
- func (d *DB) Reindex() error
- func (d *DB) RestoreFrom(r io.Reader) error
- func (d *DB) Search(typ string, search map[string]any) (Iterator, error)
- func (d *DB) SearchFirst(typ string, search map[string]any, target any) ([]byte, error)
- func (d *DB) SearchFirstRaw(typ string, search map[string]any) ([]byte, json.RawMessage, error)
- func (d *DB) Set(id []byte, val any) error
- func (d *DB) String() string
- func (d *DB) Validate() error
- func (d *DB) WaitReady()
- type Iterator
- type RPC
- type Status
- type Type
- type TypeKey
Constants ¶
const ( RecordSet dblogType = iota // set the full value of a record RecordDelete // delete a record )
const ( PktGetInfo = 0x00 // GetInfo() PktGetLogIds = 0x01 // GetLogs(<peer>, <epoch>) PktFetchLog = 0x02 // FetchLog(<key>) uses no response packet id, response is always inline PktGetInfoResp = 0x80 // GetInfo()|Response PktLogPush = 0x40 // pushed log entry PktLogIdsPush = 0x41 // LogIdPush(<peer>, ...<logid>) ResponseFlag = 0x80 // response flag )
Variables ¶
var (
ErrKeyConflict = errors.New("record's key conflicts with an existing record")
)
Functions ¶
func RegisterType ¶
func RegisterType(t *Type)
func ValidateBackup ¶ added in v0.1.10
ValidateBackup will read a backup and check for some possible errors, such as corrupted checkpoints
It is a good practice to call ValidateBackup after creating a backup to ensure it will be possible to restore it in the future should the need arise.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) BackupTo ¶ added in v0.1.10
BackupTo will generate a snapshot and write it to the given writer. The format is fairly simple and can be fed to RestoreFrom to restore the database to a given point in time.
Backup will include part of the database record modification history, so the backup data will usually be larger than the original database, but because the data has a lot of repetition, compression should be effective.
func (*DB) GetRaw ¶
func (d *DB) GetRaw(id []byte) (json.RawMessage, error)
GetRaw returns the json value for a given id
func (*DB) NewIterator ¶ added in v0.1.11
func (*DB) NewIteratorPrefix ¶ added in v0.1.11
func (*DB) Reindex ¶ added in v0.1.10
Reindex will re-generate all the indices for the records in the database
func (*DB) RestoreFrom ¶ added in v0.1.10
RestoreFrom will read a backup and restore the database from it. The current database must be pristine, or this will fail.
After a restore, in case of a cluster configuration, other peers will start replicating the data. This method will skip some basic checks on the input, and ValidateBackup should be called first to ensure backup usability (actually, ValidateBackup should be called after saving the backup as detecting invalid backups is more useful while the database still exists).
func (*DB) SearchFirst ¶
SearchFirst will find the first record matching the search params and set target search must match an existing key in the provided type
func (*DB) SearchFirstRaw ¶
SearchFirstRaw will find the first record matching the search params and return its json value search must match an existing key in the provided type
func (*DB) Set ¶
Set will update a given record in database. id must be unique in the whole db, even across types
type Iterator ¶ added in v0.1.11
type Iterator interface { // Key returns the key of the currently seeked item Key() []byte // Value return the raw value of the currently seeked item. Use Apply() to obtain the value as // an object. Value() []byte // Release releases resources and must be called after using the iterator Release() // Next seeks to the next record Next() bool // Prev seeks to the previous record Prev() bool // Seek seeks to the index specified and returns if it exists Seek([]byte) bool // Apply will decode the contents of the value currently pointed by Iterator // into the object passed by reference Apply(v any) error }
type RPC ¶
type RPC interface { // All will send a given data object to all other RPC instances on the fleet // and will collect responses All(ctx context.Context, data []byte) ([]any, error) // Broadcast will do the same as All but will not wait for responses Broadcast(ctx context.Context, data []byte) error // Request will send a given object to a specific peer and return the response Request(ctx context.Context, id string, data []byte) ([]byte, error) // Send will send a given buffer to a specific peer and ignore the response Send(ctx context.Context, id string, data []byte) error // Self will return the id of the local peer, can be used for other instances // to contact here with Send(). Self() string // ListPeers returns a list of connected peers ListOnlinePeers() []string // CountAllPeers return the number of known connected or offline peers CountAllPeers() int // Connect connects this RPC instance incoming events to a given function // that will be called each time an event is received. Connect(cb func(context.Context, []byte) ([]byte, error)) }
RPC interface is standardized
type Type ¶
type Type struct { Name string `json:"name"` Keys []*TypeKey `json:"keys"` Version int `json:"version"` // version for the definition, can be set to zero }
Type is a registered index type used in records. A record of a given type will inherit the passed keys and be indexed based on it. Some keys will always exist, such as to ensure objects can be referenced at all times.
Types will be stored in the database to ensure records can be indexed properly on first try.