Documentation
¶
Overview ¶
Package ratel is a badger DB based event store.
Index ¶
- Constants
- func Create_a_Tag(tagKey, tagValue string, CA *createdat.T, ser *serial.T) (prf index.P, elems []keys.Element, err error)
- func GetCounterKey(ser *serial.T) (key []byte)
- func GetIndexKeysForEvent(ev *event.T, ser *serial.T) (keyz [][]byte)
- func GetTagKeyPrefix(tagValue string) (key []byte, err error)
- func NewLogger(logLevel int32, label string) (l *logger)
- func PrepareQueries(f *filter.T) (qs []query, ext *filter.T, since uint64, err error)
- type BackendParams
- type Results
- type T
- func (r *T) Close() (err error)
- func (r *T) DeleteEvent(c context.T, eid *eventid.T, noTombstone ...bool) (err error)
- func (r *T) Export(c context.T, w io.Writer, pubkeys ...[]byte)
- func (r *T) FetchIds(c context.T, evIds *tag.T, out io.Writer) (err error)
- func (r *T) GetConfiguration() (c *config.C, err error)
- func (r *T) Import(rr io.Reader)
- func (r *T) Init(path string) (err error)
- func (r *T) Marshal(ev *event.T, dst []byte) (b []byte)
- func (r *T) Nuke() (err error)
- func (r *T) Path() string
- func (r *T) QueryEvents(c context.T, f *filter.T) (evs event.Ts, err error)
- func (r *T) QueryForIds(c context.T, f *filter.T) (founds []store.IdTsPk, err error)
- func (r *T) Rescan() (err error)
- func (r *T) SaveEvent(c context.T, ev *event.T) (err error)
- func (r *T) Serial() (ser uint64, err error)
- func (r *T) SerialBytes() (ser []byte, err error)
- func (r *T) SerialKey() (idx []byte, ser *serial.T)
- func (r *T) SetConfiguration(c *config.C) (err error)
- func (r *T) SetLogLevel(level string)
- func (r *T) Sync() (err error)
- func (r *T) Unmarshal(ev *event.T, evb []byte) (rem []byte, err error)
Constants ¶
const DefaultMaxLimit = 2048
DefaultMaxLimit is set to a size that means the usual biggest batch of events sent to a client usually is at most about 256kb or so.
const Version = 1
Variables ¶
This section is empty.
Functions ¶
func Create_a_Tag ¶
func Create_a_Tag(tagKey, tagValue string, CA *createdat.T, ser *serial.T) (prf index.P, elems []keys.Element, err error)
Create_a_Tag generates tag indexes from a tag key, tag value, created_at timestamp and the event serial.
func GetCounterKey ¶
GetCounterKey returns the proper counter key for a given event Id. This needs a separate function because of what it does, but is generated in the general GetIndexKeysForEvent function.
func GetIndexKeysForEvent ¶
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 GetTagKeyPrefix ¶
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 BackendParams ¶
type BackendParams struct {
Ctx context.T
WG *sync.WaitGroup
HasL2, UseCompact bool
BlockCacheSize, LogLevel, MaxLimit int
Compression string // none,snappy,zstd
Extra []int
}
BackendParams is the configurations used in creating a new ratel.T.
type T ¶
type T struct {
Ctx context.T
WG *sync.WaitGroup
HasL2 bool
BlockCacheSize int
InitLogLevel int32
Logger *logger
// DB is the badger db
*badger.DB
// Threads is how many CPU threads we dedicate to concurrent actions, flatten and GC mark
Threads int
// MaxLimit is a default limit that applies to a query without a limit, to avoid sending out
// too many events to a client from a malformed or excessively broad filter.
MaxLimit int
// Flatten should be set to true to trigger a flatten at close... this is mainly triggered
// by running an import
Flatten bool
// UseCompact uses a compact encoding based on the canonical format (generate hash of it to
// get Id field with the signature in raw binary after.
UseCompact bool
// Compression sets the compression to use, none/snappy/zstd. If zstd compression is enabled
// there is less benefit to UseCompact, and instead of having to re-marshal the event it can
// be directly delivered from the form returned from the database.
Compression string
// contains filtered or unexported fields
}
T is a badger event store database with layer2 and garbage collection.
func GetBackend
deprecated
func GetBackend(Ctx context.T, WG *sync.WaitGroup, hasL2, useCompact bool, blockCacheSize, logLevel, maxLimit int, compression string) (b *T)
GetBackend returns a reasonably configured badger.Backend.
The variadic params correspond to DBSizeLimit, DBLowWater, DBHighWater and GCFrequency as an integer multiplier of number of seconds.
Note that the cancel function for the context needs to be managed by the caller.
Deprecated: use New instead.
func (*T) Close ¶
Close the database. If the Flatten flag was set, then trigger the flattening of tables before shutting down.
func (*T) DeleteEvent ¶
DeleteEvent deletes an event if it exists, and writes a tombstone for the event unless requested not to, so that the event can't be saved again.
func (*T) Export ¶
Export the complete database of stored events to an io.Writer in line structured minified JSON.
func (*T) FetchIds ¶
FetchIds retrieves events based on a list of event Ids that have been provided.
func (*T) GetConfiguration ¶
GetConfiguration returns the current store.C stored in the database.
func (*T) QueryForIds ¶
func (*T) SerialBytes ¶
SerialBytes returns a new serial value, used to store an event record with a conflict-free unique code (it is a monotonic, atomic, ascending counter).
func (*T) SerialKey ¶
SerialKey returns a key used for storing events, and the raw serial counter bytes to copy into index keys.
func (*T) SetConfiguration ¶
SetConfiguration stores the store.C value to a provided setting.
func (*T) SetLogLevel ¶
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package del is a simple sorted list for database keys, primarily used to collect lists of events that need to be deleted either by expiration or for the garbage collector.
|
Package del is a simple sorted list for database keys, primarily used to collect lists of events that need to be deleted either by expiration or for the garbage collector. |
|
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
Package arb implements arbitrary length byte keys.Element.
|
Package arb implements arbitrary length byte keys.Element. |
|
count
Package count contains a series of data types for managing lists of indexes for garbage collection.
|
Package count contains a series of data types for managing lists of indexes for garbage collection. |
|
createdat
Package createdat implements a badger key index keys.Element for timestamps.
|
Package createdat implements a badger key index keys.Element for timestamps. |
|
fullid
Package fullid implements a keys.Element for a complete 32 byte event Ids.
|
Package fullid implements a keys.Element for a complete 32 byte event Ids. |
|
fullpubkey
Package fullpubkey implements a keys.Element for a complete 32 byte nostr pubkeys.
|
Package fullpubkey implements a keys.Element for a complete 32 byte nostr pubkeys. |
|
id
Package id implements a keys.Element for a truncated event Ids containing the first 8 bytes of an eventid.T.
|
Package id implements a keys.Element for a truncated event Ids containing the first 8 bytes of an eventid.T. |
|
index
Package index implements the single byte prefix of the database keys.
|
Package index implements the single byte prefix of the database keys. |
|
kinder
Package kinder implements a keys.Element for the 16 bit nostr 'kind' value for use in indexes.
|
Package kinder implements a keys.Element for the 16 bit nostr 'kind' value for use in indexes. |
|
pubkey
Package pubkey implements an 8 byte truncated public key implementation of a keys.Element.
|
Package pubkey implements an 8 byte truncated public key implementation of a keys.Element. |
|
serial
Package serial implements a keys.Element for encoding a serial (monotonic 64 bit counter) for stored events, used to link an index to the main data table.
|
Package serial implements a keys.Element for encoding a serial (monotonic 64 bit counter) for stored events, used to link an index to the main data table. |
|
tombstone
Package tombstone is a 16 byte truncated event Id for keys.Element used to mark an event as being deleted so it isn't saved again.
|
Package tombstone is a 16 byte truncated event Id for keys.Element used to mark an event as being deleted so it isn't saved again. |
|
Package prefixes provides a list of the index.P types that designate tables in the ratel event store, as well as enabling a simple syntax to assemble and decompose an index key into its keys.Element s.
|
Package prefixes provides a list of the index.P types that designate tables in the ratel event store, as well as enabling a simple syntax to assemble and decompose an index key into its keys.Element s. |