\Drupal\strata\Codec\Dictionary DictionaryStore

Keeps every dictionary version any live frame might need.

A dictionary is the one object in the store whose loss is unrecoverable by any other means. A frame compressed against one cannot be opened without it - not partially, not approximately - so a dictionary is never overwritten, never pruned while referenced, and replicated with the frames that name it.

Retraining therefore adds a version rather than replacing one. New frames use the new version, old frames keep naming the old one, and both stay until nothing references them.

The local table is an index over what the bucket already holds, so an uninstall that drops it loses nothing: strata:reindex reads the dictionary objects back.

Summary

Methods
Properties
Constants
__construct
store
record
get
ref
latest
all
ids
versions
forget
flushCache
No public properties found
TABLE
No protected methods found
No protected properties found
No protected constants found
nextVersion
hydrate
bytes
refs
provider
database
No private constants found

Constant

TABLE

TABLE = 'strata_dict'

The table versions are indexed in.

Properties

$bytes

$bytes : array

Dictionary bytes already fetched, keyed by id.

Type

array<string, string> —

$refs

$refs : array

References already read, keyed by id.

Type

array<string, DictionaryRef> —

$database

$database : \Drupal\Core\Database\Connection

Type

Connection

Methods

__construct()

__construct(\Drupal\strata\Storage\StorageProviderInterface  $provider, \Drupal\Core\Database\Connection  $database) : mixed

Constructs a store.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $provider

Where dictionary objects live.

\Drupal\Core\Database\Connection $database

The connection holding the index.

Returns

mixed —

store()

store(string  $realm, string  $bytes, string  $source = \Drupal\strata\Codec\Dictionary\DictionaryRef::RAW, float  $ratio = 1.0, int  $samples = 0) : \Drupal\strata\Codec\Dictionary\DictionaryRef

Stores a newly trained dictionary as the next version of its realm.

Parameters

string $realm

Realm value.

string $bytes

The dictionary.

string $source

Either DictionaryRef::RAW or DictionaryRef::TRAINED.

float $ratio

The ratio it measured on the samples it was scored against.

int $samples

How many samples it was built from.

Throws

\RuntimeException

When the dictionary is empty or cannot be written.

Returns

\Drupal\strata\Codec\Dictionary\DictionaryRef —

The stored reference.

record()

record(\Drupal\strata\Codec\Dictionary\DictionaryRef  $ref) : void

Writes a reference into the local index.

Public so a reindex can rebuild the index from the objects in the bucket.

Parameters

\Drupal\strata\Codec\Dictionary\DictionaryRef $ref

The reference.

Returns

void —

get()

get(string  $id) : string|null

The bytes of one dictionary version.

Parameters

string $id

The id a frame recorded.

Throws

\RuntimeException

When the object is indexed but absent, or its bytes do not hash to the recorded address. A dictionary that decodes to something else would open every frame that names it into garbage, so this refuses rather than returning it.

Returns

string|null —

The dictionary, or NULL when the id names nothing this store holds.

ref()

ref(string  $id) : \Drupal\strata\Codec\Dictionary\DictionaryRef|null

One version's reference.

Parameters

string $id

The id.

Returns

\Drupal\strata\Codec\Dictionary\DictionaryRef|null —

The reference, or NULL when nothing is indexed under it.

latest()

latest(string  $realm) : \Drupal\strata\Codec\Dictionary\DictionaryRef|null

The newest version for a realm.

What a flush and a compaction pass compress against.

Parameters

string $realm

Realm value.

Returns

\Drupal\strata\Codec\Dictionary\DictionaryRef|null —

The reference, or NULL when the realm has no dictionary yet.

all()

all() : array<string,\Drupal\strata\Codec\Dictionary\DictionaryRef>

Every version this store knows about.

Returns

array

Id keyed to reference, newest first within each realm.

ids()

ids() : list<string>

Ids of every version, for a reachability walk.

Returns

list

The ids.

versions()

versions(string  $realm) : int

How many versions a realm has.

Parameters

string $realm

Realm value.

Returns

int —

The count.

forget()

forget(string  $id) : bool

Removes one version from the index and the store.

Only ever called with a version a reachability walk has proved nothing references. There is no safe way to check that here, which is why this takes no decision of its own.

Parameters

string $id

The id.

Returns

bool —

TRUE when a row was removed.

flushCache()

flushCache() : void

Forgets what has been fetched, keeping the objects.

Returns

void —

nextVersion()

nextVersion(string  $realm) : int

The version number a realm's next dictionary gets.

Parameters

string $realm

Realm value.

Returns

int —

One more than the newest, or one when the realm has none.

hydrate()

hydrate(array  $row) : \Drupal\strata\Codec\Dictionary\DictionaryRef

A reference from an index row.

Parameters

array $row

The row.

Returns

\Drupal\strata\Codec\Dictionary\DictionaryRef —

The reference.