badger

package
v1.1.22 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 37 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Megabyte is the standard 1 million byte units.
	Megabyte = 1000 * 1000

	// SerialLen is the length of serial values used for conflict resistant
	// keys.
	SerialLen = 8

	// TimestampLen is the standard 64 bit, 8 byte unix timestamp
	TimestampLen = 8

	// IDPrefixLen is the length of the prefix trimmed out of a 256 bit SHA256
	// hash that is the "id" field of an event.
	IDPrefixLen = 8

	// PubkeyPrefixLen is the length of the prefix trimmed out of a public key
	// field of an event used in index keys.
	PubkeyPrefixLen = 8

	// KindLen is the length of bytes to store a kind.T - 2 bytes/16 bits
	KindLen = 2

	// PrefixLen is the length of the database key prefixes for each type of
	// record. It is 1, but this makes it unambiguous what it means.
	PrefixLen = 1
)

Variables

This section is empty.

Functions

func GetCounterKey added in v1.1.11

func GetCounterKey(ev *eventid.T, ser []byte) (key []byte)

GetCounterKey returns the proper counter key for a given event ID.

func GetIndexKeysForEvent added in v1.1.21

func GetIndexKeysForEvent(ev *event.T, evtSerial []byte) (keyz [][]byte)

GetIndexKeysForEvent generates all the index keys required to filter for events. evtSerial should be the output of Serial() which gets a unique, monotonic counter value for each new event.

func GetTagKeyElements added in v1.1.21

func GetTagKeyElements(tagValue string) (prf index.P, elems []keys.Element)

func GetTagKeyPrefix added in v1.1.21

func GetTagKeyPrefix(tagValue string) (key []byte, err error)

GetTagKeyPrefix returns tag index prefixes based on the initial field of a tag.

There is 3 types of index tag keys:

- TagAddr: [ 8 ][ 2b Kind ][ 8b Pubkey ][ address/URL ][ 8b Serial ] - Tag32: [ 7 ][ 8b Pubkey ][ 8b Serial ] - Tag: [ 6 ][ address/URL ][ 8b Serial ]

This function produces the initial bytes without the index.

Types

type AccessEvent added in v1.1.21

type AccessEvent struct {
	EvID *eventid.T
	Ser  []byte
}

func (AccessEvent) String added in v1.1.21

func (a AccessEvent) String() (s string)

type Backend

type Backend struct {
	Path string
	// MaxLimit is the largest a single event JSON can be, in bytes.
	MaxLimit int
	// DBSizeLimit is the number of Mb we want to keep the data store from
	// exceeding.
	DBSizeLimit int
	// DBLowWater is the percentage of DBSizeLimit a GC run will reduce the used
	// storage down to.
	DBLowWater int
	// DBHighWater is the trigger point at which a GC run should start if
	// exceeded.
	DBHighWater int
	// GCFrequency is the frequency of checks of the current utilisation.
	GCFrequency time.Duration

	*badger.DB

	Ctx context.T
	WG  *sync.WaitGroup
	// contains filtered or unexported fields
}

func (*Backend) Close

func (b *Backend) Close()

func (*Backend) CountEvents

func (b *Backend) CountEvents(c context.T, f *filter.T) (count int, err error)

func (*Backend) DeleteEvent

func (b *Backend) DeleteEvent(c context.T, ev *event.T) error

func (*Backend) GCRun added in v1.1.18

func (b *Backend) GCRun() (err error)

func (*Backend) GarbageCollector added in v1.1.13

func (b *Backend) GarbageCollector()

func (*Backend) IncrementAccesses added in v1.1.12

func (b *Backend) IncrementAccesses(txMx *sync.Mutex, acc []AccessEvent) (err error)

IncrementAccesses takes a list of event IDs of events that were accessed in a query and updates their access counter records.

func (*Backend) Init

func (b *Backend) Init() error

func (*Backend) QueryEvents

func (b *Backend) QueryEvents(c context.T, f *filter.T) (ch event.C, err error)

func (*Backend) SaveEvent

func (b *Backend) SaveEvent(c context.T, ev *event.T) (err error)

func (*Backend) Serial

func (b *Backend) Serial() (ser uint64, err error)

func (*Backend) SerialBytes added in v1.1.21

func (b *Backend) SerialBytes() (ser []byte, err error)

func (*Backend) SerialKey added in v1.1.21

func (b *Backend) SerialKey() (idx []byte, ser []byte)

SerialKey gets a sequence number from the badger DB backend, prefixed with a key type code 0 Event.

This value is used as the key for a raw event record.

func (*Backend) Wipe added in v1.1.19

func (b *Backend) Wipe() (err error)

type CountItem added in v1.1.13

type CountItem struct {
	Key       []byte
	Value     []byte
	Size      uint32
	Freshness timestamp.T
}

type CountItems added in v1.1.13

type CountItems []CountItem

func (CountItems) Len added in v1.1.13

func (c CountItems) Len() int

func (CountItems) Less added in v1.1.13

func (c CountItems) Less(i, j int) bool

func (CountItems) Swap added in v1.1.13

func (c CountItems) Swap(i, j int)

func (CountItems) Total added in v1.1.13

func (c CountItems) Total() (total int)

type Results added in v1.1.21

type Results struct {
	Ev  *event.T
	Ser []byte
}

Directories

Path Synopsis
Package keys is a composable framework for constructing badger keys from fields of events.
Package keys is a composable framework for constructing badger keys from fields of events.
arb
id

Jump to

Keyboard shortcuts

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