\Drupal\strata\Compaction Rollup

Folds the segments of one retention level into the coarser level above it.

The retention ladder keeps fifteen-second windows for an hour, minutes for a day, hours for a week and days for three months. Rolling up is what moves history between those: two hundred and forty fifteen-second segments become one hour-long segment, and a subject written in several of them survives once.

What this actually saves is smaller than it looks, and the number is worth stating. Collapse is writes per distinct subject inside the window, and on a site with hundreds of thousands of subjects that is 1.00 at every level below a day: a subject is almost never written twice in the same minute. It becomes meaningful only at monthly rollups. So the saving at fine levels is the object count - two hundred and forty segment manifests become one - rather than the operations inside them, and the real byte saving at those levels comes from recompression instead.

Nothing is deleted here. A rollup writes the coarse segment and leaves the fine ones in place; removing them is a prune, which needs a reachability walk and a receipt. Writing first and removing separately means a rollup that dies halfway has duplicated history rather than lost it.

Summary

Methods
Properties
Constants
__construct
run
dueWindows
fold
No public properties found
DEFAULT_BUDGET
No protected methods found
No protected properties found
No protected constants found
boundary
reader
writer
levels
index
logger
No private constants found

Constant

DEFAULT_BUDGET

DEFAULT_BUDGET = 1000

Fine segments read into one coarse window by default.

A bound on memory: a rollup holds every operation of the window it is folding, and a day of fifteen-second segments is 5,760 of them.

Properties

$reader

$reader : \Drupal\strata\Segment\SegmentReader

Type

SegmentReader

$writer

$writer : \Drupal\strata\Segment\SegmentWriter

Type

SegmentWriter

$levels

$levels : \Drupal\strata\Compaction\LevelPolicy

Type

LevelPolicy

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

Methods

__construct()

__construct(\Drupal\strata\Segment\SegmentReader  $reader, \Drupal\strata\Segment\SegmentWriter  $writer, \Drupal\strata\Compaction\LevelPolicy  $levels, \Drupal\strata\Cas\FrameIndexInterface  $index, \Psr\Log\LoggerInterface  $logger) : mixed

Constructs a rollup pass.

Parameters

\Drupal\strata\Segment\SegmentReader $reader

Reads the fine segments.

\Drupal\strata\Segment\SegmentWriter $writer

Writes the coarse one.

\Drupal\strata\Compaction\LevelPolicy $levels

The ladder, which decides which windows are due and what they roll into.

\Drupal\strata\Cas\FrameIndexInterface $index

Referenced for each frame the coarse segment carries forward, so a prune of the fine segments cannot collect a frame the coarse one still names.

\Psr\Log\LoggerInterface $logger

Records what a pass did.

Returns

mixed —

run()

run(int  $now, int  $budget = 0) : array{windows: int, segments: int, operations: int, collapsed: int, written: list<string>, problems: list<string>}

Rolls up every window that is due, coarsest level last.

Parameters

int $now

Unix seconds to judge retention against.

int $budget

Most fine segments to read in one pass, or zero for the default.

Returns

array{windows: int, segments: int, operations: int, collapsed: int, written: list, problems: list} —

How many windows were folded, how many fine segments they covered, how many operations came out, how many were collapsed away, the coarse segment keys written, and anything that failed.

dueWindows()

dueWindows(int  $level, int  $now) : array<int,list<string>>

The windows at one level whose retention has elapsed, oldest first.

Parameters

int $level

Level number.

int $now

Unix seconds.

Returns

array> —

Coarse window start keyed to the fine segment keys inside it.

fold()

fold(int  $level, int  $start, list  $keys) : array{key: string, operations: int, collapsed: int}|null

Folds the segments of one window into a single coarser one.

Parameters

int $level

The level being rolled up.

int $start

The coarse window's start second, which the new segment is filed under.

list $keys

The fine segment keys.

Returns

array{key: string, operations: int, collapsed: int}|null —

What was written, or NULL when the window held nothing to write.

boundary()

boundary(list<\Drupal\strata\Journal\JournalOp>  $operations, bool  $lowest) : int

The lowest or highest sequence in a set of operations.

A rolled-up window spans several segments, so its sequence range is the range of what survived rather than the range of any one segment it came from.

Parameters

list<\Drupal\strata\Journal\JournalOp> $operations

The operations.

bool $lowest

TRUE for the first sequence, FALSE for the last.

Returns

int —

The sequence.