Documentation
¶
Overview ¶
Package timebucket shares the aligned merge ladder and bounded selection between both engines.
Index ¶
- Constants
- Variables
- func CanCompact(lo, hi, level, newest int64) bool
- func End(ts, level int64) int64
- func Finest(lo, hi int64) (int64, bool)
- func Fits(lo, hi, level int64) bool
- func Forced[P any](src []P, span func(P) (lo, hi int64), size func(P) int64, ...) []P
- func Of(ts, level int64) int64
- func Runs(ts []int64, fn func(lo, hi int) error) error
- func SplitsFrom[P any](parts []P, span func(P) (lo, hi int64), start int64) bool
- func Straddlers[P any](src []P, span func(P) (lo, hi int64), size func(P) int64, capBytes int64, ...) []P
- func Top() int64
- func Union[P any](parts []P, span func(P) (lo, hi int64)) (lo, hi int64)
- type Router
- func (r *Router[W]) Append(ts int64, add func(W) (full bool, err error)) error
- func (r *Router[W]) Close() error
- func (r *Router[W]) Drop(release func(W))
- func (r *Router[W]) Peak() (total, run int64)
- func (r *Router[W]) Seal(ts int64) error
- func (r *Router[W]) Shed() error
- func (r *Router[W]) Writer(ts int64) (W, error)
Constants ¶
const MaxOpenWriters = 32
MaxOpenWriters bounds the day-keyed writers one merge holds open: a month of days, so a batch of straddlers spanning weeks is still written in one pass without finishing a day early.
Variables ¶
Ladder is the merge bucket ladder, ascending. Each level divides the next, so a bucket nests exactly inside its parent and a part promoted upward never straddles. The top level is the widest part a merge builds, and so the coarsest time locality a query can rely on.
Functions ¶
func CanCompact ¶ added in v0.49.3
CanCompact reports whether a part may join size compaction at level. The newest larger bucket admits only parts already too wide for its preceding level.
func End ¶
End returns the last timestamp of the level-aligned bucket holding ts, saturating at the int64 maximum instead of overflowing past it.
func Finest ¶
Finest returns the narrowest level whose bucket contains [lo, hi], reporting false for a straddler: a span crossing a top-level boundary.
func Forced ¶
func Forced[P any]( src []P, span func(P) (lo, hi int64), size func(P) int64, forced, sealed func(P) bool, capBytes int64, maxParts int, ) []P
Forced returns the forced rewrite for one merge, in src order. The oldest forced part picks the bucket; that bucket's forced parts are taken oldest first up to capBytes of their size (≤ 0 ⇒ unbounded) and maxParts of them (≤ 0 ⇒ unbounded), at least one, and its parts neither forced nor sealed then fill what remains, smallest first. A forced straddler belongs to no bucket and goes alone.
func Of ¶
Of returns the start of the level-aligned bucket holding ts. It rounds toward negative infinity, not toward zero: Go's % keeps the dividend's sign, which would make the bucket at ts = -1 start at 0 and overlap its successor.
func Runs ¶
Runs calls fn once per run of the ascending ts inside one top-level bucket, with the run's [lo, hi) index range.
func SplitsFrom ¶
SplitsFrom reports whether merging parts from start on writes more than one top-level bucket.
func Straddlers ¶
func Straddlers[P any](src []P, span func(P) (lo, hi int64), size func(P) int64, capBytes int64, maxParts int) []P
Straddlers returns the straddlers to split in one merge: oldest first, up to capBytes of their size (≤ 0 ⇒ unbounded) and maxParts of them (≤ 0 ⇒ unbounded), at least one, in src order.
Merging straddlers together rather than one at a time is what makes a backlog converge: their rows land in the same few buckets, so one merge writes a part per bucket touched, not per straddler.
Types ¶
type Router ¶
type Router[W any] struct { Open func(bucket int64) (W, error) Finish func(W) error Resident func(W) int64 Held func() int64 MaxOpen int ResidentLimit int64 ReserveRun int64 // contains filtered or unexported fields }
Router hands a merge's output rows to one writer per top-level bucket, so a merge whose rows span several days writes a part per day in a single pass over its inputs.
At most MaxOpen writers are open, and together with Held — what the caller holds beside them — they hold less than ResidentLimit (≤ 0 ⇒ unbounded) after every run Router.Append routes: past either bound the writer holding the most is finished early. A writer's size is whatever Resident reports, so it must count everything the writer holds. A day can therefore end up in several parts, each of which still fits the day, and the ladder merges them later. The limit is checked per run rather than per series, so one series spanning every open day overshoots it by one run, not by one writer's worth per day — unless ReserveRun keeps room for the next run: the writers are then shed once they leave less than ReserveRun or the largest run so far, whichever is more, and exceed the limit only by a run that outgrows both, by the difference.
func (*Router[W]) Append ¶
Append routes one run of rows, all in the top-level bucket holding ts, to that day's writer: add appends it and reports whether the writer is full, which finishes it. The open writers are then shed back under ResidentLimit.
func (*Router[W]) Drop ¶
func (r *Router[W]) Drop(release func(W))
Drop hands every open writer to release unfinished, for a merge that failed.
func (*Router[W]) Peak ¶
Peak returns the most the open writers held together as a run landed, and the most one run added to a writer: the first exceeds ResidentLimit by at most the second.