\Drupal\strata\Segment SegmentBuilder

Turns a window of journal operations into a manifest, storing each payload as it goes.

The order is fixed and each step depends on the last. Operations are collapsed first, so a subject touched ten times in the window is stored once. Payloads then go through the object store, which deduplicates against everything already held, so an unchanged value costs a lookup rather than an upload. Only what survives both is written.

A payload is supplied by the caller rather than read here, because the value is already in memory at capture time. Nothing in this class reads Drupal.

Summary

Methods
Properties
Constants
__construct
add
count
isEmpty
build
reset
No public properties found
No public constants found
No protected methods found
No protected properties found
No protected constants found
previousMap
operations
payloads
store
level
previous
No private constants found

Properties

$operations

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

Operations added so far, keyed by nothing; order is preserved.

Type

array<int, JournalOp> —

$payloads

$payloads : array

Payload bytes, keyed by operation key.

Type

array<string, string> —

$store

$store : \Drupal\strata\Cas\ObjectStore

Type

ObjectStore

$level

$level : int

Type

int

$previous

$previous : mixed

Type

mixed

Methods

__construct()

__construct(\Drupal\strata\Cas\ObjectStore  $store, int  $level = 0, callable|null  $previous = null) : mixed

Constructs a builder.

Parameters

\Drupal\strata\Cas\ObjectStore $store

Where payloads are stored.

int $level

Compaction level to stamp on the manifest.

callable|null $previous

Given a subject path, returns the frame map of that subject's previous version as a list<string>, or an empty array when there is none. Supplied rather than looked up here so this class keeps knowing nothing about where history lives. Without it every payload is stored standalone, which costs the delta-coding gain and nothing else.

Returns

mixed —

add()

add(\Drupal\strata\Journal\JournalOp  $operation, string|null  $payload = null) : $this

Adds an operation and the payload it captured.

Adding the same operation key twice is expected: that is what collapsing exists for. The later payload wins, matching the surviving operation the collapser produces.

Parameters

\Drupal\strata\Journal\JournalOp $operation

The operation.

string|null $payload

The value the operation captured, or NULL for an operation that carries none.

Returns

$this —

The builder, for chaining.

count()

count() : int

How many operations have been added, before collapsing.

Returns

int —

The count.

isEmpty()

isEmpty() : bool

Whether anything has been added.

Returns

bool —

TRUE when nothing has been added.

build()

build() : \Drupal\strata\Segment\SegmentManifest|null

Collapses, stores the surviving payloads, and produces the manifest.

Clears the builder, so the same instance can start the next window.

Throws

\RuntimeException

When storing a payload fails.

Returns

\Drupal\strata\Segment\SegmentManifest|null —

The manifest, or NULL when nothing was added.

reset()

reset() : void

Discards everything added without storing it.

Used when a flush fails and the window will be rebuilt from the journal rather than retried from memory.

Returns

void —

previousMap()

previousMap(\Drupal\strata\Journal\JournalOp  $operation) : list<string>

The frame map of one subject's previous version.

Parameters

\Drupal\strata\Journal\JournalOp $operation

The operation being stored.

Returns

list

Frame addresses, empty when there is no previous version or no lookup was supplied.