\Drupal\strata\Archive ArchiveExporter

Writes a span of history into one portable file.

The archive is the bucket's own layout, tarred - object keys become paths inside the tar, so an import is a copy rather than a translation, and a human can open one and read it with no tooling.

What makes it self-contained is the closure, not the commits. A commit resolves through a base anchor, an anchor names frames, a frame may be a delta against a parent frame and may need a dictionary to decompress. Exporting only the commits would produce an archive that unpacks cleanly and restores nothing. So each commit pulls in its whole chain of anchors, every frame those anchors and segments reference, every delta parent up the chain, and every dictionary any of those frames names.

A frame that lives inside a pack pulls the whole pack, which carries frames belonging to other commits too. That costs archive size and buys correctness: a pack is one object, and slicing one frame out of it would mean rewriting the pack index.

Summary

Methods
Properties
Constants
__construct
export
closure
No public properties found
DEFAULT_LIMIT
No protected methods found
No protected properties found
No protected constants found
segmentFrames
anchorChain
frameObjects
dictionaryKey
read
compression
provider
commits
refs
segments
bases
index
dictionaries
site
time
logger
No private constants found

Constant

DEFAULT_LIMIT

DEFAULT_LIMIT = 500

Commits one export walks when no limit is given.

An archive is a file someone downloads, so the default is bounded. --limit=0 lifts it.

Properties

$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

$dictionaries

$dictionaries : \Drupal\strata\Codec\Dictionary\DictionaryStore

Type

DictionaryStore

$site

$site : \Drupal\strata\Site\SiteContext

Type

SiteContext

$time

$time : \Drupal\Component\Datetime\TimeInterface

Type

TimeInterface

$logger

$logger : \Psr\Log\LoggerInterface

Type

LoggerInterface

Methods

__construct()

__construct(\Drupal\strata\Storage\StorageProviderInterface  $provider, \Drupal\strata\Tree\CommitLog  $commits, \Drupal\strata\Tree\RefStore  $refs, \Drupal\strata\Segment\SegmentReader  $segments, \Drupal\strata\Tree\BaseReader  $bases, \Drupal\strata\Cas\FrameIndexInterface  $index, \Drupal\strata\Codec\Dictionary\DictionaryStore  $dictionaries, \Drupal\strata\Site\SiteContext  $site, \Drupal\Component\Datetime\TimeInterface  $time, \Psr\Log\LoggerInterface  $logger) : mixed

Constructs an exporter.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $provider

Where the objects are read from.

\Drupal\strata\Tree\CommitLog $commits

Walks the history.

\Drupal\strata\Tree\RefStore $refs

Names the head the export starts from.

\Drupal\strata\Segment\SegmentReader $segments

Reads which frames a segment references.

\Drupal\strata\Tree\BaseReader $bases

Reads which frames an anchor references.

\Drupal\strata\Cas\FrameIndexInterface $index

Resolves a frame to the object it lives in, and to its delta parent.

\Drupal\strata\Codec\Dictionary\DictionaryStore $dictionaries

Resolves a dictionary id to its object key.

\Drupal\strata\Site\SiteContext $site

Names the site in the manifest.

\Drupal\Component\Datetime\TimeInterface $time

Stamps the manifest.

\Psr\Log\LoggerInterface $logger

Records what the export could not read.

Returns

mixed —

export()

export(string  $path, string|null  $fromCommit = null, int|null  $limit = null) : \Drupal\strata\Archive\ArchiveManifest

Writes an archive.

Parameters

string $path

Where to write. A .gz or .tgz suffix compresses the archive.

string|null $fromCommit

Commit to walk back from, or NULL for the current head.

int|null $limit

Commits to include, or NULL for the default; 0 for every commit.

Throws

\RuntimeException

When the archive file cannot be created, or the history is empty.

Returns

\Drupal\strata\Archive\ArchiveManifest —

What was written.

closure()

closure(string  $head, int  $limit = \self::DEFAULT_LIMIT) : array<string,list<string>>

Everything an archive needs to be restorable on its own.

Parameters

string $head

Commit to walk back from.

int $limit

Commits to include, or 0 for every commit.

Returns

array> —

Keys commits, frames, dictionaries, objects and problems, each holding a list of strings.

segmentFrames()

segmentFrames(\Drupal\strata\Tree\Commit  $commit, array  $objects, list  $problems) : list<string>

Frames a commit's segment references, adding the segment object itself.

Parameters

\Drupal\strata\Tree\Commit $commit

The commit.

array $objects

Object keys collected so far, added to by reference.

list $problems

Problems collected so far, added to by reference.

Returns

list

Frame addresses.

anchorChain()

anchorChain(string  $address, array  $anchors, array  $objects, list  $problems) : list<string>

Frames the whole anchor chain behind an address references.

A commit between two anchors names the anchor in force, so several commits share one chain and it is walked once.

Parameters

string $address

The anchor address the commit names, or an empty string.

array $anchors

Anchor addresses already walked, added to by reference.

array $objects

Object keys collected so far, added to by reference.

list $problems

Problems collected so far, added to by reference.

Returns

list

Frame addresses.

frameObjects()

frameObjects(list  $hashes, list  $problems) : array{frames: list<string>, objects: list<string>, dictionaries: list<string>}

Resolves frames to the objects that hold them, following every delta chain to its anchor.

Parameters

list $hashes

Frame addresses the commits reference directly.

list $problems

Problems collected so far, added to by reference.

Returns

array{frames: list, objects: list, dictionaries: list} —

Every frame including chain parents, the objects holding them, and the dictionaries they decode against.

dictionaryKey()

dictionaryKey(string  $id, list  $problems) : string|null

The object key a dictionary id lives at.

Parameters

string $id

The dictionary id.

list $problems

Problems collected so far, added to by reference.

Returns

string|null —

The key, or NULL when the dictionary is not known here.

read()

read(string  $key, list  $problems) : string|null

Reads one object, recording rather than throwing when it is gone.

Parameters

string $key

The object key.

list $problems

Problems collected so far, added to by reference.

Returns

string|null —

The bytes, or NULL when the object could not be read.

compression()

compression(string  $path) : string|null

The compression an archive path asks for.

Parameters

string $path

The archive path.

Returns

string|null —

"gz" for a gzip suffix, otherwise NULL for an uncompressed tar.