badger

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 13 Imported by: 0

Documentation

Overview

Package badger provides a configurable BadgerDB go-datastore for use with IPFS Cluster.

Index

Constants

View Source
const (
	DefaultSubFolder = "badger"
)

Default values for badger Config

Variables

View Source
var (
	// DefaultBadgerOptions has to be a var because badger.DefaultOptions
	// is. Values are customized during Init().
	DefaultBadgerOptions badger.Options

	// DefaultGCDiscardRatio for GC operations. See Badger docs.
	DefaultGCDiscardRatio float64 = 0.2
	// DefaultGCInterval specifies interval between GC cycles.
	DefaultGCInterval time.Duration = 15 * time.Minute
	// DefaultGCSleep specifies sleep time between GC rounds.
	DefaultGCSleep time.Duration = 10 * time.Second
)

Functions

func Cleanup

func Cleanup(cfg *Config) error

Cleanup deletes the badger datastore.

func New

func New(cfg *Config) (ds.Datastore, error)

New returns a BadgerDB datastore configured with the given configuration.

Types

type Config

type Config struct {
	config.Saver

	// The folder for this datastore. Non-absolute paths are relative to
	// the base configuration folder.
	Folder string

	// For GC operation. See Badger documentation.
	GCDiscardRatio float64

	// Interval between GC cycles. Each GC cycle runs one or more
	// rounds separated by GCSleep.
	GCInterval time.Duration

	// Time between rounds in a GC cycle
	GCSleep time.Duration

	BadgerOptions badger.Options
}

Config is used to initialize a BadgerDB datastore. It implements the ComponentConfig interface.

func (*Config) ApplyEnvVars

func (cfg *Config) ApplyEnvVars() error

ApplyEnvVars fills in any Config fields found as environment variables.

func (*Config) ConfigKey

func (cfg *Config) ConfigKey() string

ConfigKey returns a human-friendly identifier for this type of Datastore.

func (*Config) Default

func (cfg *Config) Default() error

Default initializes this Config with sensible values.

func (*Config) GetFolder

func (cfg *Config) GetFolder() string

GetFolder returns the BadgerDB folder.

func (*Config) LoadJSON

func (cfg *Config) LoadJSON(raw []byte) error

LoadJSON reads the fields of this Config from a JSON byteslice as generated by ToJSON.

func (*Config) ToDisplayJSON added in v0.13.0

func (cfg *Config) ToDisplayJSON() ([]byte, error)

ToDisplayJSON returns JSON config as a string.

func (*Config) ToJSON

func (cfg *Config) ToJSON() (raw []byte, err error)

ToJSON generates a JSON-formatted human-friendly representation of this Config.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks that the fields of this Config have working values, at least in appearance.

Jump to

Keyboard shortcuts

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