Documentation
¶
Index ¶
- Constants
- func FilePath(dir, name string) string
- type FileRangeManager
- type FileRangeQueue
- type Manager
- type ManagerConfig
- type Notification
- type Queue
- type Range
- func (r Range) Contains(other Range) bool
- func (r Range) EndOffset() uint64
- func (r Range) EndOffsetInt64() int64
- func (r Range) IsEndOffsetUnbounded() bool
- func (r Range) IsValid() bool
- func (r Range) MarshalText() ([]byte, error)
- func (r *Range) Set(start, end uint64)
- func (r *Range) SetInt64(start, end int64)
- func (r *Range) Shift(newEnd uint64)
- func (r *Range) ShiftInt64(newEnd int64)
- func (r Range) StartOffset() uint64
- func (r Range) StartOffsetInt64() int64
- func (r Range) String() string
- func (r *Range) UnmarshalText(text []byte) error
- type RangeList
- type RangeQueueBatcher
- type RangeTracker
Constants ¶
const (
// FileMode is the file permissions used for the state file.
FileMode = 0644
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FileRangeManager ¶
FileRangeManager is a state manager that handles the Range.
func NewFileRangeManager ¶
func NewFileRangeManager(cfg ManagerConfig) FileRangeManager
type FileRangeQueue ¶
type Manager ¶
type Manager[I, O any] interface { Queue[I] // Restore loads the previous state. Restore() (O, error) // Run starts the update/save loop. Run(ch Notification) }
Manager handles persistence of state.
type ManagerConfig ¶
type ManagerConfig struct {
// Name is the metadata that will be persisted in the last line of the state file.
Name string
// StateFileDir is the directory where the state file will be written to.
StateFileDir string
// StateFilePrefix is an optional prefix added to the filename. Can be used to group state files.
StateFilePrefix string
// QueueSize determines the size of the internal buffer for pending state changes.
QueueSize int
// SaveInterval determines how often the state is persisted.
SaveInterval time.Duration
// MaxPersistedItems is the maximum number of items to persist in the saved state. If zero or negative, the
// persistence is unbounded.
MaxPersistedItems int
}
ManagerConfig provides all options available to configure a Manager.
func (ManagerConfig) StateFilePath ¶
func (c ManagerConfig) StateFilePath() string
StateFilePath returns the full path to the state file.
type Notification ¶
type Notification struct {
Delete chan struct{}
Done chan struct{}
}
Notification contains channels used to stop the Manager run loop.
type Queue ¶
type Queue[T any] interface { ID() string // Enqueue the current state in memory. Enqueue(state T) }
Queue handles queued state changes.
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range represents a pair of offsets [start, end).
func (Range) EndOffsetInt64 ¶
EndOffsetInt64 is the int64 version of EndOffset. If end exceeds math.MaxInt64, returns 0.
func (Range) IsEndOffsetUnbounded ¶
IsEndOffsetUnbounded returns true if the end offset is the unbounded representation (i.e. math.MaxUint64).
func (Range) MarshalText ¶
MarshalText serializes the range into "start-end". If the end is unbounded, the format is "start-".
func (*Range) Set ¶
Set updates the start and end offsets of the range. If the new start is before the current start, it indicates file truncation and increments the sequence number.
func (*Range) SetInt64 ¶
SetInt64 is the int64 version of Set. If start or end are negative, the range is not updated.
func (*Range) Shift ¶
Shift moves the previous end to the start and sets the new end. If the new end is before the previous one, it resets the range to [0, newEnd) and increments the sequence number.
func (*Range) ShiftInt64 ¶
ShiftInt64 is the int64 version of Shift. If newEnd is negative, the range is not updated.
func (Range) StartOffset ¶
StartOffset returns the inclusive start of the range.
func (Range) StartOffsetInt64 ¶
StartOffsetInt64 is the int64 version of StartOffset. If start exceeds math.MaxInt64, returns 0.
func (Range) String ¶
String returns a string representation of the range "start-end". If the end is unbounded, returns "start-".
func (*Range) UnmarshalText ¶
UnmarshalText supports unmarshalling both the "start-end" and "start-" formats.
type RangeList ¶
type RangeList []Range
RangeList is a slice of Range values.
func InvertRanges ¶
InvertRanges returns all the gaps between the ranges in sorted order. Assumes that the passed in RangeList is sorted.
func (RangeList) Last ¶
Last returns the last Range in the slice. If empty, returns the zero-value Range.
func (RangeList) OnlyUseMaxOffset ¶
OnlyUseMaxOffset returns true if the RangeList is either empty or only contains a single Range that starts at 0. The intention of this is to maintain backwards compatibility with state files that only store the offset.
type RangeQueueBatcher ¶
type RangeQueueBatcher struct {
// contains filtered or unexported fields
}
RangeQueueBatcher is meant for merging continuous ranges before sending them to the FileRangeQueue.
func NewRangeQueueBatcher ¶
func NewRangeQueueBatcher(queue FileRangeQueue) *RangeQueueBatcher
func (*RangeQueueBatcher) Done ¶
func (b *RangeQueueBatcher) Done()
Done enqueues the built range (if valid) on the queue.
func (*RangeQueueBatcher) Merge ¶
func (b *RangeQueueBatcher) Merge(r Range)
Merge stores the min start and max end between the current state and the provided range.
type RangeTracker ¶
type RangeTracker interface {
encoding.TextMarshaler
encoding.TextUnmarshaler
// Insert a Range into the store. Returns false if the Range is already contained by another Range in the store or is
// invalid.
Insert(Range) bool
// Ranges returns all ranges in sorted order.
Ranges() RangeList
// Len returns the number of ranges in the store.
Len() int
// Clear all stored ranges.
Clear()
}
RangeTracker manages a collection of ranges. Handles insertion, retrieval, and serialization.