\Drupal\strata\Journal FlushPolicy

Decides when a window of captured operations should be sealed into a segment.

The interval is a durability window, not a restore granularity. Operations inside a segment stay individually addressable and individually replayable, so a rollback reaches any single operation whatever the interval is. What the interval decides is how much is lost if the server dies before a flush.

It is also the dominant cost dial, and the cost is requests rather than bytes. Cloudflare R2 charges $4.50 per million Class A operations, and the segment count per month depends only on the interval, not on the site's size: one second costs 3,024,518 writes a month and is over the free tier on its own, while fifteen seconds costs 201,635 and is a fifth of it.

Three conditions therefore fire a flush, whichever comes first. Age bounds the loss window. Bytes bound the memory a request holds. Operations bound the work one flush does, so a burst does not produce a segment too large to seal inside a cron run.

Summary

Methods
Properties
Constants
__construct
maxAge
maxBytes
maxOps
shouldFlush
reason
secondsUntilAge
segmentsPerMonth
No public properties found
DEFAULT_MAX_AGE
DEFAULT_MAX_BYTES
DEFAULT_MAX_OPS
No protected methods found
No protected properties found
No protected constants found
No private methods found
maxAge
maxBytes
maxOps
No private constants found

Constant

DEFAULT_MAX_AGE

DEFAULT_MAX_AGE = 15

Seconds before a window is sealed.

DEFAULT_MAX_BYTES

DEFAULT_MAX_BYTES = 4194304

Buffered payload bytes before a window is sealed.

DEFAULT_MAX_OPS

DEFAULT_MAX_OPS = 5000

Buffered operations before a window is sealed.

Properties

$maxAge

$maxAge : int

Type

int

$maxBytes

$maxBytes : int

Type

int

$maxOps

$maxOps : int

Type

int

Methods

__construct()

__construct(int  $maxAge = \self::DEFAULT_MAX_AGE, int  $maxBytes = \self::DEFAULT_MAX_BYTES, int  $maxOps = \self::DEFAULT_MAX_OPS) : mixed

Constructs a policy.

Parameters

int $maxAge

Seconds before a flush. Zero means age never triggers one.

int $maxBytes

Buffered payload bytes before a flush. Zero means size never triggers one.

int $maxOps

Buffered operations before a flush. Zero means count never triggers one.

Throws

\InvalidArgumentException

When any bound is negative, or when all three are zero, which would mean a window is never sealed and the journal grows without limit.

Returns

mixed —

maxAge()

maxAge() : int

The configured age bound.

Returns

int —

Seconds, or 0 when age never triggers a flush.

maxBytes()

maxBytes() : int

The configured size bound.

Returns

int —

Bytes, or 0 when size never triggers a flush.

maxOps()

maxOps() : int

The configured count bound.

Returns

int —

Operations, or 0 when count never triggers a flush.

shouldFlush()

shouldFlush(int  $pending, int  $bytes, int|null  $oldest, int  $now) : bool

Whether a window should be sealed now.

Parameters

int $pending

Operations waiting.

int $bytes

Payload bytes waiting.

int|null $oldest

Unix microseconds of the oldest waiting operation, or NULL when nothing is waiting.

int $now

Unix microseconds to compare against.

Returns

bool —

TRUE when at least one bound has been reached.

reason()

reason(int  $pending, int  $bytes, int|null  $oldest, int  $now) : string|null

Which bound fired, for the log line and the timeline.

Age is checked first, then count, then size, so the reason reported is the one an operator is most likely to act on.

Parameters

int $pending

Operations waiting.

int $bytes

Payload bytes waiting.

int|null $oldest

Unix microseconds of the oldest waiting operation, or NULL when nothing is waiting.

int $now

Unix microseconds to compare against.

Returns

string|null —

One of "age", "operations" or "bytes", or NULL when no bound has been reached.

secondsUntilAge()

secondsUntilAge(int|null  $oldest, int  $now) : float

How long until the age bound fires, in seconds.

Surfaced so the UI can show the recovery-point lag rather than only reporting a flush after it has happened.

Parameters

int|null $oldest

Unix microseconds of the oldest waiting operation, or NULL when nothing is waiting.

int $now

Unix microseconds to compare against.

Returns

float —

Seconds remaining, 0.0 when the bound has passed, or INF when age never triggers a flush.

segmentsPerMonth()

segmentsPerMonth() : float

Segment writes per month at this interval.

The figure the settings form shows next to the interval, because it is what the request bill is proportional to and it does not depend on the site's size.

Returns

float —

Segments per 30.44-day month, or 0.0 when age never triggers a flush.