\Drupal\strata\Tree SubjectIndex

Where every subject was last stored, kept locally so a flush reads nothing.

Two things need this and neither can afford a fetch.

An anchor names the subjects that changed since the anchor before it. Working that set out from the store would mean reading every segment written since - 960 objects at the shipped intervals - on every anchor.

Delta coding needs the address of a subject's previous version, because a rewritten value compresses against its own predecessor 63.70x better than against anything else. Resolving that from the anchor chain would cost reads on the flush path, which is the one place that cannot afford them.

So this is a complete local index rather than a per-interval accumulator, and it is never cleared by writing an anchor. An earlier version truncated it at each anchor, which left the first rewrite after every anchor with no parent to code against - the delta gain silently applied to some writes and not others. Rows are selected by when they last changed instead.

Local and derivable, which is why it lives in a table rather than in the bucket. Every row is recoverable from the anchors, so an uninstall dropping it loses nothing: the next anchor is written full, which is correct if more expensive, and delta coding resumes as subjects are written again.

Summary

Methods
Properties
Constants
__construct
record
changedSince
all
frames
changedAt
count
countSince
clear
No public properties found
TABLE
BATCH
No protected methods found
No protected properties found
No protected constants found
decodeFrames
database
No private constants found

Constant

TABLE

TABLE = 'strata_subject'

The table subjects are indexed in.

BATCH

BATCH = 5000

Rows read in one batch when an anchor is written.

A bound on memory rather than on correctness: the read pages until the set is exhausted.

Properties

$database

$database : \Drupal\Core\Database\Connection

Type

Connection

Methods

__construct()

__construct(\Drupal\Core\Database\Connection  $database) : mixed

Constructs an index.

Parameters

\Drupal\Core\Database\Connection $database

The connection holding the table.

Returns

mixed —

record()

record(array, size: int}|null>  $subjects, int  $microtime) : int

Records where each subject a window touched is now stored.

Parameters

array, size: int}|null> $subjects

Subject path keyed to its frame map, or NULL for a subject the window deleted.

int $microtime

Unix microseconds the window was sealed at.

Returns

int —

How many subjects were recorded.

changedSince()

changedSince(int  $since) : array<string,array{frames: list<string>, size: int}|null>

Subjects that changed after a given moment.

What the next anchor records. Bounded by time rather than by emptying the table, so a subject appears in exactly the one anchor that follows its change and stays available to delta code against afterwards.

Parameters

int $since

Unix microseconds, exclusive. Zero returns everything.

Returns

array, size: int}|null> —

Subject path keyed to its frame map, or NULL for a deletion.

all()

all() : array<string,array{frames: list<string>, size: int}|null>

Every subject the index knows about.

Returns

array, size: int}|null> —

Subject path keyed to its frame map, or NULL for a deletion.

frames()

frames(string  $subject) : list<string>

The frame map one subject was last stored under.

What delta coding codes against.

Parameters

string $subject

Subject path.

Returns

list

Frame addresses, empty when the subject is unknown or was deleted.

changedAt()

changedAt(string  $subject) : int|null

When one subject was last written.

What a restore compares against its target to find out whether it would discard somebody's later edit.

Parameters

string $subject

Subject path.

Returns

int|null —

Unix microseconds, or NULL when the index has never seen the subject.

count()

count() : int

How many subjects the index holds.

Returns

int —

The count, including the deleted ones.

countSince()

countSince(int  $since) : int

How many subjects changed after a given moment.

Parameters

int $since

Unix microseconds, exclusive.

Returns

int —

The count.

clear()

clear() : int

Empties the index.

Called by a reindex, which rebuilds it, and never by writing an anchor: the rows are what the next delta codes against.

Returns

int —

How many rows were removed.

decodeFrames()

decodeFrames(string  $json) : list<string>

The frame list a stored row holds.

Parameters

string $json

The stored column.

Returns

list

Frame addresses.