buffer

package
v2.0.0-...-675b67f Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBufferClosed = errors.New("buffer is closed")

ErrBufferClosed is an error to indicate an operation was attempt on a buffer after it was closed

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	// Add adds an entry onto the buffer.
	// Is a blocking call if the buffer is full
	Add(context.Context, *entry.Entry) error

	// Read reads from the buffer.
	// Read can be a blocking call depending on the underlying implementation.
	Read(context.Context) ([]*entry.Entry, error)

	// Close runs cleanup code for buffer and may return entries left in the buffer
	// depending on the underlying implementation
	Close() ([]*entry.Entry, error)
}

Buffer is an interface for an entry buffer

type Builder

type Builder interface {
	Build() (Buffer, error)
}

Builder builds a Buffer given build context

type Config

type Config struct {
	Builder
}

Config is a struct that wraps a Builder

func NewConfig

func NewConfig() Config

NewConfig returns a default Config

func (Config) MarshalJSON

func (bc Config) MarshalJSON() ([]byte, error)

func (Config) MarshalYAML

func (bc Config) MarshalYAML() (interface{}, error)

func (*Config) UnmarshalJSON

func (bc *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON

func (*Config) UnmarshalYAML

func (bc *Config) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML unmarshals YAML

type DiskBuffer

type DiskBuffer struct {
}

TODO add comment

func (*DiskBuffer) Add

func (m *DiskBuffer) Add(ctx context.Context, e *entry.Entry) error

Add adds an entry onto the buffer. Is a blocking call if the buffer is full

func (*DiskBuffer) Close

func (m *DiskBuffer) Close() ([]*entry.Entry, error)

Close runs cleanup code for buffer

func (*DiskBuffer) Read

func (m *DiskBuffer) Read(ctx context.Context) ([]*entry.Entry, error)

Read reads from the buffer. Read will block until the there are MaxChunkSize entries or we have block as long as MachChunkDelay.

type DiskBufferConfig

type DiskBufferConfig struct {
	Type string `json:"type" yaml:"type"`

	// MaxSize is the maximum size in bytes of the data file on disk
	MaxSize helper.ByteSize `json:"max_size" yaml:"max_size"`

	// Path is a path to a directory which contains the data and metadata files
	Path string `json:"path" yaml:"path"`

	// Sync indicates whether to open the files with O_SYNC. If this is set to false,
	// in cases like power failures or unclean shutdowns, logs may be lost or the
	// database may become corrupted.
	Sync bool `json:"sync" yaml:"sync"`

	MaxChunkDelay helper.Duration `json:"max_delay"   yaml:"max_delay"`
	MaxChunkSize  uint            `json:"max_chunk_size" yaml:"max_chunk_size"`
}

DiskBufferConfig is a configuration struct for a DiskBuffer

func NewDiskBufferConfig

func NewDiskBufferConfig() *DiskBufferConfig

NewDiskBufferConfig creates a new default disk buffer config

func (DiskBufferConfig) Build

func (c DiskBufferConfig) Build() (Buffer, error)

Build creates a new Buffer from a DiskBufferConfig

type MemoryBuffer

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

MemoryBuffer is a buffer that holds all entries in memory until Close() is called.

func (*MemoryBuffer) Add

func (m *MemoryBuffer) Add(ctx context.Context, e *entry.Entry) error

Add adds an entry onto the buffer. Is a blocking call if the buffer is full

func (*MemoryBuffer) Close

func (m *MemoryBuffer) Close() ([]*entry.Entry, error)

Close runs cleanup code for buffer

func (*MemoryBuffer) Read

func (m *MemoryBuffer) Read(ctx context.Context) ([]*entry.Entry, error)

Read reads from the buffer. Read will block until the there are MaxChunkSize entries or we have block as long as MachChunkDelay.

type MemoryBufferConfig

type MemoryBufferConfig struct {
	Type          string          `json:"type"        yaml:"type"`
	MaxEntries    int             `json:"max_entries" yaml:"max_entries"`
	MaxChunkDelay helper.Duration `json:"max_delay"   yaml:"max_delay"`
	MaxChunkSize  uint            `json:"max_chunk_size" yaml:"max_chunk_size"`
}

MemoryBufferConfig holds the configuration for a memory buffer

func NewMemoryBufferConfig

func NewMemoryBufferConfig() *MemoryBufferConfig

NewMemoryBufferConfig creates a new default MemoryBufferConfig

func (MemoryBufferConfig) Build

func (c MemoryBufferConfig) Build() (Buffer, error)

Build builds a MemoryBufferConfig into a Buffer

Jump to

Keyboard shortcuts

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