bucket

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package bucket implements a rolling bucket system.

Index

Constants

View Source
const (
	// QueueName is identity of the queue.
	QueueName = "block-queue-cleanup"
)

Variables

View Source
var (
	// ErrInvalidParameter denotes input parameters are invalid.
	ErrInvalidParameter = errors.New("parameters are invalid")
	// ErrNoMoreBucket denotes the bucket volume reaches the limitation.
	ErrNoMoreBucket = errors.New("no more buckets")
)
View Source
var (

	// DummyReporter is a special Reporter to avoid nil errors.
	DummyReporter = &dummyReporter{}
)

Functions

This section is empty.

Types

type Channel

type Channel chan Status

Channel reports the status of a Reporter.

type Controller

type Controller interface {
	Current() (Reporter, error)
	Next() (Reporter, error)
	OnMove(prev, next Reporter)
}

Controller defines the provider of a Reporter.

type EvictFn

type EvictFn func(ctx context.Context, id interface{}) error

EvictFn is a closure executed on evicting an item.

type OnAddRecentFn added in v0.2.0

type OnAddRecentFn func() error

OnAddRecentFn is a notifier on adding an item into the recent queue.

type Queue

type Queue interface {
	Touch(id fmt.Stringer) bool
	Push(ctx context.Context, id fmt.Stringer, fn OnAddRecentFn) error
	Remove(id fmt.Stringer)
	Len() int
	Volume() int
	All() []fmt.Stringer
}

Queue is a LRU queue.

func NewQueue

func NewQueue(l *logger.Logger, size int, maxSize int, scheduler *timestamp.Scheduler, evictFn EvictFn) (Queue, error)

NewQueue return a Queue for blocks eviction.

type Reporter

type Reporter interface {
	// TODO: refactor Report to return a status. It's too complicated to return a channel
	Report() (Channel, error)
	String() string
}

Reporter allows reporting status to its supervisor.

func NewTimeBasedReporter

func NewTimeBasedReporter(name string, timeRange timestamp.TimeRange, clock timestamp.Clock, scheduler *timestamp.Scheduler) Reporter

NewTimeBasedReporter returns a Reporter which sends report based on time.

type Status

type Status struct {
	Capacity int
	Volume   int
}

Status is a sample of the Reporter's status.

type Strategy

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

Strategy controls Reporters with Controller's help.

func NewStrategy

func NewStrategy(ctrl Controller, options ...StrategyOptions) (*Strategy, error)

NewStrategy returns a Strategy.

func (*Strategy) Close

func (s *Strategy) Close()

Close the Strategy running in the background.

func (*Strategy) Run

func (s *Strategy) Run()

Run the Strategy in the background.

func (*Strategy) String added in v0.2.0

func (s *Strategy) String() string

type StrategyOptions

type StrategyOptions func(*Strategy)

StrategyOptions sets how to create a Strategy.

func WithLogger

func WithLogger(logger *logger.Logger) StrategyOptions

WithLogger sets a logger.Logger.

func WithNextThreshold

func WithNextThreshold(r ratio) StrategyOptions

WithNextThreshold sets a ratio to creat the next Reporter.

Jump to

Keyboard shortcuts

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