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.

A build is obsolete when:

  • it belongs to the same scope and scope id as a release pointer;
  • it is older than the currently released build;
  • its status is building, released or failed.

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

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

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