TABLE
TABLE = 'strata_lock'
The table leases live in.
Keeps two flushes, or two compactions, from running at once.
Cron can overlap with itself, with Drush, and with a request that triggered a flush directly. Two flushes reading the same journal window would each seal it, producing two segments describing the same operations and two commits racing for the same ref.
The lease is a row whose name is the primary key, so acquiring it is an INSERT that either succeeds or collides. A holder that dies without releasing leaves a row behind, which is why every lease carries a deadline rather than only an owner.
__construct(\Drupal\Core\Database\Connection $database, callable $clock = null) : mixed
Constructs a lease store.
| \Drupal\Core\Database\Connection | $database | Where leases are recorded. |
| callable | $clock | Returns the current unix timestamp. Injected so a test can drive expiry without sleeping. |
acquire(string $name, int $ttl = \self::DEFAULT_TTL) : bool
Takes a lease, or reports that someone else holds it.
An expired lease is taken over rather than waited for. The previous holder is gone by definition, and a flush that never runs because a crashed process left a row is worse than one that overlaps a process which no longer exists.
| string | $name | Lease name. |
| int | $ttl | Seconds before this lease expires. |
TRUE when the lease is now held by this instance.
release(string $name) : bool
Releases a lease this instance holds.
The token is part of the condition, so a process whose lease already expired and was taken over cannot release the new holder's lease on its way out.
| string | $name | Lease name. |
TRUE when a lease held by this instance was released.