Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadgerDB ¶
type BadgerDB struct {
// contains filtered or unexported fields
}
BadgerDB implements KeyValue and represents the application's connection to BadgerDB.
func NewBadgerDB ¶
NewBadgerDB initializes the BadgerDB embedded database given the provided storage directory path sd and TTL for keys. It is up to the caller to close the database with Close().
func (*BadgerDB) Cleanup ¶
Cleanup performs BadgerDB's garbage collection routine with the recommended discardRatio.
See: https://pkg.go.dev/github.com/ipsn/go-ipfs/gxlibs/github.com/dgraph-io/badger#DB.RunValueLogGC
This is the only time old records are actually removed, so make sure you're setting TTLs for records!
type KeyValue ¶
type KeyValue interface { // Replace the value of a Set or create a new one if it doesn't exist Put(KVEntry) error // Return a Set given its key Read(key []byte) (KVEntry, error) // Cleanup performs routine deletion of old records. We assign // TTLs to KV pairs and delete them periodically. Cleanup() error // Drain/tear down the connection, or something analogous for an // embedded database. Implementations should handle retries or drain // connections internally and panic on failure, since there is nothing // the program can do if it can't close the database. Close() }
KeyValue exposes a common interface for performing CRUD operations on an underlying storage layer. Assumes some kind of persistent KV store for linksrc.Sets.
Implentations need to include connection logic in code to initialize a Store.
type NoOpDB ¶
type NoOpDB struct{}
NoOpDB is used when we need to avoid touching the storage layer while still preserving our interactions with an abstract database. The strategy is to return whatever value will prevent the calling context from further interacting with the storage layer.
For get and put operations, we always return an error, so the caller knows that no actual data has been read or written.
For database-wide operations, such as cleaning up or closing the database, we always return a nil error. This is because, since there is nothing to close or clean up, the operation is always successful.
func (*NoOpDB) Cleanup ¶
Cleanup always returns nil in order to prevent retries or panics, since we want to keep the program humming along without touching the storage layer.