\Drupal\strata\File FileCapture

Captures one file as blocks, and records which version it is.

The realm with a different economy from every other one. Files are around 98% of the stored bytes on a site that captures them and get almost none of the compression benefit, so they have their own ladder, their own budget line, their own storage class, and a different default: a block is stored once by content and shared by every file and version that holds it.

The journal carries the map, not the bytes. An operation in the file realm is a few hundred bytes naming the map that reassembles the version; the blocks went straight to the store. That keeps a 256 MiB file out of the flush window entirely, which is what stops one large upload from sealing a segment nothing else needed.

A change is priced before it is paid. The previous version's map is compared with the new one, and a file whose blocks have shifted rather than changed raises file.shift_detected instead of quietly storing 60% of itself on every save.

Summary

Methods
Properties
Constants
__construct
capture
measure
previousMap
No public properties found
STATE_PREFIX
No protected methods found
No protected properties found
No protected constants found
append
raise
store
splitter
shifts
journal
scope
state
tripwires
ledger
logger
No private constants found

Constant

STATE_PREFIX

STATE_PREFIX = 'strata.file.'

State key prefix holding the map key of each file's last captured version.

Properties

$store

$store : \Drupal\strata\File\MediaStore

Type

MediaStore

$splitter

$splitter : \Drupal\strata\File\BlockSplitter

Type

BlockSplitter

$shifts

$shifts : \Drupal\strata\File\ShiftDetector

Type

ShiftDetector

$journal

$journal : \Drupal\strata\Journal\JournalInterface

Type

JournalInterface

$scope

$scope : \Drupal\strata\Capture\CaptureScope

Type

CaptureScope

$state

$state : \Drupal\Core\State\StateInterface

Type

StateInterface

$tripwires

$tripwires : \Drupal\strata\Health\TripwireRegistry

Type

TripwireRegistry

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

Methods

__construct()

__construct(\Drupal\strata\File\MediaStore  $store, \Drupal\strata\File\BlockSplitter  $splitter, \Drupal\strata\File\ShiftDetector  $shifts, \Drupal\strata\Journal\JournalInterface  $journal, \Drupal\strata\Capture\CaptureScope  $scope, \Drupal\Core\State\StateInterface  $state, \Drupal\strata\Health\TripwireRegistry  $tripwires, \Drupal\strata\Health\HealthLedgerInterface  $ledger, \Psr\Log\LoggerInterface  $logger) : mixed

Constructs a capture.

Parameters

\Drupal\strata\File\MediaStore $store

Where blocks and maps go.

\Drupal\strata\File\BlockSplitter $splitter

Splits a file into blocks.

\Drupal\strata\File\ShiftDetector $shifts

Decides whether a change is a shift.

\Drupal\strata\Journal\JournalInterface $journal

Where the operation naming the version is appended.

\Drupal\strata\Capture\CaptureScope $scope

Decides whether the file realm is captured at all.

\Drupal\Core\State\StateInterface $state

Remembers which version was captured last.

\Drupal\strata\Health\TripwireRegistry $tripwires

Runs the shift check.

\Drupal\strata\Health\HealthLedgerInterface $ledger

Where a shift is recorded.

\Psr\Log\LoggerInterface $logger

Records what a capture did.

Returns

mixed —

capture()

capture(string  $path, string|null  $storedAs = null, int|null  $actor = null) : \Drupal\strata\File\FileReport

Captures one file if it has changed.

Parameters

string $path

Path to the file on disk.

string|null $storedAs

The path to record, when it differs from where the file sits on disk.

int|null $actor

Drupal user id responsible, or NULL for unattended work.

Returns

\Drupal\strata\File\FileReport —

What the capture did.

measure()

measure(string  $path, string|null  $storedAs = null) : array{blocks: int, new: int, bytes: int, ratio: float, shifted: bool, seconds: float}

What capturing a file would cost, without storing anything.

Parameters

string $path

Path to the file.

string|null $storedAs

The path to compare against.

Returns

array{blocks: int, new: int, bytes: int, ratio: float, shifted: bool, seconds: float} —

The measurement, including how long the split itself would take on this host.

previousMap()

previousMap(string  $subject) : \Drupal\strata\File\FileMap|null

The map of a file's last captured version.

Parameters

string $subject

The path as it was recorded.

Returns

\Drupal\strata\File\FileMap|null —

The map, or NULL when the file has not been captured before or its map cannot be read. An unreadable previous version is treated as a first capture, which stores the whole file: more expensive and never wrong.

append()

append(\Drupal\strata\File\FileMap  $map, string  $key, \Drupal\strata\File\FileMapDiff  $diff, int|null  $actor) : void

Appends the operation naming a stored version.

Parameters

\Drupal\strata\File\FileMap $map

The version.

string $key

The map's object key.

\Drupal\strata\File\FileMapDiff $diff

What changed, which the label reports.

int|null $actor

Drupal user id, or NULL.

Throws

\JsonException

Never in practice, since both values are digest-derived ASCII. Declared rather than cast away so no payload in this module is ever (string) false, which is silently the empty string.

Returns

void —

raise()

raise(\Drupal\strata\File\FileMapDiff  $diff) : void

Records a shift finding when the change looks like one.

Parameters

\Drupal\strata\File\FileMapDiff $diff

What changed.

Returns

void —