Skip to content

Garbage collection

Default strategy

$stratifiedPersist->garbageCollector([
    CatalogManager::class,
    CatalogSettingsManager::class,
    ProductManager::class,
    TagManager::class,
    ProductTagManager::class,
]);

The default DeleteByBuildStrategy executes one delete per obsolete strate and manager, filtered by buildStrate.

How obsolete builds are selected

The current release pointer is authoritative.

For the same scope and scope id:

  • a build with status released is obsolete when its strate is not the current released_strates.validated_strate value;
  • a building or failed build is obsolete when its created_at is older than the currently released build;
  • the current released strate is never selected as obsolete;
  • garbage_collected rows are handled by metadata cleanup rather than selected as active business-data candidates.

This means superseded released builds do not depend on timestamp ordering. Two builds may have the same timestamp precision and the release pointer still unambiguously identifies which one must remain active.

After business rows are collected, the obsolete build is marked garbage_collected. Garbage-collected build metadata is then deleted. Failed-build metadata older than the configured retention threshold is also deleted.

Managers that were not registered in StratifiedPersist are ignored by garbageCollector().

Garbage collection removes rollback candidates

A previously released build can only be selected again while its business rows and build metadata are still retained. Once garbage collection removes that strate, it is no longer available as a rollback target.

Configure options

use Small\SwooleEntityManager\Strates\Config\StratifiedPersistOptions;

$options = new StratifiedPersistOptions(
    garbageCollectorStrategy: null,
    failedBuildMaxAgeHours: 48,
);

failedBuildMaxAgeHours must be greater than zero. null selects DeleteByBuildStrategy.

Partition strategy

use Small\SwooleEntityManager\Strates\GarbageCollector\PartitionGarbageCollectorStrategy;

$options = new StratifiedPersistOptions(
    garbageCollectorStrategy: new PartitionGarbageCollectorStrategy(),
    failedBuildMaxAgeHours: 24,
);

Partition names are derived from the UUID:

0195f88b-43fd-7f2d-a8fc-3f1fa48f8d29
p_0195f88b43fd7f2da8fc3f1fa48f8d29

MySQL executes:

ALTER TABLE business_table DROP PARTITION p_...

PostgreSQL executes:

DROP TABLE IF EXISTS business_table_p_...

The package does not create, attach or route partitions. The application schema and insertion strategy must already follow this naming convention.

Next chapter: Operational constraints and troubleshooting