Skip to content

Commit 8cbbe38

Browse files
committed
TASK: add more checks before removing/switching a release
1 parent 8434890 commit 8cbbe38

5 files changed

Lines changed: 49 additions & 7 deletions

File tree

Classes/Controller/BackendController.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ class BackendController extends \Neos\Flow\Mvc\Controller\ActionController
7575
*/
7676
protected $redisContentStores;
7777

78-
/**
79-
* @Flow\InjectConfiguration("redisKeyPostfixesForEachRelease")
80-
* @var array
81-
*/
82-
protected $redisKeyPostfixesForEachReleaseConfiguration;
83-
8478
protected $defaultViewObjectName = FusionView::class;
8579

8680
public function indexAction(?string $contentStore = null)

Classes/ReleaseSwitch/Infrastructure/RedisReleaseSwitchService.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\ContentReleaseIdentifier;
66
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\RedisInstanceIdentifier;
77
use Flowpack\DecoupledContentStore\Core\Infrastructure\ContentReleaseLogger;
8+
use Flowpack\DecoupledContentStore\Core\RedisKeyService;
89
use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService;
10+
use Flowpack\DecoupledContentStore\Transfer\Dto\RedisKeyPostfixesForEachRelease;
911
use Neos\Flow\Annotations as Flow;
1012
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
1113

@@ -27,10 +29,39 @@ class RedisReleaseSwitchService
2729
*/
2830
protected $redisContentReleaseService;
2931

32+
/**
33+
* @Flow\Inject
34+
* @var RedisKeyService
35+
*/
36+
protected $redisKeyService;
37+
38+
/**
39+
* @Flow\InjectConfiguration("redisKeyPostfixesForEachRelease")
40+
* @var array
41+
*/
42+
protected $redisKeyPostfixesForEachReleaseConfiguration;
43+
3044
public function switchContentRelease(RedisInstanceIdentifier $redisInstanceIdentifier, ContentReleaseIdentifier $contentReleaseIdentifier, ContentReleaseLogger $contentReleaseLogger)
3145
{
3246
$redis = $this->redisClient->getRedis($redisInstanceIdentifier);
3347
$current = $redis->get('contentStore:current');
48+
49+
// validation checks
50+
// we don't check for errors here (again) as we do not reach this stage if there were errors before
51+
if (!in_array($contentReleaseIdentifier->getIdentifier(), $redis->zRevRangeByLex('contentStore:registeredReleases', '+', '-'))) {
52+
$contentReleaseLogger->error('Content release identifier ' . $contentReleaseIdentifier->getIdentifier() . ' is not listed in current releases thus we do not switch.');
53+
return;
54+
}
55+
56+
$redisKeyPostfixesForEachRelease = RedisKeyPostfixesForEachRelease::fromArray($this->redisKeyPostfixesForEachReleaseConfiguration);
57+
foreach ($redisKeyPostfixesForEachRelease->getRequiredKeys() as $requiredPostfix) {
58+
$key = $this->redisKeyService->getRedisKeyForPostfix($contentReleaseIdentifier, $requiredPostfix->getRedisKeyPostfix());
59+
if (!$redis->exists($key)) {
60+
$contentReleaseLogger->error('Required redis key ' . $key . ' does not exist for release thus we do not switch.');
61+
return;
62+
}
63+
}
64+
3465
$redis->set('contentStore:current', $contentReleaseIdentifier->getIdentifier());
3566
$releaseMetadata = $this->redisContentReleaseService->fetchMetadataForContentRelease($contentReleaseIdentifier);
3667
$this->redisContentReleaseService->setContentReleaseMetadata($contentReleaseIdentifier, $releaseMetadata->withSwitchTime(new \DateTimeImmutable()), $redisInstanceIdentifier);

Classes/Transfer/ContentReleaseCleaner.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public function removeRelease(ContentReleaseIdentifier $contentReleaseIdentifier
110110
return;
111111
}
112112

113+
if ($currentRelease->equals($contentReleaseIdentifierToRemove)) {
114+
$contentReleaseLogger->error('Release to be removed is currently active, thus we do not remove it.');
115+
return;
116+
}
117+
113118
$redisKeyPostfixesForEachRelease = RedisKeyPostfixesForEachRelease::fromArray($this->redisKeyPostfixesForEachReleaseConfiguration);
114119

115120
foreach ($redisKeyPostfixesForEachRelease->getRedisKeyPostfixes() as $redisKeyPostfix) {

Classes/Transfer/Dto/RedisKeyPostfixesForEachRelease.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public function getKeysToTransfer(): iterable
4545
}
4646
}
4747

48+
/**
49+
* @return iterable|RedisKeyPostfixForEachRelease[]
50+
*/
51+
public function getRequiredKeys(): iterable
52+
{
53+
foreach ($this->redisKeyPostfixes as $redisKeyPostfix) {
54+
if ($redisKeyPostfix->isRequired()) {
55+
yield $redisKeyPostfix;
56+
}
57+
}
58+
}
59+
4860
/**
4961
* @return RedisKeyPostfixForEachRelease[]
5062
*/

Configuration/Settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Flowpack:
7575
redisKeyPostfix: 'inProgressRenderings'
7676
transfer: false
7777
transferMode: 'dump'
78-
isRequired: true
78+
isRequired: false
7979
metainfo:
8080
redisKeyPostfix: 'meta:info'
8181
transfer: true

0 commit comments

Comments
 (0)