timemachine

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLogRecords = errors.New("process has no records")

ErrNoRecords is an error returned when no log records could be found for a given process id.

Functions

func HashProfile

func HashProfile(processID format.UUID, profileType string, timeRange TimeRange) format.Hash

Types

type LogReader

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

LogReader instances allow programs to read the content of a record log.

func NewLogReader

func NewLogReader(input io.ReadSeeker, manifest *format.Manifest) *LogReader

NewLogReader construct a new log reader consuming input from the given io.Reader.

func (*LogReader) Close

func (r *LogReader) Close() error

Close closes the log reader.

func (*LogReader) ReadRecordBatch

func (r *LogReader) ReadRecordBatch() (*RecordBatch, error)

ReadRecordBatch reads the next record batch.

The RecordBatch is only valid until the next call to ReadRecordBatch or Seek.

func (*LogReader) Seek

func (r *LogReader) Seek(offset int64, whence int) (int64, error)

Seek positions r on the first record batch which contains the given record offset.

The whence value defines how to interpret the offset (see io.Seeker).

type LogRecordReader

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

LogRecordReader wraps a LogReader to help with reading individual records in order.

The reader exposes an iterator like interface. Callers should call Next to determine whether another record is available. If so, it can be retrieved via the Record method.

func NewLogRecordReader

func NewLogRecordReader(r *LogReader) *LogRecordReader

NewLogRecordReader creates a log record iterator.

func (*LogRecordReader) Read

func (r *LogRecordReader) Read(records []Record) (int, error)

Read reads records from r.

The record values share memory buffer with the reader, they remain valid until the next call to Read or Seek.

func (*LogRecordReader) Seek

func (r *LogRecordReader) Seek(offset int64, whence int) (int64, error)

Seek positions the reader on the record at the given offset.

The whence value defines how to interpret the offset (see io.Seeker).

type LogRecordWriter

type LogRecordWriter struct {
	*LogWriter
	// contains filtered or unexported fields
}

LogRecordWriter wraps a LogWriter to help with write batching.

A WriteRecord method is added that buffers records in a batch up to a configurable size before flushing the batch to the log.

func NewLogRecordWriter

func NewLogRecordWriter(w *LogWriter, batchSize int, compression Compression) *LogRecordWriter

NewLogRecordWriter creates a LogRecordWriter.

func (*LogRecordWriter) Flush

func (w *LogRecordWriter) Flush() error

Flush flushes the pending batch.

func (*LogRecordWriter) WriteRecord

func (w *LogRecordWriter) WriteRecord(record *RecordBuilder) error

WriteRecord buffers a Record in a batch and then flushes the batch once it reaches the configured maximum size.

The record is consumed immediately and can be reused safely when the call returns.

type LogWriter

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

LogWriter supports writing log segments to an io.Writer.

func NewLogWriter

func NewLogWriter(output io.Writer) *LogWriter

NewLogWriter constructs a new log writer which produces output to the given io.Writer.

func (*LogWriter) Reset

func (w *LogWriter) Reset(output io.Writer)

Reset resets the state of the log writer to produce to output to the given io.Writer.

func (*LogWriter) WriteRecordBatch

func (w *LogWriter) WriteRecordBatch(batch *RecordBatchBuilder) error

WriteRecordBatch writes a record batch to the log. The method returns a non-nil error if the write failed.

If the error occurred while writing to the underlying io.Writer, the writer is broken and will always error on future calls to WriteRecordBatch until the program calls Reset.

type Record

type Record struct {
	Offset       int64
	Time         time.Time
	FunctionID   int
	FunctionCall []byte
}

Record is a read-only record from the log.

type RecordBatch

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

RecordBatch is a read-only batch of records read from a log segment.

The records themselves are compressed and stored separately. To support use cases where the user may want to read batch metadata in order to skip the processing of records, the record batch is structured such that records are read and decompressed lazily.

func (*RecordBatch) CompressedSize

func (b *RecordBatch) CompressedSize() int64

CompressedSize returns the size of the record batch data section in the log segment.

func (*RecordBatch) Compression

func (b *RecordBatch) Compression() Compression

Compression returns the compression algorithm used to encode the record batch data section.

func (*RecordBatch) FirstOffset

func (b *RecordBatch) FirstOffset() int64

FirstOffset returns the logical offset of the first record in the batch.

func (*RecordBatch) FirstTimestamp

func (b *RecordBatch) FirstTimestamp() time.Time

FirstTimestamp returns the time of the first record in the batch.

func (*RecordBatch) LastTimestamp

func (b *RecordBatch) LastTimestamp() time.Time

LastTimestamp returns the time of the last record in the batch.

func (*RecordBatch) NextOffset

func (b *RecordBatch) NextOffset() int64

NextOffset returns the offset of the first record after this batch.

func (*RecordBatch) NumRecords

func (b *RecordBatch) NumRecords() int

NumRecords returns the number of records in the batch.

func (*RecordBatch) Read

func (b *RecordBatch) Read(records []Record) (int, error)

Read reads records from the batch.

The record values share memory buffers with the record batch, they remain valid until the next call to ReadRecordBatch on the parent LogReader.

func (*RecordBatch) Reset

func (b *RecordBatch) Reset(startTime time.Time, buf []byte, reader io.Reader)

Reset resets the record batch.

func (*RecordBatch) UncompressedSize

func (b *RecordBatch) UncompressedSize() int64

UncompressedSize returns the size of the record batch data section after being uncompressed.

type RecordBatchBuilder

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

RecordBatchBuilder is a builder for record batches.

func (*RecordBatchBuilder) AddRecord

func (b *RecordBatchBuilder) AddRecord(record *RecordBuilder)

AddRecord adds a record to the batch.

The record is consumed immediately and can be reused safely when the call returns.

func (*RecordBatchBuilder) Bytes

func (b *RecordBatchBuilder) Bytes() []byte

Bytes returns the serialized representation of the record batch.

Since the batch is made up of two components – the batch metadata and then the compressed records – additional buffering is required here to merge the two together. If efficiency is required, Write should be used instead.

func (*RecordBatchBuilder) Reset

func (b *RecordBatchBuilder) Reset(compression Compression, firstOffset int64)

Reset resets the builder.

func (*RecordBatchBuilder) Write

func (b *RecordBatchBuilder) Write(w io.Writer) (int, error)

Write writes the serialized representation of the record batch to the specified writer.

type RecordBuilder

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

RecordBuilder is a builder for records.

func (*RecordBuilder) Bytes

func (b *RecordBuilder) Bytes() []byte

Bytes returns the serialized representation of the record.

func (*RecordBuilder) Reset

func (b *RecordBuilder) Reset(startTime time.Time)

Reset resets the builder.

func (*RecordBuilder) SetFunctionCall

func (b *RecordBuilder) SetFunctionCall(functionCall []byte)

SetFunctionCall sets the function call.

The provided slice is retained until Bytes() is called and the record is serialized.

func (*RecordBuilder) SetFunctionID

func (b *RecordBuilder) SetFunctionID(id int)

SetFunctionID sets the function ID.

func (*RecordBuilder) SetTimestamp

func (b *RecordBuilder) SetTimestamp(t time.Time)

SetTimestamp sets the timestamp.

func (*RecordBuilder) Write

func (b *RecordBuilder) Write(w io.Writer) (int, error)

Write writes the serialized representation of the record to the specified writer.

type Registry

type Registry struct {
	// The object store that the registry uses to load and store data.
	Store object.Store
	// List of tags that are added to every object created by this registry.
	CreateTags []object.Tag
	// List of tags that are added to every query selecting objects from this
	// registry.
	SelectTags []object.Tag
}

func (*Registry) CreateConfig

func (reg *Registry) CreateConfig(ctx context.Context, config *format.Config, tags ...object.Tag) (*format.Descriptor, error)

func (*Registry) CreateLogManifest

func (reg *Registry) CreateLogManifest(ctx context.Context, processID format.UUID, manifest *format.Manifest) error

func (*Registry) CreateLogSegment

func (reg *Registry) CreateLogSegment(ctx context.Context, processID format.UUID, segmentNumber int) (io.WriteCloser, error)

func (*Registry) CreateModule

func (reg *Registry) CreateModule(ctx context.Context, module *format.Module, tags ...object.Tag) (*format.Descriptor, error)

func (*Registry) CreateProcess

func (reg *Registry) CreateProcess(ctx context.Context, process *format.Process, tags ...object.Tag) (*format.Descriptor, error)

func (*Registry) CreateProfile

func (reg *Registry) CreateProfile(ctx context.Context, processID format.UUID, profileType string, prof *profile.Profile) (*format.Descriptor, error)

func (*Registry) CreateRuntime

func (reg *Registry) CreateRuntime(ctx context.Context, runtime *format.Runtime, tags ...object.Tag) (*format.Descriptor, error)

func (*Registry) ListConfigs

func (reg *Registry) ListConfigs(ctx context.Context, timeRange TimeRange, tags ...object.Tag) stream.ReadCloser[*format.Descriptor]

func (*Registry) ListLogManifests

func (reg *Registry) ListLogManifests(ctx context.Context) stream.ReadCloser[*format.Manifest]

func (*Registry) ListLogSegments

func (reg *Registry) ListLogSegments(ctx context.Context, processID format.UUID) stream.ReadCloser[format.LogSegment]

func (*Registry) ListModules

func (reg *Registry) ListModules(ctx context.Context, timeRange TimeRange, tags ...object.Tag) stream.ReadCloser[*format.Descriptor]

func (*Registry) ListProcesses

func (reg *Registry) ListProcesses(ctx context.Context, timeRange TimeRange, tags ...object.Tag) stream.ReadCloser[*format.Descriptor]

func (*Registry) ListRecords

func (reg *Registry) ListRecords(ctx context.Context, processID format.UUID, timeRange TimeRange) stream.ReadCloser[Record]

func (*Registry) ListResources

func (reg *Registry) ListResources(ctx context.Context, mediaType format.MediaType, timeRange TimeRange, tags ...object.Tag) stream.ReadCloser[*format.Descriptor]

func (*Registry) ListRuntimes

func (reg *Registry) ListRuntimes(ctx context.Context, timeRange TimeRange, tags ...object.Tag) stream.ReadCloser[*format.Descriptor]

func (*Registry) LookupConfig

func (reg *Registry) LookupConfig(ctx context.Context, hash format.Hash) (*format.Config, error)

func (*Registry) LookupDescriptor

func (reg *Registry) LookupDescriptor(ctx context.Context, hash format.Hash) (*format.Descriptor, error)

func (*Registry) LookupLogManifest

func (reg *Registry) LookupLogManifest(ctx context.Context, processID format.UUID) (*format.Manifest, error)

func (*Registry) LookupModule

func (reg *Registry) LookupModule(ctx context.Context, hash format.Hash) (*format.Module, error)

func (*Registry) LookupProcess

func (reg *Registry) LookupProcess(ctx context.Context, hash format.Hash) (*format.Process, error)

func (*Registry) LookupProfile

func (reg *Registry) LookupProfile(ctx context.Context, hash format.Hash) (*profile.Profile, error)

func (*Registry) LookupRecord

func (reg *Registry) LookupRecord(ctx context.Context, process *format.Manifest, offset int64) (Record, error)

func (*Registry) LookupResource

func (reg *Registry) LookupResource(ctx context.Context, hash format.Hash) (io.ReadSeekCloser, error)

func (*Registry) LookupRuntime

func (reg *Registry) LookupRuntime(ctx context.Context, hash format.Hash) (*format.Runtime, error)

func (*Registry) ReadLogSegment

func (reg *Registry) ReadLogSegment(ctx context.Context, processID format.UUID, segmentNumber int) (io.ReadSeekCloser, error)

type TimeRange

type TimeRange struct {
	Start, End time.Time
}

func Between

func Between(then, now time.Time) TimeRange

func Since

func Since(then time.Time) TimeRange

func Until

func Until(now time.Time) TimeRange

func (TimeRange) Duration

func (tr TimeRange) Duration() time.Duration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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