\Drupal\strata\Tree BasePolicy

Decides when an anchor is due, and when it has to be a full one.

Two intervals, and they trade against different things.

The anchor interval bounds replay depth: a restore walks the segments between the target and the anchor before it, so a four-hour interval on fifteen-second flushes means at most 960 segments. It is a weak lever on stored bytes, and the reason is worth being exact about: a longer interval means fewer anchors, but each one then covers a longer window and records proportionally more changed subjects, so the two effects largely cancel. An operator tuning this is tuning restore latency, not the bill.

The full-anchor interval bounds resolve cost: reading an anchor means reading the chain back to the last full one, so writing a full anchor every so often keeps that bounded. A full anchor costs one entry per subject on the site rather than one per subject that changed, so it is the expensive kind and it is written rarely.

Summary

Methods
Properties
Constants
__construct
interval
fullEvery
isDue
needsFull
reason
fromSettings
No public properties found
DEFAULT_INTERVAL
DEFAULT_FULL_EVERY
No protected methods found
No protected properties found
No protected constants found
No private methods found
interval
fullEvery
No private constants found

Constant

DEFAULT_INTERVAL

DEFAULT_INTERVAL = 14400

Seconds between anchors.

Four hours, chosen against the replay-depth column rather than a storage one.

DEFAULT_FULL_EVERY

DEFAULT_FULL_EVERY = 24

Delta anchors written before a full one is due.

Twenty-four, so a chain never spans more than four days at the default interval and a resolve reads at most twenty-five objects.

Properties

$interval

$interval : int

Type

int

$fullEvery

$fullEvery : int

Type

int

Methods

__construct()

__construct(int  $interval = \self::DEFAULT_INTERVAL, int  $fullEvery = \self::DEFAULT_FULL_EVERY) : mixed

Constructs a policy.

Parameters

int $interval

Seconds between anchors. Zero means an anchor is written on every flush, which is what a test and an export want.

int $fullEvery

Delta anchors before a full one. One means every anchor is full.

Throws

\InvalidArgumentException

When the interval is negative or the full count is below one.

Returns

mixed —

interval()

interval() : int

The configured anchor interval.

Returns

int —

Seconds.

fullEvery()

fullEvery() : int

How many delta anchors are written before a full one.

Returns

int —

The count.

isDue()

isDue(int|null  $lastAnchor, int  $now) : bool

Whether an anchor is due.

Parameters

int|null $lastAnchor

Unix microseconds of the newest anchor, or NULL when there is none, in which case one is always due: without an anchor a replay walks to the root of history.

int $now

Unix microseconds to compare against.

Returns

bool —

TRUE when the next flush should write one.

needsFull()

needsFull(int  $chainLength) : bool

Whether the anchor now due has to be a full one.

Parameters

int $chainLength

How many anchors stand between the newest one and the full anchor behind it, counting the full one. Zero when there is no anchor at all.

Returns

bool —

TRUE when the next anchor must list every subject.

reason()

reason(int|null  $lastAnchor, int  $now, int  $chainLength) : string|null

Which bound made an anchor due, for the log line.

Parameters

int|null $lastAnchor

Unix microseconds of the newest anchor, or NULL when there is none.

int $now

Unix microseconds.

int $chainLength

The current chain length.

Returns

string|null —

The reason, or NULL when no anchor is due.

fromSettings()

fromSettings(int|null  $interval, int|null  $fullEvery = null) : \Drupal\strata\Tree\BasePolicy

A policy from the module's settings.

Parameters

int|null $interval

The configured interval, or NULL for the default.

int|null $fullEvery

The configured full-anchor count, or NULL for the default.

Returns

\Drupal\strata\Tree\BasePolicy —

The policy.