logger

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("partition not found")

ErrNotFound is returned when a partition could not be found

Functions

This section is empty.

Types

type CreateCall

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

CreateCall contains the arguments passed to a call to Create

type FileIndex added in v0.1.1

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

func NewFileIndex added in v0.1.1

func NewFileIndex(workDir string) *FileIndex

func (*FileIndex) GetIndex added in v0.1.1

func (idx *FileIndex) GetIndex(topic string, part uint64) (io.ReadWriteCloser, error)

func (*FileIndex) RemoveIndex added in v0.1.1

func (idx *FileIndex) RemoveIndex(topic string, part uint64) error

type GetCall

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

GetCall contains the arguments passed to a call to Get

type IndexManager added in v0.1.1

type IndexManager interface {
	// WriteIndex(topic string, part uint64, r io.Reader) (int64, error)
	GetIndex(topic string, part uint64) (io.ReadWriteCloser, error)
	RemoveIndex(topic string, part uint64) error
}

type LogRepairer

type LogRepairer interface {
	Truncate(part uint64, size int64) error
	Data(part uint64) (io.ReadCloser, error)
}

LogRepairer truncates corrupted data

type LogWriter

type LogWriter interface {
	io.WriteCloser
	Flush() error
	SetPartition(off uint64) error
}

LogWriter is the new log writer interface

type MockPartition

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

MockPartition can be used for testing purposes

func NewMockPartition

func NewMockPartition(conf *config.Config) *MockPartition

NewMockPartition returns a new instance of MockPartition

func (*MockPartition) Close

func (p *MockPartition) Close() error

Close implements Partitioner

func (*MockPartition) Offset

func (p *MockPartition) Offset() uint64

Offset implements Partitioner

func (*MockPartition) Read

func (p *MockPartition) Read(b []byte) (int, error)

func (*MockPartition) Reader

func (p *MockPartition) Reader() io.Reader

Reader implements Partitioner

func (*MockPartition) SetData

func (p *MockPartition) SetData(b []byte) *MockPartition

SetData sets the data on the partition

func (*MockPartition) SetOffset

func (p *MockPartition) SetOffset(off uint64) *MockPartition

SetOffset sets the offset on the partition

func (*MockPartition) SetReader

func (p *MockPartition) SetReader(r io.ReadCloser) *MockPartition

SetReader sets the reader the partition will return from Get

func (*MockPartition) Size

func (p *MockPartition) Size() int

Size implements Partitioner

type MockPartitions

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

MockPartitions can be used for testing purposes

func NewMockPartitions

func NewMockPartitions(conf *config.Config) *MockPartitions

NewMockPartitions returns an instance of MockPartitions

func (*MockPartitions) Create

func (m *MockPartitions) Create(offset uint64) (Partitioner, error)

Create implements PartitionManager

func (*MockPartitions) CreateCalls

func (m *MockPartitions) CreateCalls() []CreateCall

CreateCalls returns a list containing the arguments supplied to each previous Create call

func (*MockPartitions) FailCreateAfter

func (m *MockPartitions) FailCreateAfter(n int) *MockPartitions

FailCreateAfter returns an error after Create is called n times

func (*MockPartitions) FailGetAfter

func (m *MockPartitions) FailGetAfter(n int) *MockPartitions

FailGetAfter returns an error after Get is called n times

func (*MockPartitions) FailListAfter

func (m *MockPartitions) FailListAfter(n int) *MockPartitions

FailListAfter returns an error after List is called n times

func (*MockPartitions) FailRemoveAfter

func (m *MockPartitions) FailRemoveAfter(n int) *MockPartitions

FailRemoveAfter returns an error after Remove is called n times

func (*MockPartitions) Get

func (m *MockPartitions) Get(offset uint64, delta int, limit int) (Partitioner, error)

Get implements PartitionManager

func (*MockPartitions) GetCalls

func (m *MockPartitions) GetCalls() []GetCall

GetCalls returns a list containing the arguments supplied to each previous Get call

func (*MockPartitions) List

func (m *MockPartitions) List() ([]uint64, error)

List implements PartitionManager

func (*MockPartitions) ListCalls

func (m *MockPartitions) ListCalls() int

ListCalls returns the number of times List was called

func (*MockPartitions) Remove

func (m *MockPartitions) Remove(offset uint64) error

Remove implements PartitionManager

func (*MockPartitions) RemoveCalls

func (m *MockPartitions) RemoveCalls() []RemoveCall

RemoveCalls returns a list containing the arguments supplied to each previous Remove call

func (*MockPartitions) SetNextError

func (m *MockPartitions) SetNextError(err error) *MockPartitions

SetNextError sets an error to be returned from the next call

func (*MockPartitions) Shutdown

func (m *MockPartitions) Shutdown() error

Shutdown implements PartitionManager

func (*MockPartitions) Uncirculate

func (m *MockPartitions) Uncirculate(offset uint64) error

Uncirculate implements PartitionManager

type MockWriter

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

MockWriter can be used for testing purposes

func NewDiscardWriter

func NewDiscardWriter(conf *config.Config) *MockWriter

NewDiscardWriter returns a logger that discards all input

func NewMockWriter

func NewMockWriter(conf *config.Config) *MockWriter

NewMockWriter returns an instance of MockWriter

func (*MockWriter) Close

func (w *MockWriter) Close() error

Close implements LogWriter

func (*MockWriter) Flush

func (w *MockWriter) Flush() error

Flush implements LogWriter

func (*MockWriter) Partitions

func (w *MockWriter) Partitions() []*bytes.Buffer

Partitions returns a list of *bytes.Buffer-s containing the state of the log

func (*MockWriter) SetPartition

func (w *MockWriter) SetPartition(off uint64) error

SetPartition implements LogWriter

func (*MockWriter) SetWriter

func (w *MockWriter) SetWriter(wr io.Writer) *MockWriter

SetWriter sets the io.Writer on the MockWriter. The writer can also implement Flush.

func (*MockWriter) Write

func (w *MockWriter) Write(p []byte) (int, error)

type Partition

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

Partition implements Partitioner

func NewPartition

func NewPartition(conf *config.Config, offset uint64, size int) *Partition

NewPartition returns a new instance of Partition

func (*Partition) Close

func (p *Partition) Close() error

Close implements Partitioner

func (*Partition) Offset

func (p *Partition) Offset() uint64

Offset implements Partitioner

func (*Partition) Read

func (p *Partition) Read(b []byte) (int, error)

func (*Partition) Reader

func (p *Partition) Reader() io.Reader

Reader implements Partitioner. It can be used to access the underlying reader, mainly so the stdlib's sendfile can be used via TCPConn.ReadFrom(io.LimitRead(os.File))

func (*Partition) Reset

func (p *Partition) Reset()

Reset sets Partition to its initial params

func (*Partition) Size

func (p *Partition) Size() int

Size implements Partitioner

func (*Partition) String

func (p *Partition) String() string

type PartitionFile

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

PartitionFile wraps a LimitReader(*os.File) so it can be unwrapped by the socket and sendfile can be leveraged. PartitionFile is also involved in deletions. each partition on disk should have an associated reference count, and when it's slated for deletion, it should wait until all references have been closed before deleting the file from disk. It should move the file into a temp directory so subsequent requests for deleted offsets return not found errors.

type PartitionManager

type PartitionManager interface {
	// Remove deletes a partition. If the partition doesn't exist, return an
	// error.
	Remove(off uint64) error
	// Get returns an io.Reader representing the partition located at offset,
	// its start position seeked to delta, and limited to limit bytes.
	Get(offset uint64, delta, limit int) (Partitioner, error)
	// List returns a list of the currently available partition offsets
	List() ([]Partitioner, error)
}

PartitionManager gets, create, and otherwise manages partitions

type Partitioner

type Partitioner interface {
	io.ReadCloser
	Offset() uint64
	Size() int
	Reader() io.Reader
}

Partitioner wraps the log partition. in most usage, an *os.File

type Partitions

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

Partitions implements PartitionManager. It creates, removes, lists, and gets Partitions to be read from by server connections.

func NewPartitions

func NewPartitions(conf *config.Config, topic string) *Partitions

NewPartitions returns an instance of Partitions, which implements PartitionManager

func (*Partitions) Get

func (p *Partitions) Get(off uint64, delta, limit int) (Partitioner, error)

Get implements PartitionManager

func (*Partitions) Len

func (p *Partitions) Len() int

Len implements sort.Interface

func (*Partitions) Less

func (p *Partitions) Less(i, j int) bool

Less implements sort.Interface

func (*Partitions) List

func (p *Partitions) List() ([]Partitioner, error)

List implements PartitionManager

func (*Partitions) Remove

func (p *Partitions) Remove(off uint64) error

Remove implements PartitionManager

func (*Partitions) Setup

func (p *Partitions) Setup() error

Setup implements internal.LifecycleManager

func (*Partitions) Shutdown

func (p *Partitions) Shutdown() error

Shutdown implements internal.LifecycleManager

func (*Partitions) Swap

func (p *Partitions) Swap(i, j int)

Swap implements sort.Interface

type RemoveCall

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

RemoveCall contains the arguments passed to a call to Remove

type Repairer

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

Repairer implements LogRepairer using the filesystem

func NewRepairer

func NewRepairer(conf *config.Config, topic string) *Repairer

NewRepairer returns a new instance of *Repairer

func (*Repairer) Data

func (r *Repairer) Data(part uint64) (io.ReadCloser, error)

Data implements LogRepairer interface

func (*Repairer) Truncate

func (r *Repairer) Truncate(part uint64, size int64) error

Truncate implements LogRepairer interface

type TopicManager

type TopicManager interface {
	List() ([]string, error)
	Create(topic string) error
	Remove(topic string) error
}

TopicManager deals with the listing of topics, which typically will exist as directories in the filesystem. TODO it should probably create/remove them as well

type Topics

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

Topics implements TopicManager

func NewTopics

func NewTopics(conf *config.Config) *Topics

NewTopics returns a new instance of Topics

func (*Topics) Create

func (t *Topics) Create(name string) error

Create implements TopicManager

func (*Topics) List

func (t *Topics) List() ([]string, error)

List implements TopicManager

func (*Topics) Remove

func (t *Topics) Remove(name string) error

Remove implements TopicManager

func (*Topics) Setup

func (t *Topics) Setup() error

Setup implements internal.LifecycleManager

func (*Topics) Shutdown

func (t *Topics) Shutdown() error

Shutdown implements internal.LifecycleManager

type Writer

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

Writer writes to the log

func NewWriter

func NewWriter(conf *config.Config, topic string) *Writer

NewWriter returns a new instance of Writer

func (*Writer) Close

func (w *Writer) Close() error

Close implements LogWriter interface

func (*Writer) Flush

func (w *Writer) Flush() error

Flush implements LogWriter interface

func (*Writer) SetPartition

func (w *Writer) SetPartition(off uint64) error

SetPartition implements LogWriter interface

func (*Writer) Setup

func (w *Writer) Setup() error

Setup implements internal.LifecycleManager

func (*Writer) Shutdown

func (w *Writer) Shutdown() error

Shutdown implements LifecycleManager interface

func (*Writer) Write

func (w *Writer) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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