persistence

package
v0.0.0-...-3fc995f Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: BSD-2-Clause-Views Imports: 12 Imported by: 7

README

persistence

A simple logging persistence engine. Logs operations to logfiles, when they get too big it merges them into snapshots.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger is something that can log or replay Ops.

func NewLogger

func NewLogger(dir string) *Logger

NewLogger will return a Logger that will dump data into dir, or replay data from dir.

func (*Logger) Clear

func (self *Logger) Clear()

Clear will stop this Logger and remove all snapshots or logfiles older than now.

func (*Logger) Dump

func (self *Logger) Dump(o Op)

Dump will accept an operation if this Logger is recording, and dump it into a logfile.

func (*Logger) Limit

func (self *Logger) Limit(maxSize int64) *Logger

Limit will limit the size of the last logfile to maxSize bytes. When the last logfile is bigger than maxSize, it will merge the last snapshot and any logfile created after it into a new snapshot, and start a new logfile to continue. All this will happen transparently in a separate goroutine.

func (*Logger) Play

func (self *Logger) Play(operate Operate)

Play will replay the latest snapshot and all logfiles created after it using the provided operate.

func (*Logger) Record

func (self *Logger) Record() (rval chan *logfile)

Record will make this Logger start recording.

func (*Logger) Recording

func (self *Logger) Recording() bool

Recording returns true if this Logger is currently recording (as opposed to replaying or idling).

func (*Logger) Stop

func (self *Logger) Stop() *Logger

Stop will stop this Logger. It will not return until all running recordings or snaphots are finished.

type Op

type Op struct {
	Key           []byte
	SubKey        []byte
	Value         []byte
	Timestamp     int64
	Put           bool
	Clear         bool
	Configuration map[string]string
}

Op is a simple get/put/clear or configuration operation to log or replay.

type Operate

type Operate func(o Op)

Operate is a function that operates on an Op, for replay purposes. It is supposed to insert Ops with the Put flag, Clear data if the Clear flag is set, handle configuration changes or delete data.

Jump to

Keyboard shortcuts

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