\Drupal\strata\Tier TierPolicy

Decides which tier an object is written to, read from, and moved into.

All of it is pure: a key, an age and a placement in, tier indexes out. That is deliberate, because these are the decisions that decide whether history is readable, and a decision that needs a bucket to answer cannot be tested against the cases that matter.

Three rules do the work.

Every write lands in the nearest tier and nowhere else. A far tier is written to exactly once per object, by TierMigrator, and never on the flush path. That is what makes a far tier cheap: its class-A request count is the number of objects that have ever aged into it, not the number of times the site was written to.

Refs are pinned to the nearest tier. A ref is the only mutable object in the store and the only place two writers can collide, so it lives in exactly one bucket. A second ref in a far tier would be a second opinion about where history ends, with no rule for resolving a disagreement that is not a guess. It also keeps the cost of reading a ref at one request whatever the ladder depth, which matters because every flush reads one.

A read tries the tiers a placement names, then the rest nearest-first. A known object costs what an untiered read costs. An unknown one costs one request per tier and records what it found, so it is only ever unknown once.

Summary

Methods
Properties
Constants
__construct
tiers
tierForWrite
readOrder
targetFor
promotionFor
retainsBelow
isPinned
No public properties found
PINNED_PREFIXES
No protected methods found
No protected properties found
No protected constants found
No private methods found
tiers
No private constants found

Constant

PINNED_PREFIXES

PINNED_PREFIXES = [\Drupal\strata\Tree\RefStore::PREFIX]

Key prefixes that never leave the nearest tier.

Matched as a whole path segment, so it catches both the bare prefix and the site-scoped form a shared bucket produces.

Properties

$tiers

$tiers : \Drupal\strata\Tier\TierMap

Type

TierMap

Methods

__construct()

__construct(\Drupal\strata\Tier\TierMap  $tiers) : mixed

Constructs a policy.

Parameters

\Drupal\strata\Tier\TierMap $tiers

The ladder being applied.

Returns

mixed —

tiers()

tiers() : \Drupal\strata\Tier\TierMap

The ladder this policy applies.

Returns

\Drupal\strata\Tier\TierMap —

The ladder.

tierForWrite()

tierForWrite() : int

Where a write goes.

One tier rather than a set, and that is the point rather than a simplification: a body may be an open stream, the contract says a stream is read once and not rewound, and a write fanned out to two tiers would hand the second one an exhausted stream. A second copy is made later, from the bytes in the bucket, by TierMigrator.

Returns

int —

The nearest tier's index.

readOrder()

readOrder(string  $key, \Drupal\strata\Tier\Placement|null  $placement) : list<int>

The order tiers are tried in when reading.

Parameters

string $key

The object key.

\Drupal\strata\Tier\Placement|null $placement

What is known about where it is, or NULL when nothing is.

Returns

list

Tier indexes to try, in order. A pinned key resolves to the nearest tier alone, so a ref that is genuinely absent costs one request rather than one per tier.

targetFor()

targetFor(string  $key, int  $age) : int

The tier an object belongs in, given how long it has gone untouched.

Parameters

string $key

The object key.

int $age

Seconds since the object was last written.

Returns

int —

The tier index. A pinned key is always the nearest tier however old it is.

promotionFor()

promotionFor(string  $key, int  $from, int  $age) : int|null

Whether an object should move out of the tier it is in.

Parameters

string $key

The object key.

int $from

Tier index it is in now.

int $age

Seconds since it was last written.

Returns

int|null —

The tier index to promote it into, or NULL when it is already where it belongs. Only ever one step, so an object crossing two thresholds at once is moved by two passes and every intermediate state is one this code can describe.

retainsBelow()

retainsBelow(int  $tier) : bool

Whether the copy below survives a promotion into a tier.

Parameters

int $tier

Tier index being promoted into.

Returns

bool —

TRUE when the object is copied and the nearer copy stays; FALSE when it moves.

isPinned()

isPinned(string  $key) : bool

Whether a key never leaves the nearest tier.

Parameters

string $key

The object key, scoped or not.

Returns

bool —

TRUE when the key sits under a pinned prefix.