\Drupal\strata\Flush Flusher

Seals a window of captured operations into a segment and a commit.

The step that turns capture into a backup. Everything before it is local and cheap; this is where bytes leave the site.

Four objects, whatever the site's size. A pack of frames, a segment manifest, a commit and the ref that names it. The index of every subject is not one of them: writing one per flush was measured at 3,989,289 bytes to record a 201-byte change across 50,000 subjects, because its cost scaled with how many subjects the site had rather than with how many changed. So the index belongs to a base anchor on its own interval, the commits in between inherit its address, and what changed in the meantime accumulates in a local table that costs no requests at all.

The order is fixed by what a crash between two steps would leave behind. Payloads are stored first, because a frame nothing references is collectable garbage while a manifest naming a frame that was never written is a corrupt segment. The segment is written before the anchor, the anchor before the commit, and the commit before the ref moves, so at every point the objects already written are either referenced or collectable, and never dangling.

The journal is trimmed last, after the ref has moved. A flush that dies before the trim leaves the window in place and repeats itself on the next run, producing an identical segment - every object is content-addressed, so a repeat costs a few lookups and writes nothing new. A flush that trimmed first and then died would lose the window outright.

Summary

Methods
Properties
Constants
__construct
flush
isDue
lag
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
seal
anchor
resolveFull
actorOf
now
journal
policy
store
segments
bases
reader
basePolicy
subjects
commits
lease
logger
index
notifier
site
No private constants found

Properties

$journal

$journal : \Drupal\strata\Journal\JournalInterface

Type

JournalInterface

$policy

$policy : \Drupal\strata\Journal\FlushPolicy

Type

FlushPolicy

$store

$store : \Drupal\strata\Cas\ObjectStore

Type

ObjectStore

$segments

$segments : \Drupal\strata\Segment\SegmentWriter

Type

SegmentWriter

$bases

$bases : \Drupal\strata\Tree\BaseWriter

Type

BaseWriter

$reader

$reader : \Drupal\strata\Tree\BaseReader

Type

BaseReader

$basePolicy

$basePolicy : \Drupal\strata\Tree\BasePolicy

Type

BasePolicy

$subjects

$subjects : \Drupal\strata\Tree\SubjectIndex

Type

SubjectIndex

$commits

$commits : \Drupal\strata\Tree\CommitLog

Type

CommitLog

$lease

$lease : \Drupal\strata\Flush\Lease

Type

Lease

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

$index

$index : ?\Drupal\strata\Tree\CommitIndex

Type

CommitIndex|null

$notifier

$notifier : ?\Drupal\strata\Event\Notifier

Type

Notifier|null

$site

$site : string

Type

string

Methods

__construct()

__construct(\Drupal\strata\Journal\JournalInterface  $journal, \Drupal\strata\Journal\FlushPolicy  $policy, \Drupal\strata\Cas\ObjectStore  $store, \Drupal\strata\Segment\SegmentWriter  $segments, \Drupal\strata\Tree\BaseWriter  $bases, \Drupal\strata\Tree\BaseReader  $reader, \Drupal\strata\Tree\BasePolicy  $basePolicy, \Drupal\strata\Tree\SubjectIndex  $subjects, \Drupal\strata\Tree\CommitLog  $commits, \Drupal\strata\Flush\Lease  $lease, \Psr\Log\LoggerInterface  $logger, \Drupal\strata\Tree\CommitIndex|null  $index = null, \Drupal\strata\Event\Notifier|null  $notifier = null, string  $site = '') : mixed

Constructs a flusher.

Parameters

\Drupal\strata\Journal\JournalInterface $journal

The journal to drain.

\Drupal\strata\Journal\FlushPolicy $policy

Decides whether a window is due.

\Drupal\strata\Cas\ObjectStore $store

Stores payloads.

\Drupal\strata\Segment\SegmentWriter $segments

Writes the segment manifest.

\Drupal\strata\Tree\BaseWriter $bases

Writes the base anchor when one is due.

\Drupal\strata\Tree\BaseReader $reader

Resolves the anchor chain when a full anchor is due.

\Drupal\strata\Tree\BasePolicy $basePolicy

Decides when an anchor is due and when it has to list every subject.

\Drupal\strata\Tree\SubjectIndex $subjects

Records where every subject was last stored, which is both what the next anchor names and what the next rewrite of a subject is delta coded against.

\Drupal\strata\Tree\CommitLog $commits

Appends the commit and advances the ref.

\Drupal\strata\Flush\Lease $lease

Keeps two flushes from overlapping.

\Psr\Log\LoggerInterface $logger

Records what a flush did, and what it could not do.

\Drupal\strata\Tree\CommitIndex|null $index

Mirrors the commit into the local index, or NULL to write only to the store. The index is a cache over what the bucket already holds, so a flush that cannot reach it has still produced a complete backup and says so.

\Drupal\strata\Event\Notifier|null $notifier

Announces a sealed window, or NULL to announce nothing. Optional because a flush is correct without one and this class is constructed directly by several tests.

string $site

The site identifier a subscriber needs to tell two sites in one bucket apart.

Returns

mixed —

flush()

flush(bool  $force = false, string  $ref = \Drupal\strata\Tree\RefStore::MAIN) : \Drupal\strata\Flush\FlushResult

Seals a window if one is due.

Parameters

bool $force

TRUE to seal whatever is pending regardless of the policy. Used by a shutdown, an export and the strata:flush command.

string $ref

Ref to advance.

Returns

\Drupal\strata\Flush\FlushResult —

What happened.

isDue()

isDue() : bool

Whether a window is due, without sealing one.

Read by the status page and by strata:status, so it does not take the lease.

Returns

bool —

TRUE when a flush would run.

lag()

lag() : float

How far behind the store is, in seconds.

The recovery-point lag: how much of the site's recent history exists only on this server. The number the timeline shows beside the head.

Returns

float —

Seconds since the oldest unsealed operation, or 0.0 when nothing is pending.

seal()

seal(string  $reason, string  $ref) : \Drupal\strata\Flush\FlushResult

Does the sealing, with the lease already held.

Parameters

string $reason

Which bound fired.

string $ref

Ref to advance.

Returns

\Drupal\strata\Flush\FlushResult —

What happened.

anchor()

anchor(\Drupal\strata\Tree\Commit|null  $head, int  $microtime) : array{index: string, wrote: bool, chain: int, at: int, why: string}

Writes the base anchor if one is due, or names the one already in force.

Which subjects the anchor names is decided by when they last changed rather than by emptying a queue. The rows stay, because they are what the next rewrite of each subject is delta coded against, and a failed anchor therefore costs nothing: the next attempt selects the same set.

Parameters

\Drupal\strata\Tree\Commit|null $head

The commit this one follows, or NULL for the root of history, which always writes one.

int $microtime

Unix microseconds the window was sealed at.

Returns

array{index: string, wrote: bool, chain: int, at: int, why: string} —

The anchor address to record, whether this flush wrote it, its chain length, the time it was written and why, which is an empty string when nothing was written.

resolveFull()

resolveFull(\Drupal\strata\Tree\Commit|null  $head, array, size: int}|null>  $changed) : array<string,array{frames: list<string>, size: int}>

The complete index a full anchor lists.

The previous anchor resolved, with this window's changes applied over it. Reading the previous chain is what a full anchor costs and why it is written rarely.

Parameters

\Drupal\strata\Tree\Commit|null $head

The commit this one follows, or NULL when there is no history to carry forward.

array, size: int}|null> $changed

What has changed since the last anchor.

Returns

array, size: int}> —

Every subject the site holds.

actorOf()

actorOf(list<\Drupal\strata\Journal\JournalOp>  $operations) : int|null

The user a commit is attributed to.

A window covering one person's work is attributed to them; one covering several, or covering unattended work, is attributed to nobody rather than to whoever happened to be last.

Parameters

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

The operations the commit covers.

Returns

int|null —

A Drupal user id, or NULL.

now()

now() : int

The current time in unix microseconds.

Returns

int —

Microseconds since the epoch.