\Drupal\strata\Drush\Commands StrataMaintenanceCommands

The passes that make stored history cheaper, and the two that remove parts of it.

Recompaction, re-anchoring, dictionary training and reindexing change no restore target: each rewrites or rebuilds derived state, so the worst case of running one at the wrong moment is wasted work. strata:compact therefore never prunes, whatever else it does.

Pruning and collecting do remove restore targets, so both print their receipt in full and ask before acting, and both go through Compactor::prune() rather than deleting objects themselves. A pack survives while one frame in it is live, a candidate is dropped only when all three reachability classes agree, and an incomplete walk refuses the whole pass; putting a second deletion path beside that one would mean maintaining those rules twice.

Summary

Methods
Properties
Constants
__construct
compact
reanchor
newKey
rotateKey
trainDict
reindex
prune
gc
No public properties found
No public constants found
value
number
flag
ref
prose
agreed
announce
bytes
moment
digest
duration
yesNo
No protected properties found
No protected constants found
adoptRef
printReceipt
receiptList
engine
keyMaker
configFactory
No private constants found

Properties

$engine

$engine : \Drupal\strata\Engine

Type

Engine

$keyMaker

$keyMaker : \Drupal\strata\Crypto\KeyMaker

Type

KeyMaker

$configFactory

$configFactory : \Drupal\Core\Config\ConfigFactoryInterface

Type

ConfigFactoryInterface

Methods

__construct()

__construct(\Drupal\strata\Engine  $engine, \Drupal\strata\Crypto\KeyMaker  $keyMaker, \Drupal\Core\Config\ConfigFactoryInterface  $configFactory) : mixed

Constructs the command set.

Parameters

\Drupal\strata\Engine $engine

Builds the compactor, the reachability set and the passes over them.

\Drupal\strata\Crypto\KeyMaker $keyMaker

Creates the key entity strata:new-key selects.

\Drupal\Core\Config\ConfigFactoryInterface $configFactory

Holds which key is current and which are retired.

Returns

mixed —

compact()

compact(array  $options = ['budget' => 0]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Rewrites stored objects at a setting the flush path cannot afford.

Folds each retention level into the one above, breaks delta chains that have grown past the cap, and recompresses packs. No content address changes and nothing is removed, so the pass is safe to schedule and safe to interrupt. Removing what history no longer needs is strata:prune.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

What the pass did.

reanchor()

reanchor(array  $options = ['budget' => 0, 'dry-run' => false]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Breaks delta chains that have grown past the configured cap.

A chain past the cap still decodes; every frame in it has to be fetched to do so. Re-anchoring stores the deepest frames standalone again, trading stored bytes for a bounded restore cost.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

What the pass did, or would do.

newKey()

newKey(array  $options = ['id' => \Drupal\strata\Crypto\KeyMaker::DEFAULT_ID]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Creates an encryption key, selects it, and retires the one it displaced.

Encryption ships on with no key, so a fresh install refuses every flush until somebody creates a key entity of the right type and length in another module. This is that, in one command.

Retiring the outgoing key is not optional and there is no flag to skip it: everything sealed before this moment stays readable only while the key that sealed it is on the ring, and a store whose key was dropped is indistinguishable from a corrupt one. strata:rotate-key is the pass that ends that state, and it reports when the old key is safe to remove.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

What was created and what was retired.

rotateKey()

rotateKey(array  $options = ['budget' => 0, 'dry-run' => false]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Re-seals frames that still open under a retired key.

A rotation is a state the store is in, not an event: a new key seals everything written from the moment it is configured, and everything written before it stays readable only while the key that sealed it is still on the ring. This is the pass that ends that state. It is bounded, safe to interrupt and safe to repeat, and it moves nothing: a frame is addressed by its decoded bytes, so re-sealing rewrites one object and nothing that references it.

Removing a retired key before complete says yes makes every frame still sealed under it unreadable, and nothing afterwards can tell that apart from corruption.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

What the pass did, or what a measurement found.

trainDict()

trainDict(array  $options = ['ref' => \Drupal\strata\Tree\RefStore::MAIN, 'realm' => \self::REQ]) : \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Trains a compression dictionary per realm from what the store already holds.

A dictionary is what makes small payloads compress at all: a 200-byte field delta has almost no internal redundancy, and the shared structure it does have lives in the other payloads from the same realm. Existing frames stay decodable, because each names the dictionary it used.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\RowsOfFields —

One row per realm, empty when there is no history to sample.

reindex()

reindex(array  $options = ['keep' => false, 'adopt-ref' => false]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Rebuilds the local indexes from what the bucket holds.

The commit index and the frame index are caches over the store, so a site restored from a database dump, or one that imported an archive, has objects the indexes do not know about. This reads the objects back and rewrites both tables from them. Nothing in the bucket is touched.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

What was rebuilt.

prune()

prune(array  $options = ['dry-run' => false, 'limit' => 1000]) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Removes what no reachable history needs, or explains why it would not.

The receipt is printed before anything is deleted, and the numbers in a dry run are the same ones an applied run produces. Every candidate held back is named with its reason, so a pass that frees nothing says which frames kept it from doing so.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

The receipt.

gc()

gc(array  $options = ['dry-run' => false, 'limit' => 1000]) : \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Reports what the reachability walk reached, and removes the frames it did not.

The walk's own totals are what answer "why is nothing collectable": a frame is held by a reachable commit, by a live frame that was compressed against its dictionary, or by something that decodes against it as a delta parent, and the counts say which class is doing the holding. The removal itself is the same prune pass, so the pack and dictionary rules apply unchanged.

Parameters

array $options

Command options.

Returns

\Consolidation\OutputFormatters\StructuredData\RowsOfFields —

One row per reachability class, plus what is collectable.

value()

value(array  $options, string  $name) : string|null

Reads an option that carries a value.

A value option declares DrushCommands::REQ as its default, and Drush replaces that with the string the operator supplied or with NULL before the command body runs. A method called directly - from a test, a hook, or another command - still sees the sentinel, and both forms mean that nothing was supplied. Drush only ever passes a string, so an integer sentinel cannot be confused with a value.

Parameters

array $options

The options the command was called with.

string $name

The option name.

Returns

string|null —

The value, or NULL when none was supplied.

number()

number(array  $options, string  $name, int  $fallback) : int

Reads an option that carries a whole number.

Parameters

array $options

The options the command was called with.

string $name

The option name.

int $fallback

What to return when nothing was supplied.

Returns

int —

The value, or the fallback.

flag()

flag(array  $options, string  $name) : bool

Whether a flag was given.

Parameters

array $options

The options the command was called with.

string $name

The option name.

Returns

bool —

TRUE when the flag was supplied.

ref()

ref(array  $options) : string

The ref an option set names.

Parameters

array $options

The options the command was called with.

Returns

string —

The ref name, or the main ref when none was supplied.

prose()

prose() : \Symfony\Component\Console\Style\SymfonyStyle

The style prose is written to.

Returns

\Symfony\Component\Console\Style\SymfonyStyle —

A style over standard error.

agreed()

agreed(string  $question) : bool

Asks before doing something that removes a restore target or overwrites live data.

Drush answers this itself under --yes and --no, so a scripted run never blocks. The default is no, because the question is only ever asked about something irreversible.

Parameters

string $question

What is about to happen, phrased as a question.

Returns

bool —

TRUE to go ahead.

announce()

announce(bool  $acted, string  $summary) : void

States what a pass did, at the severity the outcome deserves.

A pass that ran and a pass that declined to run both produce a summary worth reading, and the difference between them is what an operator watching a scheduled job needs to see.

Parameters

bool $acted

TRUE when the pass did the thing it was asked to do.

string $summary

The one-line summary to print.

Returns

void —

bytes()

bytes(int  $bytes) : string

Renders a byte count at a readable scale.

Parameters

int $bytes

The count.

Returns

string —

For example "4.0 MiB".

moment()

moment(int  $microtime) : string

Renders unix microseconds as a timestamp.

Parameters

int $microtime

Microseconds since the epoch, or zero for no moment at all.

Returns

string —

An ISO-8601 timestamp, or "-".

digest()

digest(string|null  $digest) : string

Shortens a content address for a table cell.

Anything that is not a digest is returned whole, so an object key or a refusal reason passed here is readable rather than truncated to twelve characters of a path.

Parameters

string|null $digest

The digest, or NULL.

Returns

string —

The first twelve characters of a digest, the value unchanged when it is not one, or "-".

duration()

duration(float  $seconds) : string

Renders a duration.

Parameters

float $seconds

The duration.

Returns

string —

For example "1.24s".

yesNo()

yesNo(bool  $value) : string

Renders a boolean as a word.

Parameters

bool $value

The value.

Returns

string —

Either "yes" or "no".

adoptRef()

adoptRef(bool  $asked) : string|null

Points a lost ref at the newest commit a rebuild recovered.

A rebuild reads objects; it does not decide what history is current, and a ref is a restore target rather than derived state. So this is asked for explicitly and never happens on its own. Without it a store whose ref was deleted can have every object recovered and still have no head, which leaves a verify pass with nothing to walk and a restore with nothing to plan against - recoverable in principle and unrecoverable in practice.

Parameters

bool $asked

TRUE when --adopt-ref was passed.

Returns

string|null —

The commit adopted, or NULL when nothing was asked for, a ref already exists, or the rebuild recovered no commit to adopt.

printReceipt()

printReceipt(\Drupal\strata\Compaction\PruneReceipt  $receipt) : void

Prints a receipt in full, before anything acts on it.

Parameters

\Drupal\strata\Compaction\PruneReceipt $receipt

The receipt.

Returns

void —

receiptList()

receiptList(\Drupal\strata\Compaction\PruneReceipt  $receipt) : \Consolidation\OutputFormatters\StructuredData\PropertyList

Turns a receipt into the command's result.

Parameters

\Drupal\strata\Compaction\PruneReceipt $receipt

The receipt.

Returns

\Consolidation\OutputFormatters\StructuredData\PropertyList —

The result.