Skip to content

Commit 0f9156f

Browse files
committed
FEATURE: add option to specify transfer of keys per content store
1 parent 522556f commit 0f9156f

6 files changed

Lines changed: 39 additions & 10 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Flowpack\DecoupledContentStore\Exception;
3+
4+
class InvalidTransferConfigException extends \Flowpack\DecoupledContentStore\Exception
5+
{
6+
7+
}

Classes/ReleaseSwitch/Infrastructure/RedisReleaseSwitchService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function switchContentRelease(RedisInstanceIdentifier $redisInstanceIdent
5656
$redisKeyPostfixesForEachRelease = RedisKeyPostfixesForEachRelease::fromArray($this->redisKeyPostfixesForEachReleaseConfiguration);
5757
$hasError = false;
5858
foreach ($redisKeyPostfixesForEachRelease->getRequiredKeys() as $requiredPostfix) {
59-
if ($requiredPostfix->shouldTransfer()) {
59+
if ($requiredPostfix->shouldTransfer($redisInstanceIdentifier)) {
6060
$key = $this->redisKeyService->getRedisKeyForPostfix($contentReleaseIdentifier, $requiredPostfix->getRedisKeyPostfix());
6161
if (!$redis->exists($key)) {
6262
$contentReleaseLogger->error('Required redis key ' . $key . ' does not exist for release thus we do not switch.');

Classes/Transfer/ContentReleaseSynchronizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function syncToTarget(RedisInstanceIdentifier $targetRedisIdentifier, Con
4848

4949
$redisKeyPostfixesForEachRelease = RedisKeyPostfixesForEachRelease::fromArray($this->redisKeyPostfixesForEachReleaseConfiguration);
5050

51-
foreach ($redisKeyPostfixesForEachRelease->getKeysToTransfer() as $redisKeyPostfix) {
51+
foreach ($redisKeyPostfixesForEachRelease->getKeysToTransfer($targetRedisIdentifier) as $redisKeyPostfix) {
5252
$redisKey = $this->redisKeyService->getRedisKeyForPostfix($contentReleaseIdentifier, $redisKeyPostfix->getRedisKeyPostfix());
5353
$contentReleaseLogger->info($redisKey);
5454
if ($redisKeyPostfix->isRequired() && !$sourceRedis->exists($redisKey)) {

Classes/Transfer/Dto/RedisKeyPostfixForEachRelease.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace Flowpack\DecoupledContentStore\Transfer\Dto;
55

6+
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\RedisInstanceIdentifier;
7+
use Flowpack\DecoupledContentStore\Exception\InvalidTransferConfigException;
68
use Neos\Flow\Annotations as Flow;
79

810
/**
@@ -15,24 +17,31 @@ final class RedisKeyPostfixForEachRelease
1517
private const TRANSFER_MODE_DUMP = 'dump';
1618

1719
protected string $redisKeyPostfix;
18-
protected bool $transfer;
20+
protected array $transfer;
1921
protected string $transferMode;
2022
protected bool $isRequired;
2123

2224
/**
2325
* @param string $redisKeyPostfix
24-
* @param bool $transfer
26+
* @param bool|array $transfer
2527
* @param string $transferMode
2628
* @param bool $isRequired
2729
*/
28-
private function __construct(string $redisKeyPostfix, bool $transfer, string $transferMode, bool $isRequired)
30+
private function __construct(string $redisKeyPostfix, $transfer, string $transferMode, bool $isRequired)
2931
{
3032
if (!in_array($transferMode, [self::TRANSFER_MODE_HASH_INCREMENTAL, self::TRANSFER_MODE_DUMP])) {
3133
throw new \RuntimeException('TransferMode ' . $transferMode . ' not supported.');
3234
}
3335

36+
if (is_bool($transfer)) {
37+
$this->transfer = [
38+
'*' => $transfer
39+
];
40+
} else {
41+
$this->transfer = $transfer;
42+
}
43+
3444
$this->redisKeyPostfix = $redisKeyPostfix;
35-
$this->transfer = $transfer;
3645
$this->transferMode = $transferMode;
3746
$this->isRequired = $isRequired;
3847
}
@@ -51,9 +60,15 @@ public static function fromArray(array $in): self
5160
/**
5261
* @return bool
5362
*/
54-
public function shouldTransfer(): bool
63+
public function shouldTransfer(RedisInstanceIdentifier $redisInstanceIdentifier): bool
5564
{
56-
return $this->transfer;
65+
if (array_key_exists($redisInstanceIdentifier->getIdentifier(), $this->transfer)) {
66+
return $this->transfer[$redisInstanceIdentifier->getIdentifier()];
67+
}
68+
if (array_key_exists('*', $this->transfer)) {
69+
return $this->transfer['*'];
70+
}
71+
throw new InvalidTransferConfigException('No valid transfer mode is configured.');
5772
}
5873

5974
public function isRequired(): bool

Classes/Transfer/Dto/RedisKeyPostfixesForEachRelease.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
declare(strict_types=1);
33

44
namespace Flowpack\DecoupledContentStore\Transfer\Dto;
5+
use Flowpack\DecoupledContentStore\Core\Domain\ValueObject\RedisInstanceIdentifier;
6+
57
class RedisKeyPostfixesForEachRelease
68
{
79

@@ -36,10 +38,10 @@ public static function fromArray(array $in): self
3638
/**
3739
* @return iterable|RedisKeyPostfixForEachRelease[]
3840
*/
39-
public function getKeysToTransfer(): iterable
41+
public function getKeysToTransfer(RedisInstanceIdentifier $redisInstanceIdentifier): iterable
4042
{
4143
foreach ($this->redisKeyPostfixes as $redisKeyPostfix) {
42-
if ($redisKeyPostfix->shouldTransfer()) {
44+
if ($redisKeyPostfix->shouldTransfer($redisInstanceIdentifier)) {
4345
yield $redisKeyPostfix;
4446
}
4547
}

Configuration/Settings.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ Flowpack:
6464
# each content release starts with a fixed prefix "contentRelease:[releaseId]:", and afterwards
6565
# follows a part which needs to be registered here. This is needed for synchronization between different
6666
# content stores and cleanup of old releases.
67+
# the transfer setting can either be a boolean value for all redis content stores or an object that specifies
68+
# *per content store*, if the key should be transferred or not. example for the latter:
69+
# transfer:
70+
# target_live: false
71+
# '*': true
6772
data:
6873
redisKeyPostfix: 'data'
6974
transfer: true

0 commit comments

Comments
 (0)