\Drupal\strata\Tree RefStore

Holds the pointers that say where history currently ends.

A ref is a mutable name for one commit. heads/main is the tip a flush advances; a restore moves it, and a drill reads it without touching it.

A ref is the only mutable object in the store, so it is also the only place two writers can collide. Where the endpoint honours a conditional write, RefStore::compareAndSet() uses one, and a caller that loses the race is told rather than silently overwriting the winner. Where it does not, the same call still verifies the expected value first, which narrows the window without closing it; the flush lease in strata_lock is what actually serialises writers.

Summary

Methods
Properties
Constants
__construct
read
write
compareAndSet
delete
all
No public properties found
PREFIX
MAIN
No protected methods found
No protected properties found
No protected constants found
key
provider
No private constants found

Constant

PREFIX

PREFIX = 'refs'

Key prefix refs are written under.

MAIN

MAIN = 'heads/main'

The ref a flush advances.

Properties

Methods

__construct()

__construct(\Drupal\strata\Storage\StorageProviderInterface  $provider) : mixed

Constructs a ref store.

Parameters

\Drupal\strata\Storage\StorageProviderInterface $provider

Where refs are written.

Returns

mixed —

read()

read(string  $name = \self::MAIN) : string|null

Reads a ref.

Parameters

string $name

Ref name, such as RefStore::MAIN.

Throws

\RuntimeException

When the ref exists but does not hold a valid commit id.

Returns

string|null —

The commit id the ref points at, or NULL when the ref does not exist.

write()

write(string  $commit, string  $name = \self::MAIN) : void

Points a ref at a commit.

Parameters

string $commit

The commit id.

string $name

Ref name.

Throws

\InvalidArgumentException

When the commit id is not a valid digest.

\RuntimeException

When the write fails.

Returns

void —

compareAndSet()

compareAndSet(string|null  $expected, string  $commit, string  $name = \self::MAIN) : bool

Advances a ref only if it still points where the caller thinks it does.

Parameters

string|null $expected

The commit id the ref should currently hold, or NULL to require that it does not exist.

string $commit

The commit id to write.

string $name

Ref name.

Throws

\InvalidArgumentException

When the commit id is not a valid digest.

\RuntimeException

When the write fails for a reason other than losing the race.

Returns

bool —

TRUE when the ref was advanced, FALSE when another writer had already moved it.

delete()

delete(string  $name) : bool

Removes a ref.

The commits it pointed at are untouched; only the name goes away.

Parameters

string $name

Ref name.

Returns

bool —

TRUE when a ref was removed.

all()

all() : array<string,string>

Every ref the store holds.

Throws

\RuntimeException

When a ref holds something that is not a commit id.

Returns

array

Ref name keyed to the commit id it points at.

key()

key(string  $name) : string

The object key a ref lives at.

Parameters

string $name

Ref name.

Throws

\InvalidArgumentException

When the name is empty or contains a traversal segment.

Returns

string —

The object key.