journey

package module
v0.0.0-...-2d5462d Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Naive writeMethod = iota
	Syncr
	Batch
	Catastrophic
)

Indexes of each different handler implementation.

View Source
const (
	// Serialized logs commands as []byte to maximize command interpretation during
	// state recovery.
	Serialized logClass = iota

	// Recov is a minimal log format, stores just operation and operands following
	// the same kvstore message syntax, e.g.:
	//		"set-X-Y"
	//
	Recov

	// Verbose is a more complex record syntax, containing most fields of the command
	// struct, e.g.:
	//		"LogIndex | Operation | comments | IP"
	//
	Verbose

	// Stamped is the same as verbose class, but with a timestamp as sufix.
	Stamped
)

Variables

View Source
var DefaultConfig = &Config{
	Class:       Recov,
	Sync:        true,
	Batch:       10,
	PerstWrites: false,
}

DefaultConfig provides a Config with default values.

Functions

This section is empty.

Types

type Command

type Command struct {
	Id      uint64    `json:"id,omitempty"`
	Ip      string    `json:"ip,omitempty"`
	Op      Operation `json:"cmd,omitempty"`
	Comment string    `json:"comment,omitempty"`
}

A Command represents the records saved on log file.

type Config

type Config struct {
	Class logClass
	Batch uint32
	Sync  bool

	// Used in catastrophic fault models, where crash faults must be recoverable even if
	// all nodes presented in the consensus cluster are down. Always set to false in any
	// other cases, because this strong assumption greatly degradates performance.
	PerstWrites bool
}

Config provides any necessary configuration for journey.

type Log

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

Log struct for now just stores the chosen handler option

TODO: Instantiate alternative datastructures to optimize logging performance on command recording (less application overhead), or automatic command trimming from log file (reduced recovery time).

e.g.: DAG's for dependency tracking

func New

func New(cf *Config, logfile string) *Log

New function instantiates a new logger with default handler and configured by Config struct.

func (*Log) Close

func (l *Log) Close()

Close calls the handler deconstructor, that releases file descriptor and writes remaining buffered commands to stable storage.

func (*Log) Get

func (l *Log) Get(id uint64)

Get returns a specific command from log structure.

func (*Log) Put

func (l *Log) Put(command []byte) error

Put directly writes a serialized command into log.

func (*Log) PutFormat

func (l *Log) PutFormat(id uint64, op Operation, comment, ip, timeStamp string)

PutFormat constructs and writes a new command into the log.

func (*Log) PutJSON

func (l *Log) PutJSON(command []byte) error

PutJSON writes a JSON serialized command into log. Unmarshaling it for more verbosed writing.

func (*Log) PutPB

func (l *Log) PutPB(command []byte) error

PutPB writes a Protobuf serialized command into log. Unmarshaling it for more verbosed writing.

func (*Log) Reduce

func (l *Log) Reduce()

Reduce produces a compressed log for a faster state-recover.

type Logger

type Logger interface {

	// Append a protobuff serialized command into the log.
	Put(command []byte)

	// Append a JSON serialized command into the log.
	PutJSON(command []byte)

	// Classical insert, just append a new record on the file
	PutFormat(id int, op Operation, comment string, timeStamp string)

	// Returns a record with the corresponding id (not removing it)
	Get(id uint64)

	// Produces a compressed log for state-recover based on application semantics and dependency
	// tracking. The interpretation of the compressed log is equivalent to the original in terms
	// of safety, but quicker.
	Reduce()

	// Log desconstructor.
	Close()
}

Logger is the interface that log implements

type Operation

type Operation int

Operation indexes for command interpretation.

const (
	Get Operation = iota
	Set
	Delete
)

Different Operation types indexes, must modify it to accept different index based on an application semantics (readed from config file).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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