Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! FEATURE: Subscription Engine #5321

Merged
merged 161 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 157 commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
2172f09
WIP
bwaidelich Oct 24, 2024
13b1073
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Oct 24, 2024
d75f174
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Oct 24, 2024
937f84d
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Oct 26, 2024
03fb7ca
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Oct 29, 2024
dcb4be2
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Nov 3, 2024
fafe080
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Nov 5, 2024
29ba908
WIP
bwaidelich Nov 5, 2024
207179b
Tweak type comments
bwaidelich Nov 6, 2024
a127706
Wiring...
bwaidelich Nov 13, 2024
765b84f
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Nov 13, 2024
5b035c1
first (almost) working version
bwaidelich Nov 14, 2024
aca0f9b
Fix CatchUpHooks
bwaidelich Nov 14, 2024
7fea53e
Replace ProjectionService
bwaidelich Nov 14, 2024
ec08d64
remove `EventPersister` and much more :)
bwaidelich Nov 14, 2024
9fef068
Remove `RunSubscriptionEventStore`
bwaidelich Nov 14, 2024
46ad9d1
Improve error handling (WIP)
bwaidelich Nov 14, 2024
5ea8fae
Merge branch '9.0' into feature/4746-rework-catchup-mechanism-3
bwaidelich Nov 17, 2024
88cc600
Fix `ContentRepositoryFactory` constructor
bwaidelich Nov 17, 2024
e3f85ac
Improve error handling during `SubscriptionEngine::setup()`
bwaidelich Nov 17, 2024
c43a2ea
Allow to reset subscriptions
bwaidelich Nov 18, 2024
40e8d35
Re-implement `cr:status` CLI command
bwaidelich Nov 18, 2024
3744fd5
Fix `test_parallel` cr settings
bwaidelich Nov 18, 2024
c0fbfe1
Fix `test_parallel` cr settings 2/2
bwaidelich Nov 18, 2024
f5ff7d6
Tweak subscription engine setup/reset from tests
bwaidelich Nov 18, 2024
f8a8b5b
Fix behat tests ?
bwaidelich Nov 18, 2024
1562435
Disable `EventExportProcessor` test
bwaidelich Nov 18, 2024
2902dc2
Revert "Disable `EventExportProcessor` test"
bwaidelich Nov 18, 2024
0fe05b5
TASK: Fix phpstan
mhsdesign Nov 20, 2024
6e5b565
Merge remote-tracking branch 'origin/9.0' into feature/4746-rework-ca…
mhsdesign Nov 20, 2024
8967ead
TASK: Add sanity check assertion after setting node properties a coup…
mhsdesign Nov 20, 2024
2b5d338
TASK: Introduce dedicated `contentRepositoryLogger`
mhsdesign Nov 20, 2024
2d3a136
Fix parallel tests and publish events on correct stream
mhsdesign Nov 20, 2024
46dc510
TASK: Simplify `normalizeEvents`
mhsdesign Nov 20, 2024
0680533
Merge remote-tracking branch 'origin/9.0' into feature/4746-rework-ca…
mhsdesign Nov 20, 2024
de92d79
TASK: Test that locking and concurrent writing works under heavy load
mhsdesign Nov 20, 2024
f58cefa
TASK: Improve exception thrown if subscriber failed
mhsdesign Nov 20, 2024
e15ae79
TASK: Fix of-by-one error in catchup
mhsdesign Nov 20, 2024
c7df820
TASK: Improve logging and simplify information on debug
mhsdesign Nov 20, 2024
0bd129a
TASK: Remove obsolete ContentRepositorySubscribersFactoryInterface
mhsdesign Nov 20, 2024
1dfaa2c
TASK: Remove generic `EventHandlerInterface` for now, everything is a…
mhsdesign Nov 20, 2024
441b035
TASK: Remove other generic subscription concepts not required for pro…
mhsdesign Nov 20, 2024
9c6ba75
TASK: Remove subscription groups and filtering except for status and ids
mhsdesign Nov 21, 2024
0ac8751
TASK: Remove `$skipBooting` because its an odd signature and unused
mhsdesign Nov 20, 2024
9be3308
TASK: Remove removal of subscriptions
mhsdesign Nov 20, 2024
53790b9
TASK: Remove sqlite support for `DoctrineSubscriptionStore` as db loc…
mhsdesign Nov 20, 2024
481f173
TASK: Inline `ProjectionEventHandler` to `Subscriber` and make it a `…
mhsdesign Nov 21, 2024
b9569c5
TASK: Introduce tests for subscription booting, active and error state
mhsdesign Nov 21, 2024
427829e
TASK: Allow to replace setting of cr registry via `injectSettings`
mhsdesign Nov 21, 2024
715ec2e
TASK: Subscription engine test new and detached status
mhsdesign Nov 21, 2024
512e3c4
TASK: Speedup tests by using truncate
mhsdesign Nov 21, 2024
408ceb2
TASK: Subscription engine test filtering by subscription id
mhsdesign Nov 21, 2024
b71165c
TASK: Subscription engine test `filteringReset`
mhsdesign Nov 22, 2024
c8f8c6a
TASK: introduce `DebugEventProjection` for testing to assert each eve…
mhsdesign Nov 22, 2024
91046e6
TASK: introduce test that projection is rollback'd in case of error
mhsdesign Nov 22, 2024
f624ac6
TASK: test catchup hooks on failure
mhsdesign Nov 22, 2024
0197017
TASK: Introduce test to assert that projection keeps events previousl…
mhsdesign Nov 23, 2024
3b6ca26
TASK: Improve catchup rollback test
mhsdesign Nov 23, 2024
794be11
TASK: Split up mighty `SubscriptionEngineTest`
mhsdesign Nov 23, 2024
752d434
TASK: Simplify AbstractSubscriptionEngineTestCase by moving out speci…
mhsdesign Nov 23, 2024
c4da7fe
TASK: Test error behaviour for onBeforeCatchUp and onAfterCatchUp
mhsdesign Nov 23, 2024
c8cb0a2
TASK: Add test for happy catchup hooks
mhsdesign Nov 23, 2024
dfe5eb3
TASK: Adjust subscription test exceptions to do no retry
mhsdesign Nov 23, 2024
a32bfb2
TASK: Remove `retry_attempt` from subscriptions
mhsdesign Nov 23, 2024
836c347
TASK: Rename factory back to `$additionalSubscriberFactories`
mhsdesign Nov 23, 2024
830b5cc
BUGFIX: `discoverDetachedSubscriptions` did not persist changes
mhsdesign Nov 23, 2024
3d43183
Merge pull request #5375 from mhsdesign/task/radical-cleanup-for-subs…
mhsdesign Nov 23, 2024
6f43825
TASK: Fix phpstan
mhsdesign Nov 23, 2024
60d4f8c
BUGFIX: Reintroduce catchup hooks for all projections
mhsdesign Nov 23, 2024
5ef4ab1
TASK: Adjust to doctrine deprecations in DoctrineSubscriptionStore
mhsdesign Nov 23, 2024
c7cb75b
TASK: Minor code adjustments
mhsdesign Nov 23, 2024
a80639b
TASK: Ensure that the content graph projection is not part of the gen…
mhsdesign Nov 23, 2024
e7acfaa
BUGFIX: ProjectionErrorTest::fixFailedProjection reset error on reset
mhsdesign Nov 23, 2024
fdeec75
TASK: Assertions that setup and boot do not retry failed projections
mhsdesign Nov 23, 2024
31913f5
BUGFIX: SubscriptionDetachedStatusTest::projectionIsDetachedIfConfigu…
mhsdesign Nov 23, 2024
c5ea757
TASK: Throw `CatchUpFailed` exception in case onBeforeCatchUp or onAf…
mhsdesign Nov 23, 2024
794eaf2
TASK: Use save points to rollback projections during transaction on f…
mhsdesign Nov 23, 2024
7852f61
TASK: Handle `TableNotFoundException` gracefully in `subscriptionStat…
mhsdesign Nov 23, 2024
d582766
TASK: Move back to `subscriptionStatuses` test. We need to make sure …
mhsdesign Nov 23, 2024
5dfa592
TASK: Inline `discoverDetachedSubscriptions`
mhsdesign Nov 23, 2024
d5715c7
TASK: Do not discover new subscriptions during catchup
mhsdesign Nov 23, 2024
37a4e47
TASK: Introduce further tests to assert behaviour for catchup and setup
mhsdesign Nov 24, 2024
a8f246b
BUGFIX: Setup must re-setup active projections for migrations
mhsdesign Nov 24, 2024
73e1097
BUGFIX: Setup should reattach detached projections if possible, and m…
mhsdesign Nov 24, 2024
6726d73
FEATURE: Setup marks failed projections to be booted again
mhsdesign Nov 24, 2024
f46077e
FEATURE: Introduce `ContentRepositoryMaintainer` and restore cr:proje…
mhsdesign Nov 24, 2024
bace8ff
TASK: Rename `ProjectionStatus` and introduce `ProjectionSubscription…
mhsdesign Nov 24, 2024
8ff0f61
TASK: Introduce `DetachedSubscriptionStatus` as the projection setup …
mhsdesign Nov 24, 2024
9675572
TASK: Inline `pruneAllWorkspacesAndContentStreamsFromEventStream` int…
mhsdesign Nov 24, 2024
655ac3c
TASK: Reimplement 40e8d35e09ee690406c6a9cfc823c775d4ee3b51
mhsdesign Nov 24, 2024
e235e69
TASK: Document new `ContentRepositoryMaintainer`
mhsdesign Nov 24, 2024
611ca37
TASK: Rename `ProjectionSetupStatus` back to `ProjectionStatus`
mhsdesign Nov 25, 2024
0b8a3b5
TASK: Rename `SubscriptionStatuses` to `SubscriptionStatusCollection`
mhsdesign Nov 25, 2024
51f0cf6
TASK: Leave warning hint for why we do a replay
mhsdesign Nov 25, 2024
a2a2411
TASK: Warn in `catchupProjection` if projection is not ready to be ca…
mhsdesign Nov 25, 2024
63d1589
TASK: Document `catchupProjection` correctly
mhsdesign Nov 25, 2024
2297c14
TASK: Reintroduce `ContentRepositoryStatus` object and expose current…
mhsdesign Nov 25, 2024
1220f82
TASK: Swap Projection and Setup in output so that Setup comes first
mhsdesign Nov 25, 2024
800fd53
WIP: Introduce `cr:reactivateSubscription`
mhsdesign Nov 26, 2024
a0c9f90
TASK: Dont crash on status when the event store is not setup
mhsdesign Nov 27, 2024
8c079d9
TASK: Split projection replay into separate SubscriptionCommandContro…
mhsdesign Nov 27, 2024
4c65d81
TASK: Status also shows new subscriptions even if they are not persis…
mhsdesign Nov 27, 2024
8c9c0e8
TASK: Refine todos
mhsdesign Nov 27, 2024
4424483
TASK: Declare SubscriptionEngine and friends as internal
mhsdesign Nov 27, 2024
baa5e4a
TASK: Add error code to `SubscriptionEngineAlreadyProcessingException`
mhsdesign Nov 27, 2024
66e54bc
TASK: Allow cr registry to implement internal subscription store beca…
mhsdesign Nov 27, 2024
51d39e5
TASK: Rename to `SubscriptionReplayProcessor`
mhsdesign Nov 27, 2024
b2c1a29
TASK: Improve legacy projectionReplayCommand stub
mhsdesign Nov 27, 2024
d84c2a4
TASK: Add test for Subscription & Cr Commands (and thus CRMaintainer)
mhsdesign Nov 27, 2024
fd768da
Merge pull request #5378 from mhsdesign/feature/content-repository-ma…
mhsdesign Nov 27, 2024
ac425ff
TASK: Remove `SubscriptionManager` and make subscriptions immutable
mhsdesign Nov 27, 2024
eb0d792
FEATURE: Implement `reactivateSubscription`
mhsdesign Nov 27, 2024
dc5ff10
TASK: Move transactional logic _on_ projection as it does not belong …
mhsdesign Nov 27, 2024
3448e21
SubscriptionEngineTest postgresql compatible
kitsunet Dec 1, 2024
5abdb0a
Add missing empty string check
kitsunet Dec 1, 2024
2b82f62
TASK: Declare `EventNormalizer` as internal
mhsdesign Dec 2, 2024
4353f0f
TASK: Simplify `SubscriberFactoryDependencies` to only contain api th…
mhsdesign Dec 2, 2024
ea3eaa6
TASK: Introduce `getPropertyConverter` to denote that this is really …
mhsdesign Dec 2, 2024
e750d93
TASK: Migrate checkpoints to subscriptions via `migrateevents:migrate…
mhsdesign Dec 2, 2024
33b717a
TASK: Disable running subscription test on PostgreSQL
mhsdesign Dec 2, 2024
9286afc
TASK: Remove obsolete todo
mhsdesign Dec 2, 2024
d13c153
Merge remote-tracking branch 'origin/9.0' into feature/4746-rework-ca…
mhsdesign Dec 2, 2024
34fd834
TASK: Dont use `new EventNormalizer()` in tests
mhsdesign Dec 2, 2024
caa70bf
TASK: Fix php cs
mhsdesign Dec 3, 2024
54b24b8
BUGFIX: Ensure `onAfterCatchUp` is always executed _after_ the projec…
mhsdesign Dec 2, 2024
4a7b058
TASK: Reactivate `ParallelWritingInWorkspacesTest`
mhsdesign Dec 3, 2024
c47d181
TASK: Test `ProjectionTransactionTrait` when using external projections
mhsdesign Dec 2, 2024
fd9faa4
TASK: Implement that `onAfterCatchUp` called _after_ everything is pe…
mhsdesign Dec 3, 2024
175ab4c
Move savepoint creation back on the subscription store
mhsdesign Dec 3, 2024
582c5e6
TASK: Adjust tests that exactly once delivery is not possible for ext…
mhsdesign Dec 3, 2024
bfb4655
TASK: Change that hooks are not executed in the same savepoint and do…
mhsdesign Dec 3, 2024
aa2e7b1
TASK: Prevent catchup hooks from halting the projections
mhsdesign Dec 3, 2024
bccea53
TASK: Introduce dedicated `CatchUpHadErrors` exception
mhsdesign Dec 3, 2024
4c41482
TASK: Introduce test to assert behaviour when catchup hooks use the p…
mhsdesign Dec 4, 2024
21318b2
TASK: Explain behaviour when handling multiple commands
mhsdesign Dec 7, 2024
47fc20b
FEATURE: Introduce batching in subscription engine
mhsdesign Dec 7, 2024
6b59fdb
FEATURE: Introduce `onAfterBatchCompleted` hook
mhsdesign Dec 7, 2024
d04b8f3
TASK: Trivial cosmetic changes
mhsdesign Dec 9, 2024
b852617
TASK: Update documentation of `CatchUpHookInterface`
mhsdesign Dec 9, 2024
8daa836
TASK: Introduce test that we cannot roll-back setup
mhsdesign Dec 10, 2024
8f55975
TASK: Remove use of save-points for projections
mhsdesign Dec 10, 2024
79d4ec7
Fix `DoctrineSubscriptionStore` compatibility with SQLite and PostgreSQL
bwaidelich Dec 10, 2024
6423dc6
Merge pull request #5392 from mhsdesign/task/subscription-engine-save…
mhsdesign Dec 11, 2024
42edc02
Merge remote-tracking branch 'origin/9.0' into feature/4746-rework-ca…
mhsdesign Dec 11, 2024
c3e3291
TASK: Improve errors for catch hooks to only the first error the exce…
mhsdesign Dec 13, 2024
542bd4e
TASK: Replace `transactional` function use with explicit start and stop
mhsdesign Dec 13, 2024
efa4165
TASK: Ensure that subscriptions are not catchup'd if "onBeforeCatchUp…
mhsdesign Dec 13, 2024
202519c
TASK: Add test to ensure transaction is not active during onAfterBatc…
mhsdesign Dec 13, 2024
cc299c3
TASK: Only collect first Throwable object instance during catchup
mhsdesign Dec 13, 2024
431732e
TASK: Improve message of `CatchUpHadErrors` by concatenating all erro…
mhsdesign Dec 13, 2024
3fa4122
TASK: Log catchup hook errors directly and improve error output durin…
mhsdesign Dec 13, 2024
2e76381
TASK: Add position of error to catchup error for better debug informa…
mhsdesign Dec 13, 2024
cd384e5
TASK: Credit patchlevel in SubscriptionEngine
mhsdesign Dec 13, 2024
4d65f9c
Merge remote-tracking branch 'origin/9.0' into feature/4746-rework-ca…
mhsdesign Dec 13, 2024
d53c361
TASK: Adjust commitOnConnection_onAfterEvent test to batching
mhsdesign Dec 13, 2024
24890b9
TASK: Ensure status is serialized by value
mhsdesign Dec 13, 2024
ca79907
BUGFIX: Ensure that replay does not reset new or detached projections
mhsdesign Dec 13, 2024
dc97232
TASK: Make phpcs happy
mhsdesign Dec 13, 2024
b76f80e
TASK: Test that rest skips detached and new projections
mhsdesign Dec 16, 2024
6b90c92
TASK: Test that reset also resets detached projections if they are re…
mhsdesign Dec 16, 2024
525fcc4
TASK: Remove `subscription:reactivate` for now
mhsdesign Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,4 @@ public function contentStream(): string
{
return $this->tableNamePrefix . '_contentstream';
}

public function checkpoint(): string
{
return $this->tableNamePrefix . '_checkpoint';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@
use Neos\ContentRepository\Core\Feature\WorkspacePublication\Event\WorkspaceWasPublished;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceRebaseFailed;
use Neos\ContentRepository\Core\Feature\WorkspaceRebase\Event\WorkspaceWasRebased;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\NodeType\NodeTypeName;
use Neos\ContentRepository\Core\Projection\CheckpointStorageStatusType;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjectionInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
use Neos\ContentRepository\Core\Projection\ContentGraph\NodeTags;
Expand All @@ -73,7 +71,6 @@
use Neos\ContentRepository\Core\SharedModel\Node\NodeName;
use Neos\ContentRepository\Core\SharedModel\Node\ReferenceName;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\EventEnvelope;

/**
Expand All @@ -91,20 +88,13 @@ final class DoctrineDbalContentGraphProjection implements ContentGraphProjection

public const RELATION_DEFAULT_OFFSET = 128;

private DbalCheckpointStorage $checkpointStorage;

public function __construct(
private readonly Connection $dbal,
private readonly ProjectionContentGraph $projectionContentGraph,
private readonly ContentGraphTableNames $tableNames,
private readonly DimensionSpacePointsRepository $dimensionSpacePointsRepository,
private readonly ContentGraphReadModelInterface $contentGraphReadModel
) {
$this->checkpointStorage = new DbalCheckpointStorage(
$this->dbal,
$this->tableNames->checkpoint(),
self::class
);
}

public function setUp(): void
Expand All @@ -118,18 +108,10 @@ public function setUp(): void
throw new \RuntimeException(sprintf('Failed to setup projection %s: %s', self::class, $e->getMessage()), 1716478255, $e);
}
}
$this->checkpointStorage->setUp();
}

public function status(): ProjectionStatus
{
$checkpointStorageStatus = $this->checkpointStorage->status();
if ($checkpointStorageStatus->type === CheckpointStorageStatusType::ERROR) {
return ProjectionStatus::error($checkpointStorageStatus->details);
}
if ($checkpointStorageStatus->type === CheckpointStorageStatusType::SETUP_REQUIRED) {
return ProjectionStatus::setupRequired($checkpointStorageStatus->details);
}
try {
$this->dbal->connect();
} catch (\Throwable $e) {
Expand All @@ -147,59 +129,16 @@ public function status(): ProjectionStatus
return ProjectionStatus::ok();
}

public function reset(): void
public function resetState(): void
{
$this->truncateDatabaseTables();

$this->checkpointStorage->acquireLock();
$this->checkpointStorage->updateAndReleaseLock(SequenceNumber::none());
}

public function getCheckpointStorage(): DbalCheckpointStorage
{
return $this->checkpointStorage;
}

public function getState(): ContentGraphReadModelInterface
{
return $this->contentGraphReadModel;
}

public function canHandle(EventInterface $event): bool
{
return in_array($event::class, [
ContentStreamWasClosed::class,
ContentStreamWasCreated::class,
ContentStreamWasForked::class,
ContentStreamWasRemoved::class,
ContentStreamWasReopened::class,
DimensionShineThroughWasAdded::class,
DimensionSpacePointWasMoved::class,
NodeAggregateNameWasChanged::class,
NodeAggregateTypeWasChanged::class,
NodeAggregateWasMoved::class,
NodeAggregateWasRemoved::class,
NodeAggregateWithNodeWasCreated::class,
NodeGeneralizationVariantWasCreated::class,
NodePeerVariantWasCreated::class,
NodePropertiesWereSet::class,
NodeReferencesWereSet::class,
NodeSpecializationVariantWasCreated::class,
RootNodeAggregateDimensionsWereUpdated::class,
RootNodeAggregateWithNodeWasCreated::class,
RootWorkspaceWasCreated::class,
SubtreeWasTagged::class,
SubtreeWasUntagged::class,
WorkspaceBaseWorkspaceWasChanged::class,
WorkspaceRebaseFailed::class,
WorkspaceWasCreated::class,
WorkspaceWasDiscarded::class,
WorkspaceWasPublished::class,
WorkspaceWasRebased::class,
WorkspaceWasRemoved::class,
]) || $event instanceof EmbedsContentStreamId;
}

public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
{
match ($event::class) {
Expand Down Expand Up @@ -232,7 +171,7 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
WorkspaceWasPublished::class => $this->whenWorkspaceWasPublished($event),
WorkspaceWasRebased::class => $this->whenWorkspaceWasRebased($event),
WorkspaceWasRemoved::class => $this->whenWorkspaceWasRemoved($event),
default => $event instanceof EmbedsContentStreamId || throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
default => null,
};
if (
$event instanceof EmbedsContentStreamId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\DimensionSpacePointsRepository;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\NodeFactory;
use Neos\ContentGraph\DoctrineDbalAdapter\Domain\Repository\ProjectionContentGraph;
use Neos\ContentRepository\Core\Factory\ProjectionFactoryDependencies;
use Neos\ContentRepository\Core\Factory\SubscriberFactoryDependencies;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjectionFactoryInterface;

/**
Expand All @@ -24,8 +24,7 @@ public function __construct(
}

public function build(
ProjectionFactoryDependencies $projectionFactoryDependencies,
array $options,
SubscriberFactoryDependencies $projectionFactoryDependencies,
): DoctrineDbalContentGraphProjection {
$tableNames = ContentGraphTableNames::create(
$projectionFactoryDependencies->contentRepositoryId
Expand All @@ -35,7 +34,7 @@ public function build(

$nodeFactory = new NodeFactory(
$projectionFactoryDependencies->contentRepositoryId,
$projectionFactoryDependencies->propertyConverter,
$projectionFactoryDependencies->getPropertyConverter(),
$dimensionSpacePointsRepository
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\ContentStreamForking;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\NodeCreation;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\NodeModification;
Expand All @@ -26,7 +25,6 @@
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\NodeVariation;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\Feature\SubtreeTagging;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\SchemaBuilder\HypergraphSchemaBuilder;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Feature\ContentStreamForking\Event\ContentStreamWasForked;
use Neos\ContentRepository\Core\Feature\NodeCreation\Event\NodeAggregateWithNodeWasCreated;
Expand All @@ -41,12 +39,10 @@
use Neos\ContentRepository\Core\Feature\RootNodeCreation\Event\RootNodeAggregateWithNodeWasCreated;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasTagged;
use Neos\ContentRepository\Core\Feature\SubtreeTagging\Event\SubtreeWasUntagged;
use Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage;
use Neos\ContentRepository\Core\Infrastructure\DbalSchemaDiff;
use Neos\ContentRepository\Core\Projection\CheckpointStorageStatusType;
use Neos\ContentRepository\Core\Projection\ProjectionStatus;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjectionInterface;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphReadModelInterface;
use Neos\ContentRepository\Core\Projection\ProjectionStatus;
use Neos\EventStore\Model\EventEnvelope;

/**
Expand All @@ -66,7 +62,6 @@ final class HypergraphProjection implements ContentGraphProjectionInterface
use NodeTypeChange;
use NodeVariation;

private DbalCheckpointStorage $checkpointStorage;
private ProjectionHypergraph $projectionHypergraph;

public function __construct(
Expand All @@ -75,11 +70,6 @@ public function __construct(
private readonly ContentGraphReadModelInterface $contentGraphReadModel
) {
$this->projectionHypergraph = new ProjectionHypergraph($this->dbal, $this->tableNamePrefix);
$this->checkpointStorage = new DbalCheckpointStorage(
$this->dbal,
$this->tableNamePrefix . '_checkpoint',
self::class
);
}


Expand All @@ -97,18 +87,10 @@ public function setUp(): void
create index if not exists restriction_affected
on ' . $this->tableNamePrefix . '_restrictionhyperrelation using gin (affectednodeaggregateids);
');
$this->checkpointStorage->setUp();
}

public function status(): ProjectionStatus
{
$checkpointStorageStatus = $this->checkpointStorage->status();
if ($checkpointStorageStatus->type === CheckpointStorageStatusType::ERROR) {
return ProjectionStatus::error($checkpointStorageStatus->details);
}
if ($checkpointStorageStatus->type === CheckpointStorageStatusType::SETUP_REQUIRED) {
return ProjectionStatus::setupRequired($checkpointStorageStatus->details);
}
try {
$this->getDatabaseConnection()->connect();
} catch (\Throwable $e) {
Expand All @@ -135,12 +117,9 @@ private function determineRequiredSqlStatements(): array
return DbalSchemaDiff::determineRequiredSqlStatements($this->dbal, $schema);
}

public function reset(): void
public function resetState(): void
{
$this->truncateDatabaseTables();

$this->checkpointStorage->acquireLock();
$this->checkpointStorage->updateAndReleaseLock(SequenceNumber::none());
}

private function truncateDatabaseTables(): void
Expand All @@ -151,39 +130,6 @@ private function truncateDatabaseTables(): void
$this->dbal->executeQuery('TRUNCATE table ' . $this->tableNamePrefix . '_restrictionhyperrelation');
}

public function canHandle(EventInterface $event): bool
{
return in_array($event::class, [
// ContentStreamForking
ContentStreamWasForked::class,
// NodeCreation
RootNodeAggregateWithNodeWasCreated::class,
NodeAggregateWithNodeWasCreated::class,
// SubtreeTagging
SubtreeWasTagged::class,
SubtreeWasUntagged::class,
// NodeModification
NodePropertiesWereSet::class,
// NodeReferencing
NodeReferencesWereSet::class,
// NodeRemoval
NodeAggregateWasRemoved::class,
// NodeRenaming
NodeAggregateNameWasChanged::class,
// NodeTypeChange
NodeAggregateTypeWasChanged::class,
// NodeVariation
NodeSpecializationVariantWasCreated::class,
NodeGeneralizationVariantWasCreated::class,
NodePeerVariantWasCreated::class,
// TODO: not yet supported:
//ContentStreamWasRemoved::class,
//DimensionSpacePointWasMoved::class,
//DimensionShineThroughWasAdded::class,
//NodeAggregateWasMoved::class,
]);
}

public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
{
match ($event::class) {
Expand All @@ -209,7 +155,7 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
NodeSpecializationVariantWasCreated::class => $this->whenNodeSpecializationVariantWasCreated($event),
NodeGeneralizationVariantWasCreated::class => $this->whenNodeGeneralizationVariantWasCreated($event),
NodePeerVariantWasCreated::class => $this->whenNodePeerVariantWasCreated($event),
default => throw new \InvalidArgumentException(sprintf('Unsupported event %s', get_debug_type($event))),
default => null,
};
}

Expand All @@ -228,11 +174,6 @@ public function inSimulation(\Closure $fn): mixed
}
}

public function getCheckpointStorage(): DbalCheckpointStorage
{
return $this->checkpointStorage;
}

public function getState(): ContentGraphReadModelInterface
{
return $this->contentGraphReadModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\DBAL\Connection;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Projection\HypergraphProjection;
use Neos\ContentGraph\PostgreSQLAdapter\Domain\Repository\NodeFactory;
use Neos\ContentRepository\Core\Factory\ProjectionFactoryDependencies;
use Neos\ContentRepository\Core\Factory\SubscriberFactoryDependencies;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphProjectionFactoryInterface;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;

Expand All @@ -28,16 +28,15 @@ public static function graphProjectionTableNamePrefix(
}

public function build(
ProjectionFactoryDependencies $projectionFactoryDependencies,
array $options,
SubscriberFactoryDependencies $projectionFactoryDependencies,
): HypergraphProjection {
$tableNamePrefix = self::graphProjectionTableNamePrefix(
$projectionFactoryDependencies->contentRepositoryId
);

$nodeFactory = new NodeFactory(
$projectionFactoryDependencies->contentRepositoryId,
$projectionFactoryDependencies->propertyConverter
$projectionFactoryDependencies->getPropertyConverter()
);

return new HypergraphProjection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
use Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\Dto\TraceEntries;
use Neos\ContentRepository\BehavioralTests\ProjectionRaceConditionTester\Dto\TraceEntryType;
use Neos\ContentRepository\Core\EventStore\EventInterface;
use Neos\ContentRepository\Core\Projection\CatchUpHookInterface;
use Neos\ContentRepository\Core\Projection\CatchUpHook\CatchUpHookInterface;
use Neos\ContentRepository\Core\Subscription\SubscriptionStatus;
use Neos\EventStore\Model\EventEnvelope;
use Neos\Flow\Annotations as Flow;

/**
* We had some race conditions in projections, where {@see \Neos\ContentRepository\Core\Infrastructure\DbalCheckpointStorage} was not working properly.
* We had some race conditions in projections
* We saw some non-deterministic, random errors when running the tests - unluckily only on Linux, not on OSX:
* On OSX, forking a new subprocess in {@see SubprocessProjectionCatchUpTrigger} is *WAY* slower than in Linux;
* and thus the race conditions which appears if two projector instances of the same class run concurrently
Expand Down Expand Up @@ -73,7 +74,7 @@
*
* When {@see onBeforeEvent} is called, we know that we are inside applyEvent() in the diagram above,
* thus we know the lock *HAS* been acquired.
* When {@see onBeforeBatchCompleted}is called, we know the lock will be released directly afterwards.
* When {@see onAfterCatchUp}is called, we know the lock will be released directly afterwards.
*
* We track these timings across processes in a single Redis Stream. Because Redis is single-threaded,
* we can be sure that we observe the correct, total order of interleavings *across multiple processes*
Expand Down Expand Up @@ -107,7 +108,7 @@ final class RaceTrackerCatchUpHook implements CatchUpHookInterface
protected $configuration;
private bool $inCriticalSection = false;

public function onBeforeCatchUp(): void
public function onBeforeCatchUp(SubscriptionStatus $subscriptionStatus): void
{
RedisInterleavingLogger::connect($this->configuration['redis']['host'], $this->configuration['redis']['port']);
}
Expand All @@ -126,16 +127,16 @@ public function onAfterEvent(EventInterface $eventInstance, EventEnvelope $event
{
}

public function onBeforeBatchCompleted(): void
public function onAfterBatchCompleted(): void
{
}

public function onAfterCatchUp(): void
{
// we only want to track relevant lock release calls (i.e. if we were in the event processing loop before)
if ($this->inCriticalSection) {
$this->inCriticalSection = false;
RedisInterleavingLogger::trace(TraceEntryType::LockWillBeReleasedIfItWasAcquiredBefore);
}
}

public function onAfterCatchUp(): void
{
}
}
Loading
Loading