Oihana PHP Arango

ArangoRotationTrait

Archive rotation for the `dump` action — **opt-in**.

Old dump archives are pruned according to a retention policy (RetentionOption); without a configured policy (and without --prune) nothing is ever deleted.

The unit of rotation is the bucket: the archive suffix signature ({database}[-partial][-{label}], i.e. the file name minus the leading ISO date and the extension). Archives of the same nature rotate together.

Per bucket: keep the keep most recent, and/or those younger than max_age (an ISO 8601 duration). When both are set the rule is conservative — an archive is deleted only if it is both beyond keep and older than max_age. A global max_total size cap is applied last. Safety rails: at least one archive is always kept per bucket, and the freshly created archive is never pruned.

Table of Contents

Methods

planRotation()  : array<int, string>
Plans the rotation: returns the archive paths to delete.
pruneDumps()  : int
Enumerates the dump directory and prunes (or lists, on a dry run) the archives the policy designates for deletion.
resolveRetentionPolicy()  : RotationPolicy
Resolves the `[arango.dump.retention]` config into a pure policy for {@see planRotation()} (parses the ISO 8601 `max_age` into a cutoff and the `max_total` size into bytes).
retentionEnabled()  : bool
True when the retention config carries at least one deletion criterion (`keep`, `max_age` or `max_total`). `auto` alone never deletes anything.
applyMaxTotal()  : void
Applies the global `max_total` size cap: deletes the oldest survivors across all buckets until the total fits, never violating the per-bucket floor nor pruning the current archive.
archiveBucket()  : string
The bucket of an archive — its suffix signature (file name minus the leading 19-character ISO date, the joining dash and the extension).
archiveDate()  : DateTimeImmutable
The date embedded at the start of an archive file name.
parseRetentionSize()  : int
Parses a human size (`5G`, `500M`, `1.5G`, `2k`, `1024`) into bytes.

Methods

planRotation()

Plans the rotation: returns the archive paths to delete.

public planRotation(array<int, Archive$archives, RotationPolicy $policy[, string|null $current = null ]) : array<int, string>

Pure (no I/O, no clock): the caller supplies the resolved policy.

Parameters
$archives : array<int, Archive>
$policy : RotationPolicy
$current : string|null = null

The freshly created archive, never deleted.

Return values
array<int, string>

The paths to delete.

pruneDumps()

Enumerates the dump directory and prunes (or lists, on a dry run) the archives the policy designates for deletion.

public pruneDumps(string $directory, RotationPolicy $policy, string|null $current, bool $dryRun, SymfonyStyle $io) : int
Parameters
$directory : string

The dump directory.

$policy : RotationPolicy

The resolved policy (resolveRetentionPolicy()).

$current : string|null

The freshly created archive, never pruned.

$dryRun : bool

List only, delete nothing.

$io : SymfonyStyle
Tags
throws
DirectoryException
Return values
int

The number of archives deleted (or that would be).

resolveRetentionPolicy()

Resolves the `[arango.dump.retention]` config into a pure policy for {@see planRotation()} (parses the ISO 8601 `max_age` into a cutoff and the `max_total` size into bytes).

public resolveRetentionPolicy(array<string|int, mixed> $retention) : RotationPolicy
Parameters
$retention : array<string|int, mixed>

The [arango.dump.retention] config section.

Tags
throws
DateInvalidOperationException
Return values
RotationPolicy

retentionEnabled()

True when the retention config carries at least one deletion criterion (`keep`, `max_age` or `max_total`). `auto` alone never deletes anything.

public retentionEnabled(array<string|int, mixed> $retention) : bool
Parameters
$retention : array<string|int, mixed>
Return values
bool

applyMaxTotal()

Applies the global `max_total` size cap: deletes the oldest survivors across all buckets until the total fits, never violating the per-bucket floor nor pruning the current archive.

private applyMaxTotal(array<int, Archive$archives, array<string, Archive&$delete, int $maxTotalBytes, string|null $current) : void
Parameters
$archives : array<int, Archive>
$delete : array<string, Archive>

The path => Archive deletion set, mutated in place.

$maxTotalBytes : int
$current : string|null

archiveBucket()

The bucket of an archive — its suffix signature (file name minus the leading 19-character ISO date, the joining dash and the extension).

private archiveBucket(string $filename) : string
Parameters
$filename : string
Return values
string

archiveDate()

The date embedded at the start of an archive file name.

private archiveDate(string $filename) : DateTimeImmutable
Parameters
$filename : string
Return values
DateTimeImmutable

parseRetentionSize()

Parses a human size (`5G`, `500M`, `1.5G`, `2k`, `1024`) into bytes.

private parseRetentionSize(int|string $value) : int
Parameters
$value : int|string
Tags
throws
InvalidArgumentException

When the value is not a valid size.

Return values
int
On this page

Search results