Documentation
¶
Index ¶
- Variables
- type CycleCallback
- type CycleCallbackCtrl
- type CycleCallbackGroup
- type CycleIntervals
- func CompactionCycleIntervals() CycleIntervals
- func GeoCommitLoggerCycleIntervals() CycleIntervals
- func HnswCommitLoggerCycleIntervals() CycleIntervals
- func MemtableFlushCycleIntervals() CycleIntervals
- func NewExpIntervals(minInterval, maxInterval time.Duration, base, steps uint) CycleIntervals
- func NewFixedIntervals(interval time.Duration) CycleIntervals
- func NewLinearIntervals(minInterval, maxInterval time.Duration, steps uint) CycleIntervals
- func NewSeriesIntervals(intervals []time.Duration) CycleIntervals
- type CycleManager
- type CycleTicker
- func CompactionCycleTicker(backoff bool) CycleTicker
- func GeoCommitLoggerCycleTicker(backoff bool) CycleTicker
- func HnswCommitLoggerCycleTicker(backoff bool) CycleTicker
- func MemtableFlushCycleTicker(backoff bool) CycleTicker
- func NewExpTicker(minInterval, maxInterval time.Duration, base, steps uint) CycleTicker
- func NewFixedTicker(interval time.Duration) CycleTicker
- func NewLinearTicker(minInterval, maxInterval time.Duration, steps uint) CycleTicker
- func NewNoopTicker() CycleTicker
- func NewSeriesTicker(intervals []time.Duration) CycleTicker
- type RegisterOption
- type ShouldAbortCallback
Constants ¶
This section is empty.
Variables ¶
var ErrorCallbackNotFound = errors.New("callback not found")
Functions ¶
This section is empty.
Types ¶
type CycleCallback ¶ added in v1.21.0
type CycleCallback func(shouldAbort ShouldAbortCallback) bool
return value indicates whether actual work was done in the cycle
type CycleCallbackCtrl ¶ added in v1.21.0
type CycleCallbackCtrl interface {
IsActive() bool
Activate() error
Deactivate(ctx context.Context) error
Unregister(ctx context.Context) error
}
Used to control of registered in CycleCallbacks container callback Allows deactivating and activating registered callback or unregistering it
func NewCallbackCtrlNoop ¶ added in v1.21.0
func NewCallbackCtrlNoop() CycleCallbackCtrl
func NewCombinedCallbackCtrl ¶ added in v1.21.0
func NewCombinedCallbackCtrl(routinesLimit int, logger logrus.FieldLogger, ctrls ...CycleCallbackCtrl) CycleCallbackCtrl
Creates combined controller to manage all provided controllers at once as it was single instance. Methods (activate, deactivate, unregister) calls nested controllers' methods in parallel by number of goroutines given as argument. If < 1 value given, NumCPU is used.
type CycleCallbackGroup ¶ added in v1.21.0
type CycleCallbackGroup interface {
// Register adds a CycleCallback to the container, returning a controller to
// activate, deactivate, or unregister it.
Register(id string, cycleCallback CycleCallback, options ...RegisterOption) CycleCallbackCtrl
// CycleCallback runs every callback due this tick, acting as a single callback
// for the whole container. It must be called by a single consumer (see the
// type doc); concurrent calls are not supported.
CycleCallback(shouldAbort ShouldAbortCallback) bool
}
CycleCallbackGroup holds multiple callbacks and exposes them as one combined CycleCallback that a CycleManager drives. Registered callbacks can be individually activated, deactivated, and unregistered while the group runs.
CycleCallback must be driven by a single consumer — one CycleManager, one tick at a time. Scheduling reserves each due callback by popping it from an internal heap, so two concurrent CycleCallback calls could otherwise reserve and run the same callback twice. Every group has exactly one CycleManager, so this holds; it is a required precondition, not something the group synchronizes against.
func NewCallbackGroup ¶ added in v1.21.0
func NewCallbackGroup(id string, logger logrus.FieldLogger, routinesLimit int) CycleCallbackGroup
func NewCallbackGroupNoop ¶ added in v1.21.0
func NewCallbackGroupNoop() CycleCallbackGroup
type CycleIntervals ¶ added in v1.21.0
CycleIntervals yields the delay before a callback's next run: Get reports it, Reset and Advance update it after a run (Reset on work done, Advance on an idle run). None may panic — the scheduler calls Get while rescheduling on the ticker goroutine, outside the callback's recover scope, so a panic there kills the scheduler goroutine. Each instance serves one registration and must not be shared across registrations.
func CompactionCycleIntervals ¶ added in v1.21.0
func CompactionCycleIntervals() CycleIntervals
3s . 6.8s .. 14.4s .... 29.6s ........ 60s
func GeoCommitLoggerCycleIntervals ¶ added in v1.21.0
func GeoCommitLoggerCycleIntervals() CycleIntervals
10s . 13.3s .. 20s .... 33.3s ........ 60s
func HnswCommitLoggerCycleIntervals ¶ added in v1.21.0
func HnswCommitLoggerCycleIntervals() CycleIntervals
500ms . 806ms .. 1.42s .... 2.65s ........ 5.1s ................10s
func MemtableFlushCycleIntervals ¶ added in v1.21.0
func MemtableFlushCycleIntervals() CycleIntervals
100ms . 258ms .. 574ms .... 1.206s ........ 2.471s ................ 5s
func NewExpIntervals ¶ added in v1.21.0
func NewExpIntervals(minInterval, maxInterval time.Duration, base, steps uint) CycleIntervals
func NewFixedIntervals ¶ added in v1.21.0
func NewFixedIntervals(interval time.Duration) CycleIntervals
func NewLinearIntervals ¶ added in v1.21.0
func NewLinearIntervals(minInterval, maxInterval time.Duration, steps uint) CycleIntervals
func NewSeriesIntervals ¶ added in v1.21.0
func NewSeriesIntervals(intervals []time.Duration) CycleIntervals
type CycleManager ¶
type CycleManager interface {
Start()
Stop(ctx context.Context) chan bool
StopAndWait(ctx context.Context) error
Running() bool
}
func NewManager ¶ added in v1.21.0
func NewManager(name string, cycleTicker CycleTicker, cycleCallback CycleCallback, logger logrus.FieldLogger) CycleManager
func NewManagerNoop ¶ added in v1.21.0
func NewManagerNoop() CycleManager
type CycleTicker ¶ added in v1.18.3
type CycleTicker interface {
Start()
Stop()
C() <-chan time.Time
// called with bool value whenever cycle function finished execution
// true - indicates cycle function actually did some processing
// false - cycle function returned without doing anything
CycleExecuted(executed bool)
}
func CompactionCycleTicker ¶ added in v1.18.3
func CompactionCycleTicker(backoff bool) CycleTicker
backoff true backs off towards the max interval while cycles report no work and resets to min once work is done; false pins the fixed min interval.
func GeoCommitLoggerCycleTicker ¶ added in v1.18.3
func GeoCommitLoggerCycleTicker(backoff bool) CycleTicker
backoff true backs off towards the max interval while cycles report no work and resets to min once work is done; false pins the fixed min interval.
func HnswCommitLoggerCycleTicker ¶ added in v1.18.3
func HnswCommitLoggerCycleTicker(backoff bool) CycleTicker
backoff true backs off towards the max interval while cycles report no work and resets to min once work is done; false pins the fixed min interval.
func MemtableFlushCycleTicker ¶ added in v1.18.3
func MemtableFlushCycleTicker(backoff bool) CycleTicker
backoff true backs off towards the max interval while cycles report no work and resets to min once work is done; false pins the fixed min interval.
func NewExpTicker ¶ added in v1.18.3
func NewExpTicker(minInterval, maxInterval time.Duration, base, steps uint) CycleTicker
Creates ticker with intervals between minInterval and maxInterval values. Number of intervals in-between is determined by steps value. Ticker starts with minInterval value and with every report of executed "false" changes interval value to next one, up until maxInterval. Report of executed "true" resets interval to minInterval Example: for minInterval = 100ms, maxInterval = 5s, base = 2, steps = 4, intervals are 100ms . 427ms .. 1080ms .... 2387ms ........ 5000ms
If min- or maxInterval is <= 0 or base = 0 or steps = 0 or min > maxInterval, ticker will not fire
func NewFixedTicker ¶ added in v1.21.0
func NewFixedTicker(interval time.Duration) CycleTicker
Creates ticker with fixed interval. Interval is not changed regardless of execution results reported by cycle function
If interval <= 0 given, ticker will not fire
func NewLinearTicker ¶ added in v1.18.3
func NewLinearTicker(minInterval, maxInterval time.Duration, steps uint) CycleTicker
Creates ticker with intervals between minInterval and maxInterval values. Number of intervals in-between is determined by steps value. Ticker starts with minInterval value and with every report of executed "false" changes interval value to next one, up until maxInterval. Report of executed "true" resets interval to minInterval Example: for minInterval = 100ms, maxInterval = 5s, steps = 4, intervals are 100ms . 1325ms . 2550ms . 3775ms . 5000ms
If min- or maxInterval is <= 0 or steps = 0 or min > maxInterval, ticker will not fire
func NewNoopTicker ¶ added in v1.18.3
func NewNoopTicker() CycleTicker
func NewSeriesTicker ¶ added in v1.18.3
func NewSeriesTicker(intervals []time.Duration) CycleTicker
Creates ticker with set of interval values. Ticker starts with intervals[0] value and with every report of executed "false" changes interval value to next one in given array up until last one. Report of executed "true" resets interval to interval[0]
If any of intervals given is <= 0 given, ticker will not fire
type RegisterOption ¶ added in v1.21.0
type RegisterOption func(*cycleCallbackMeta)
RegisterOption is applied to a callback at registration time.
func AsInactive ¶ added in v1.21.0
func AsInactive() RegisterOption
AsInactive returns a RegisterOption that marks the callback inactive on registration; it will not run until explicitly activated.
func WithIntervals ¶ added in v1.21.0
func WithIntervals(intervals CycleIntervals) RegisterOption
WithIntervals returns a RegisterOption that assigns the given intervals to the callback and adjusts the start time so the first run is immediate. Returns nil when intervals is nil, which Register treats as a no-op option.
type ShouldAbortCallback ¶ added in v1.21.0
type ShouldAbortCallback func() bool
indicates whether cyclemanager's stop was requested to allow safely abort execution of CycleCallback and stop cyclemanager earlier