buffer

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	Add(context.Context, *entry.Entry) error
	Read([]*entry.Entry) (FlushFunc, int, error)
	ReadWait(context.Context, []*entry.Entry) (FlushFunc, int, error)
	Close() error
}

type BufferBuilder added in v0.10.0

type BufferBuilder interface {
	Build(context operator.BuildContext, pluginID string) (Buffer, error)
}

type Config

type Config struct {
	BufferBuilder
}

func NewConfig

func NewConfig() Config

func (*Config) UnmarshalJSON added in v0.10.0

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

func (*Config) UnmarshalYAML added in v0.10.0

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

type DiskBuffer added in v0.10.0

type DiskBuffer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

DiskBuffer is a buffer for storing entries on disk until they are flushed to their final destination.

func NewDiskBuffer added in v0.10.0

func NewDiskBuffer(maxDiskSize int) *DiskBuffer

NewDiskBuffer creates a new DiskBuffer

func (*DiskBuffer) Add added in v0.10.0

func (d *DiskBuffer) Add(ctx context.Context, newEntry *entry.Entry) error

Add adds an entry to the buffer, blocking until it is either added or the context is cancelled.

func (*DiskBuffer) Close added in v0.10.0

func (d *DiskBuffer) Close() error

Close flushes the current metadata to disk, then closes the underlying files

func (*DiskBuffer) Compact added in v0.10.0

func (d *DiskBuffer) Compact() error

Compact removes all flushed entries from disk

func (*DiskBuffer) Open added in v0.10.0

func (d *DiskBuffer) Open(path string, sync bool) error

Open opens the disk buffer files from a database directory

func (*DiskBuffer) Read added in v0.10.0

func (d *DiskBuffer) Read(dst []*entry.Entry) (f FlushFunc, i int, err error)

Read copies entries from the disk into the destination buffer. It returns a function that, when called, marks the entries as flushed, the number of entries read, and an error.

func (*DiskBuffer) ReadWait added in v0.10.0

func (d *DiskBuffer) ReadWait(ctx context.Context, dst []*entry.Entry) (FlushFunc, int, error)

ReadWait reads entries from the buffer, waiting until either there are enough entries in the buffer to fill dst or the context is cancelled. This amortizes the cost of reading from the disk. It returns a function that, when called, marks the read entries as flushed, the number of entries read, and an error.

type DiskBufferConfig added in v0.10.0

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

	// MaxSize is the maximum size in bytes of the data file on disk
	MaxSize int `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"`
}

DiskBufferConfig is a configuration struct for a DiskBuffer

func NewDiskBufferConfig added in v0.10.0

func NewDiskBufferConfig() *DiskBufferConfig

NewDiskBufferConfig creates a new default disk buffer config

func (DiskBufferConfig) Build added in v0.10.0

func (c DiskBufferConfig) Build(context operator.BuildContext, _ string) (Buffer, error)

Build creates a new Buffer from a DiskBufferConfig

type FlushFunc added in v0.10.0

type FlushFunc func() error

type MemoryBuffer

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

MemoryBuffer is a buffer that holds all entries in memory until Close() is called, at which point it saves the entries into a database. It provides no guarantees about lost entries if shut down uncleanly.

func (*MemoryBuffer) Add added in v0.10.0

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

Add inserts an entry into the memory database, blocking until there is space

func (*MemoryBuffer) Close added in v0.10.0

func (m *MemoryBuffer) Close() error

Close closes the memory buffer, saving all entries currently in the memory buffer to the agent's database.

func (*MemoryBuffer) Read added in v0.10.0

func (m *MemoryBuffer) Read(dst []*entry.Entry) (FlushFunc, int, error)

Read reads entries until either there are no entries left in the buffer or the destination slice is full. The returned function must be called once the entries are flushed to remove them from the memory buffer.

func (*MemoryBuffer) ReadWait added in v0.10.0

func (m *MemoryBuffer) ReadWait(ctx context.Context, dst []*entry.Entry) (FlushFunc, int, error)

ReadWait reads entries until either the destination slice is full, or the context passed to it is cancelled. The returned function must be called once the entries are flushed to remove them from the memory buffer

type MemoryBufferConfig added in v0.10.0

type MemoryBufferConfig struct {
	Type       string `json:"type" yaml:"type"`
	MaxEntries int    `json:"max_entries" yaml:"max_entries"`
}

MemoryBufferConfig holds the configuration for a memory buffer

func NewMemoryBufferConfig added in v0.10.0

func NewMemoryBufferConfig() *MemoryBufferConfig

NewMemoryBufferConfig creates a new default MemoryBufferConfig

func (MemoryBufferConfig) Build added in v0.10.0

func (c MemoryBufferConfig) Build(context operator.BuildContext, pluginID string) (Buffer, error)

Build builds a MemoryBufferConfig into a Buffer, loading any entries that were previously unflushed back into memory

type Metadata added in v0.10.0

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

Metadata is a representation of the on-disk metadata file. It contains information about the layout, location, and flushed status of entries stored in the data file

func OpenMetadata added in v0.10.0

func OpenMetadata(path string, sync bool) (*Metadata, error)

OpenMetadata opens and parses the metadata

func (*Metadata) Close added in v0.10.0

func (m *Metadata) Close() error

Close syncs metadata to disk and closes the underlying file descriptor

func (*Metadata) MarshalBinary added in v0.10.0

func (m *Metadata) MarshalBinary(wr io.Writer) (err error)

MarshalBinary marshals a metadata struct to a binary stream

func (*Metadata) Sync added in v0.10.0

func (m *Metadata) Sync() error

Sync persists the metadata to disk

func (*Metadata) UnmarshalBinary added in v0.10.0

func (m *Metadata) UnmarshalBinary(r io.Reader) error

UnmarshalBinary unmarshals metadata from a binary stream (usually a file)

Jump to

Keyboard shortcuts

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