Documentation
¶
Index ¶
Constants ¶
const ( Byte MemorySize = 1 Kilobyte = Byte * 1024 Megabyte = Kilobyte * 1024 Gigabyte = Megabyte * 1024 Terabyte = Gigabyte * 1024 )
Variables ¶
var ( ErrNoEncoder = errors.New("no encoder provided") ErrNoDecoder = errors.New("no decoder provided") ErrNoWriter = errors.New("no writer provided") ErrNoReader = errors.New("no reader provided") ErrNoQueue = errors.New("no destination queue provided") ErrTimeout = errors.New("operation too long") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
/*
Common params.
*/
// Write version. Must be changed at any change of Encoder param.
Version Version
// Metrics writer handler.
MetricsWriter MetricsWriter
// Logger handler.
Logger queue.Logger
/*
Queue params.
Params of this group will ignore by Restorer.
*/
// Max queue capacity in bytes.
// When dumped data will reach size, queue will flush the data.
// Mandatory param.
Capacity MemorySize
// Wait duration until flush the data.
// After first incoming item will start the timer to flush the data when timer reach.
// If this param omit defaultFlushInterval (30 seconds) will use by default.
FlushInterval time.Duration
// Encoder helper to convert item to bytes.
// Mandatory param.
Encoder Encoder
// Writer helper to dump data to various destinations.
// Mandatory param.
Writer Writer
/*
Restorer params.
Params of this group will ignore by Queue.
*/
// Interval between restore attempts.
// If this param omit defaultWaitInterval (1 second) will use by default.
CheckInterval time.Duration
// Wait duration if queue rate exceeds AllowRate.
// If this param omit CheckInterval will use instead.
PostponeInterval time.Duration
// Queue rate that allows restore.
// If this param omit defaultAllowRate (95%) will use by default.
AllowRate float32
// Helper to achieve data from dump.
// Mandatory param.
Reader Reader
// Decoder helper to convert bytes to item.
// Mandatory param.
Decoder Decoder
// Destination queue to restore dump.
// Mandatory param.
Queue queue.Interface
}
type Decoder ¶
Decoder is the interface that wraps the basic Write Decode.
Decode decodes value from p. It returns decoded value and any error encountered.
type DummyMetrics ¶
type DummyMetrics struct{}
func (DummyMetrics) Dump ¶
func (DummyMetrics) Dump(_ int)
func (DummyMetrics) Fail ¶
func (DummyMetrics) Fail(_ string)
func (DummyMetrics) Flush ¶
func (DummyMetrics) Flush(_ string, _ int)
func (DummyMetrics) Restore ¶
func (DummyMetrics) Restore(_ int)
type Encoder ¶
Encoder is the interface that wraps the basic Encode method.
Encode encodes x to dst. It returns dst and any error encountered.
type MemorySize ¶
type MemorySize uint64
type MetricsWriter ¶
type MetricsWriter interface {
// Dump registers how many bytes dumped to the queue.
Dump(size int)
// Flush registers how many bytes flushed to the queue and what reason is.
Flush(reason string, size int)
// Restore registers how many bytes restored to the queue.
Restore(size int)
// Fail registers fail reason for given queue.
Fail(reason string)
}
MetricsWriter is the interface that wraps the basic metrics methods.
type Queue ¶
Queue represents dumping queue.
type Reader ¶
Reader is the interface that wraps the basic Read method.
Read reads next encoded entry from the dump to dst. It returns version, dst contains entry and any error encountered.
type Restorer ¶
type Restorer struct {
Err error
// contains filtered or unexported fields
}
Restorer represents dump restore handler. Restorer may be scheduled (see Config.CheckInterval).
func NewRestorer ¶
NewRestorer makes new restorer instance and initialize it according config params.
func (*Restorer) CloseWithTimeout ¶
CloseWithTimeout stops the queue with timeout.
func (*Restorer) ForceClose ¶
ForceClose immediately stops the queue.
type Version ¶
type Version uint64
Version represent simple version container.
func NewVersion ¶
NewVersion composes version from given parts.
func ParseVersion ¶
ParseVersion makes new version from source string.
See version_test.go for examples.
type Writer ¶
type Writer interface {
// Write returns the number of bytes written from p (0 <= n <= len(p) + 8) and any error encountered.
Write(ver Version, p []byte) (int, error)
// Size returns size in bytes of collected data.
Size() MemorySize
// Flush flushes collected data.
Flush() error
}
Writer is the interface that wraps the basic Write method.