transactor

package
v0.0.0-...-f714a01 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

The transactor package contains the APIs for writing facts to storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCanceled       = errors.New("transactor: canceled")
	ErrNoID           = errors.New("transactor: could not create tx id")
	ErrCommitConflict = errors.New("transactor: commit conflict")
	ErrReceiveTimeout = errors.New("transactor: receive timeout")
	ErrNoDomain       = errors.New("transactor: no fact domain")
	ErrCouldNotRoute  = errors.New("transactor: could not route")
)
View Source
var DefaultOptions = Options{
	ReceiveWait:     time.Minute,
	BufferSize:      1000,
	AllowDuplicates: false,
}

DefaultOptions hold the default options for a transaction.

View Source
var ErrCommitted = errors.New("transactor: segment already committed")

Functions

This section is empty.

Types

type Info

type Info struct {
	ID        uint64
	StartTime time.Time
	EndTime   time.Time
	Duration  time.Duration
	Domains   []*Stats
	Bytes     int
	Count     int
}

Info holds information about a transaction.

type Options

type Options struct {
	// Default domain for unbounded facts. If this is ommitted and a fact
	// does not specify a domain, an error will occur.
	DefaultDomain string

	// Duration of time wait to receive facts before timing out the transaction.
	ReceiveWait time.Duration

	// Defines the buffer size of the channel that receives facts for processing.
	// Increasing this may increase throughput at the expense of memory.
	BufferSize int

	// If true, a zeroed fact time will be set to the transaction start time. This
	// is useful for facts that are considered "new in the world".
	SetDefaultTime bool

	// If true, duplicates will facts will be written to storage.
	AllowDuplicates bool
}

Options are used to supply default values as well as alter the behavior of a running transaction.

type Pipeline

type Pipeline struct {
	Domain string
	// contains filtered or unexported fields
}

A Pipeline does the actual work of processing and writing facts to storage.

func (*Pipeline) Abort

func (p *Pipeline) Abort(tx storage.Tx) error

Abort aborts the pipeline and deletes any data written to storage.

func (*Pipeline) Commit

func (p *Pipeline) Commit(tx storage.Tx) error

Commit takes a storage transaction and writes any headers or indexes to make the transacted facts visible. A storage transaction is passed in to enable the writes to occur atomically which ensures consistency of the transacted facts.

func (*Pipeline) Handle

func (p *Pipeline) Handle(fact *origins.Fact) error

Handle takes a fact and returns an error if the fact cannot be handled.

func (*Pipeline) Init

func (p *Pipeline) Init(tx *Transaction) error

Init initializes the pipeline for the transaction.

func (*Pipeline) Stats

func (p *Pipeline) Stats() *Stats

Stats returns the the stats for the pipeline.

func (*Pipeline) String

func (p *Pipeline) String() string

type Segment

type Segment struct {
	// Embed DAL segment for simpler access.
	dal.Segment

	Engine storage.Engine
	// contains filtered or unexported fields
}

Segment represents a transacted set of facts. Segments are broken up into fixed-sized blocks to facilitate flushing the data to disk during a long-running transaction. Each segment maintains the basis

func NewSegment

func NewSegment(engine storage.Engine, domain string, tx uint64) *Segment

NewSegment initializes a new segment for writing.

func (*Segment) Abort

func (s *Segment) Abort(tx storage.Tx) error

Abort aborts the segment and attempts to delete all data that has been written to storage.

func (*Segment) Commit

func (s *Segment) Commit(tx storage.Tx) error

Commit writes the last partial block.

func (*Segment) Write

func (s *Segment) Write(f *origins.Fact) error

Write a fact to the current block.

type Stats

type Stats struct {
	Domain string

	// Total number of blocks.
	Blocks int

	// Total of number bytes.
	Bytes int

	// Total number of facts.
	Count int
}

Stats contains information about a pipeline.

type Transaction

type Transaction struct {
	// Unique ID for the transaction.
	ID uint64

	// The start and end time of transaction.
	StartTime time.Time
	EndTime   time.Time

	// Error during the transaction and commit error.
	Error       error
	CommitError error

	Engine storage.Engine
	// contains filtered or unexported fields
}

Transaction is the entrypoint for transacting facts.

func New

func New(engine storage.Engine, options Options) (*Transaction, error)

New initializes and returns a transaction for passed storage engine. The options are used to change the behavior of the transaction itself.

func (*Transaction) Cancel

func (tx *Transaction) Cancel() error

Cancel cancels the transaction.

func (*Transaction) Commit

func (tx *Transaction) Commit() error

Commit commits the transaction. All head of all affected logs will be atomically updated to make the transacted data visible to clients.

func (*Transaction) Info

func (tx *Transaction) Info() *Info

Stats returns the stats of the transaction which aggregates them from the pipelines.

func (*Transaction) Write

func (tx *Transaction) Write(fact *origins.Fact) error

Write writes a fact to the transaction.

Jump to

Keyboard shortcuts

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