persist

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 17 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadFilenameSuffix indicates that SaveJSON or LoadJSON was called using
	// a filename that has a bad suffix. This prevents users from trying to use
	// this package to manage the temp files - this packaage will manage them
	// automatically.
	ErrBadFilenameSuffix = errors.New("filename suffix not allowed")

	// ErrBadHeader indicates that the file opened is not the file that was
	// expected.
	ErrBadHeader = errors.New("wrong header")

	// ErrBadVersion indicates that the version number of the file is not
	// compatible with the current codebase.
	ErrBadVersion = errors.New("incompatible version")

	// ErrFileInUse is returned if SaveJSON or LoadJSON is called on a file
	// that's already being manipulated in another thread by the persist
	// package.
	ErrFileInUse = errors.New("another thread is saving or loading this file")
)

Functions

func LoadJSON added in v0.1.2

func LoadJSON(meta Metadata, object interface{}, filename string) error

LoadJSON will load a persisted json object from disk.

func RandomSuffix

func RandomSuffix() string

RandomSuffix returns a 20 character base32 suffix for a filename. There are 100 bits of entropy, and a very low probability of colliding with existing files unintentionally.

func RemoveFile added in v0.1.2

func RemoveFile(filename string) error

RemoveFile removes an atomic file from disk, along with any uncommitted or temporary files.

func SaveJSON added in v0.1.2

func SaveJSON(meta Metadata, object interface{}, filename string) error

SaveJSON will save a json object to disk in a durable, atomic way. The resulting file will have a checksum of the data as the third line. If manually editing files, the checksum line can be replaced with the 8 characters "manual". This will cause the reader to accept the checksum even though the file has been changed.

Types

type BoltDatabase

type BoltDatabase struct {
	Metadata
	*bolt.DB
}

BoltDatabase is a persist-level wrapper for the bolt database, providing extra information such as a version number.

func OpenDatabase

func OpenDatabase(md Metadata, filename string) (*BoltDatabase, error)

OpenDatabase opens a database and validates its metadata.

func (*BoltDatabase) Close

func (db *BoltDatabase) Close() error

Close closes the database.

func (*BoltDatabase) SaveMetadata added in v1.0.5

func (db *BoltDatabase) SaveMetadata() error

SaveMetadata overwrites the metadata.

type LazyBoltBucket added in v1.2.0

type LazyBoltBucket struct {
	// contains filtered or unexported fields
}

LazyBoltBucket is a lazy implementation of the bolt DB, allowing you to only actually get the bucket from bolt db if you need it.

func NewLazyBoltBucket added in v1.2.0

func NewLazyBoltBucket(getter func() (*bolt.Bucket, error)) *LazyBoltBucket

NewLazyBoltBucket creates a new lazy BoltDB bucket, see `LazyBoltBucket` for more information.

func (*LazyBoltBucket) AsBoltBucket added in v1.3.1

func (lb *LazyBoltBucket) AsBoltBucket() (*bolt.Bucket, error)

func (*LazyBoltBucket) Bucket added in v1.2.0

func (lb *LazyBoltBucket) Bucket(name []byte) (*bolt.Bucket, error)

func (*LazyBoltBucket) CreateBucket added in v1.2.0

func (lb *LazyBoltBucket) CreateBucket(key []byte) (*bolt.Bucket, error)

func (*LazyBoltBucket) CreateBucketIfNotExists added in v1.2.0

func (lb *LazyBoltBucket) CreateBucketIfNotExists(key []byte) (*bolt.Bucket, error)

func (*LazyBoltBucket) Cursor added in v1.2.0

func (lb *LazyBoltBucket) Cursor() (*bolt.Cursor, error)

func (*LazyBoltBucket) Delete added in v1.2.0

func (lb *LazyBoltBucket) Delete(key []byte) error

func (*LazyBoltBucket) DeleteBucket added in v1.2.0

func (lb *LazyBoltBucket) DeleteBucket(key []byte) error

func (*LazyBoltBucket) ForEach added in v1.2.0

func (lb *LazyBoltBucket) ForEach(fn func(k, v []byte) error) error

func (*LazyBoltBucket) Get added in v1.2.0

func (lb *LazyBoltBucket) Get(key []byte) ([]byte, error)

func (*LazyBoltBucket) NextSequence added in v1.2.0

func (lb *LazyBoltBucket) NextSequence() (uint64, error)

func (*LazyBoltBucket) Put added in v1.2.0

func (lb *LazyBoltBucket) Put(key []byte, value []byte) error

func (*LazyBoltBucket) Root added in v1.2.0

func (lb *LazyBoltBucket) Root() (uint64, error)

func (*LazyBoltBucket) Sequence added in v1.2.0

func (lb *LazyBoltBucket) Sequence() (uint64, error)

func (*LazyBoltBucket) SetSequence added in v1.2.0

func (lb *LazyBoltBucket) SetSequence(v uint64) error

func (*LazyBoltBucket) Stats added in v1.2.0

func (lb *LazyBoltBucket) Stats() (bolt.BucketStats, error)

func (*LazyBoltBucket) Tx added in v1.2.0

func (lb *LazyBoltBucket) Tx() (*bolt.Tx, error)

func (*LazyBoltBucket) Writable added in v1.2.0

func (lb *LazyBoltBucket) Writable() (bool, error)

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

Logger is a wrapper for the standard library logger that enforces logging with the Sia-standard settings. It also supports a Close method, which attempts to close the underlying io.Writer.

func NewDiscardLogger added in v1.3.1

func NewDiscardLogger() *Logger

NewDiscardLogger creates a logger on which all calls succceed but do nothing.

func NewFileLogger

func NewFileLogger(info types.BlockchainInfo, logFilename string, verbose bool) (*Logger, error)

NewFileLogger returns a logger that logs to logFilename. The file is opened in append mode, and created if it does not exist. If verbose is set, Debug log statements are printed as well.

func NewLogger

func NewLogger(info types.BlockchainInfo, w io.Writer, verbose bool) *Logger

NewLogger returns a logger that can be closed. Calls should not be made to the logger after 'Close' has been called.

func (*Logger) Close

func (l *Logger) Close() error

Close logs a shutdown message and closes the Logger's underlying io.Writer, if it is also an io.Closer.

func (*Logger) Critical

func (l *Logger) Critical(v ...interface{})

Critical logs a message with a CRITICAL prefix that guides the user to the Sia github tracker. If debug mode is enabled, it will also write the message to os.Stderr and panic. Critical should only be called if there has been a developer error, otherwise Severe should be called.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug is equivalent to Logger.Print when build.DEBUG is true. Otherwise it is a no-op.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf is equivalent to Logger.Printf when build.DEBUG is true. Otherwise it is a no-op.

func (*Logger) Debugln

func (l *Logger) Debugln(v ...interface{})

Debugln is equivalent to Logger.Println when build.DEBUG is true. Otherwise it is a no-op.

func (*Logger) Severe

func (l *Logger) Severe(v ...interface{})

Severe logs a message with a SEVERE prefix. If debug mode is enabled, it will also write the message to os.Stderr and panic. Severe should be called if there is a severe problem with the user's machine or setup that should be addressed ASAP but does not necessarily require that the machine crash or exit.

type Metadata

type Metadata struct {
	Header, Version string
}

Metadata contains the header and version of the data being stored.

Jump to

Keyboard shortcuts

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