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
releasedis obsolete when its strate is not the currentreleased_strates.validated_stratevalue; - a
buildingorfailedbuild is obsolete when itscreated_atis older than the currently released build; - the current released strate is never selected as obsolete;
garbage_collectedrows 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:
MySQL executes:
PostgreSQL executes:
The package does not create, attach or route partitions. The application schema and insertion strategy must already follow this naming convention.