\Drupal\strata\Restore Replayer

Reconstructs what a subject looked like at a point in history.

What is stored per change is a FIELD DELTA, not a whole value - a body rewrite costs 297 bytes rather than 2,211 - so a value at time T is the accumulation of every change up to T rather than a single object to fetch. That is the trade the whole storage model rests on, and this is where it is paid back.

The walk runs from the nearest base anchor forward to the target, which is what bounds it: an anchor is a commit a replay may start at, so history before one is never read. Until compaction has produced anchors, the only anchor is the root and a replay covers the whole chain; the report carries the depth either way, so a restore's cost is visible rather than assumed.

Nothing is invented. A version that cannot be read is recorded as unreadable and the fields it carried are left out, which is what makes the result DEGRADED rather than a plausible-looking complete value. A caller that writes a degraded result over a live one has turned a recovery into a second incident, so ReplayResult says which it is and Preflight decides.

Summary

Methods
Properties
Constants
__construct
materialize
materializeAll
subjectsAt
resolve
flushCache
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
manifestAt
apply
manifests
store
commits
refs
segments
bases
No private constants found

Properties

$manifests

$manifests : array

Manifests already read in this pass, keyed by object key.

A replay of many subjects at one commit reads each segment once rather than once per subject, which is the difference between one pass and one pass per subject over the same objects.

Type

array<string, SegmentManifest|false> —

$store

$store : \Drupal\strata\Cas\ObjectStore

Type

ObjectStore

$commits

$commits : \Drupal\strata\Tree\CommitLog

Type

CommitLog

$refs

$refs : \Drupal\strata\Tree\RefStore

Type

RefStore

$segments

$segments : \Drupal\strata\Segment\SegmentReader

Type

SegmentReader

$bases

$bases : \Drupal\strata\Tree\BaseReader

Type

BaseReader

Methods

__construct()

__construct(\Drupal\strata\Cas\ObjectStore  $store, \Drupal\strata\Tree\CommitLog  $commits, \Drupal\strata\Tree\RefStore  $refs, \Drupal\strata\Segment\SegmentReader  $segments, \Drupal\strata\Tree\BaseReader  $bases) : mixed

Constructs a replayer.

Parameters

\Drupal\strata\Cas\ObjectStore $store

Reads payload frames.

\Drupal\strata\Tree\CommitLog $commits

Finds the anchor and the path to the target.

\Drupal\strata\Tree\RefStore $refs

Resolves a ref when a caller names one instead of a commit.

\Drupal\strata\Segment\SegmentReader $segments

Reads the operations each commit sealed.

\Drupal\strata\Tree\BaseReader $bases

Enumerates the subjects a commit covers.

Returns

mixed —

materialize()

materialize(string  $subject, string  $commit) : \Drupal\strata\Restore\ReplayResult

Reconstructs one subject at a commit.

Parameters

string $subject

Subject path, such as "entity/node:42".

string $commit

Commit id to reconstruct at.

Returns

\Drupal\strata\Restore\ReplayResult —

The subject's fields at that commit, and what could not be read.

materializeAll()

materializeAll(list  $subjects, string  $commit) : array<string,\Drupal\strata\Restore\ReplayResult>

Reconstructs several subjects at a commit in one pass.

Parameters

list $subjects

Subject paths.

string $commit

Commit id to reconstruct at.

Returns

array

Subject path keyed to its result.

subjectsAt()

subjectsAt(string  $commit) : list<string>

Every subject a commit covers.

The anchor a commit names is a complete index at the moment the anchor was written, which is at or before the commit. So the set is the anchor's index plus whatever the commits since have touched: a subject created after the anchor appears in no anchor yet, and one deleted after it is still listed by the anchor and has to come out.

Parameters

string $commit

Commit id.

Returns

list

Subject paths.

resolve()

resolve(string  $ref = \Drupal\strata\Tree\RefStore::MAIN, int|null  $microtime = null) : string|null

The commit a ref or a timestamp resolves to.

Parameters

string $ref

Ref name.

int|null $microtime

Unix microseconds to resolve to the commit in force then, or NULL for the ref's tip.

Returns

string|null —

The commit id, or NULL when history does not reach that far back.

flushCache()

flushCache() : void

Forgets the manifests read so far.

Called by a long-running command between batches so memory does not grow with the walk.

Returns

void —

manifestAt()

manifestAt(string  $commit, array>  $unreadable) : \Drupal\strata\Segment\SegmentManifest|null

The manifest one commit sealed.

Parameters

string $commit

Commit id.

array> $unreadable

Collects a line per version that could not be read. A segment that will not read loses every subject in it, so the loss is recorded under the empty key against the commit rather than being silently skipped.

Returns

\Drupal\strata\Segment\SegmentManifest|null —

The manifest, or NULL when the commit sealed none or it would not read.

apply()

apply(string  $commit, string  $subject, \Drupal\strata\Journal\JournalOp  $operation, \Drupal\strata\Segment\SegmentManifest  $manifest, array>  $fields, array  $exists, array  $versions, array>  $unreadable) : void

Folds one operation into a subject's accumulating state.

A create or update merges its field delta over what is there; a delete resets the subject to absent, so a later create starts clean rather than inheriting fields from before the delete.

Parameters

string $commit

Commit the operation came from, for the unreadable line.

string $subject

Subject path.

\Drupal\strata\Journal\JournalOp $operation

The operation.

\Drupal\strata\Segment\SegmentManifest $manifest

The manifest it came from, which holds the frame map for its payload.

array> $fields

Accumulating field sets, keyed by subject.

array $exists

Whether each subject exists as of the operation.

array $versions

How many versions have been applied per subject.

array> $unreadable

Collects a line per version that could not be read.

Returns

void —