Skip to content

Commit 2925699

Browse files
committed
TASK: refactor healthy release check
1 parent bd36262 commit 2925699

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

Classes/Transfer/ContentReleaseCleaner.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,38 @@ public function removeOldReleases(RedisInstanceIdentifier $redisInstanceIdentifi
7373
throw new \RuntimeException('contentReleaseRetentionCount must be at least 2, found: ' . $contentReleasesToKeep);
7474
}
7575

76-
$i = 0;
76+
$healthyReleaseCounter = 0;
7777
$releasesToRemove = [];
7878
foreach ($contentReleaseIds as $id) {
7979
if ($id->equals($currentRelease)) {
8080
$contentReleaseLogger->info('- ' . $id->getIdentifier() . ' (LIVE)');
8181
} elseif ($id->equals($contentReleaseIdentifierOfUpcomingRelease)) {
8282
$contentReleaseLogger->info('- ' . $id->getIdentifier() . ' (UPCOMING)');
8383
} else {
84-
// on primary: only add to counter if status of release is "success" and release has no errors
85-
if (!$redisInstanceIdentifier->isPrimary() || ($this->redisContentReleaseService->fetchMetadataForContentRelease($id)->getStatus()->getStatus() === NodeRenderingCompletionStatus::success()->getStatus() && count($this->redisRenderingErrorManager->getRenderingErrors($id)) === 0)) {
86-
$i++;
84+
if (!$redisInstanceIdentifier->isPrimary()) {
85+
// We are on a PRODUCTION content store (in case of a replicated setup) - there are no errors transferred there
86+
// by design and we want to NEVER run into a memory problem (that's why the cleanup should always run).
87+
$healthyReleaseCounter++;
88+
} else {
89+
// We are on the primary content store (the one which the pipeline uses as scratch space).
90+
// In case of errors, we want to keep more "good" content releases ("success" state and no errors), so that we can
91+
// more easily switch back to an older release.
92+
// -> We accept potential Redis out of memory errors in this case.
93+
if (($this->redisContentReleaseService->fetchMetadataForContentRelease($id)->getStatus()->getStatus() === NodeRenderingCompletionStatus::success()->getStatus() && count($this->redisRenderingErrorManager->getRenderingErrors($id)) === 0)) {
94+
$healthyReleaseCounter++;
95+
}
8796
}
8897

8998
// we always want to keep $currentRelease and $contentReleaseIdentifierOfUpcomingRelease; thus
9099
// we need to remove 2 from $contentReleasesToKeep
91-
$shouldRemoveRelease = ($i > $contentReleasesToKeep - 2);
92-
93-
if ($shouldRemoveRelease) {
94-
$releasesToRemove[] = $id;
95-
$contentReleaseLogger->info('- ' . $id->getIdentifier() . ' <-- to remove');
96-
} else {
97-
$contentReleaseLogger->info('- ' . $id->getIdentifier());
98-
}
100+
$shouldRemoveRelease = ($healthyReleaseCounter > $contentReleasesToKeep - 2);
101+
102+
if ($shouldRemoveRelease) {
103+
$releasesToRemove[] = $id;
104+
$contentReleaseLogger->info('- ' . $id->getIdentifier() . ' <-- to remove');
105+
} else {
106+
$contentReleaseLogger->info('- ' . $id->getIdentifier());
107+
}
99108
}
100109
}
101110

0 commit comments

Comments
 (0)