From 18f200f667cc75d24e37f9b0ce1c69d450138201 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 12 May 2024 18:58:18 +0200 Subject: [PATCH] TASK: WIP Prepare synchronous cr - `ContentRepository::handle()` will block by default --- .../Classes/CommandHandler/CommandResult.php | 64 ++----------------- .../Classes/EventStore/EventPersister.php | 8 +-- .../CatchUpTriggerWithSynchronousOption.php | 6 +- 3 files changed, 13 insertions(+), 65 deletions(-) diff --git a/Neos.ContentRepository.Core/Classes/CommandHandler/CommandResult.php b/Neos.ContentRepository.Core/Classes/CommandHandler/CommandResult.php index a3b1ab3701f..515309a4974 100644 --- a/Neos.ContentRepository.Core/Classes/CommandHandler/CommandResult.php +++ b/Neos.ContentRepository.Core/Classes/CommandHandler/CommandResult.php @@ -5,75 +5,23 @@ namespace Neos\ContentRepository\Core\CommandHandler; use Neos\ContentRepository\Core\ContentRepository; -use Neos\ContentRepository\Core\Projection\ProjectionInterface; -use Neos\ContentRepository\Core\Projection\ProjectionStateInterface; -use Neos\EventStore\Model\Event\SequenceNumber; -use Neos\EventStore\Model\Event\Version; -use Neos\EventStore\Model\EventStore\CommitResult; /** - * Result of the {@see ContentRepository::handle()} method to be able to block until the projections were updated. + * Was the result of the {@see ContentRepository::handle()} method. + * Previously one would need this to be able to block until the projections were updated. * - * {@see PendingProjections} for a detailed explanation how the blocking works. + * This will no longer be required in the future see https://github.com/neos/neos-development-collection/pull/4988 * + * @deprecated this b/c layer will be removed with the next beta or before Neos 9 final release * @api */ final readonly class CommandResult { - public function __construct( - private PendingProjections $pendingProjections, - public CommitResult $commitResult, - ) { - } - - /** - * an empty command result which should not result in projection updates - * @return self - */ - public static function empty(): self - { - return new self( - PendingProjections::empty(), - new CommitResult( - Version::first(), - SequenceNumber::none() - ) - ); - } - /** - * Wait until all projections are up to date; i.e. have processed the events. - * - * @return void - * @api + * We block by default thus you must not call this method or use this legacy stub + * @deprecated this b/c layer will be removed with the next beta or before Neos 9 final release */ public function block(): void { - foreach ($this->pendingProjections->projections as $pendingProjection) { - $expectedSequenceNumber = $this->pendingProjections->getExpectedSequenceNumber($pendingProjection); - $this->blockProjection($pendingProjection, $expectedSequenceNumber); - } - } - - /** - * @param ProjectionInterface $projection - */ - private function blockProjection(ProjectionInterface $projection, SequenceNumber $expectedSequenceNumber): void - { - $attempts = 0; - while ($projection->getCheckpointStorage()->getHighestAppliedSequenceNumber()->value < $expectedSequenceNumber->value) { - usleep(50000); // 50000μs = 50ms - if (++$attempts > 100) { // 5 seconds - throw new \RuntimeException( - sprintf( - 'TIMEOUT while waiting for projection "%s" to catch up to sequence number %d ' . - '- check the error logs for details.', - $projection::class, - $expectedSequenceNumber->value - ), - 1550232279 - ); - } - } } } diff --git a/Neos.ContentRepository.Core/Classes/EventStore/EventPersister.php b/Neos.ContentRepository.Core/Classes/EventStore/EventPersister.php index 4cc945eddcb..aa0e2abed44 100644 --- a/Neos.ContentRepository.Core/Classes/EventStore/EventPersister.php +++ b/Neos.ContentRepository.Core/Classes/EventStore/EventPersister.php @@ -11,8 +11,6 @@ use Neos\ContentRepository\Core\Projection\WithMarkStaleInterface; use Neos\EventStore\EventStoreInterface; use Neos\EventStore\Exception\ConcurrencyException; -use Neos\EventStore\Model\Event; -use Neos\EventStore\Model\Event\EventId; use Neos\EventStore\Model\Events; /** @@ -39,7 +37,7 @@ public function __construct( public function publishEvents(EventsToPublish $eventsToPublish): CommandResult { if ($eventsToPublish->events->isEmpty()) { - return CommandResult::empty(); + return new CommandResult(); } // the following logic could also be done in an AppEventStore::commit method (being called // directly from the individual Command Handlers). @@ -66,8 +64,6 @@ public function publishEvents(EventsToPublish $eventsToPublish): CommandResult } } $this->projectionCatchUpTrigger->triggerCatchUp($pendingProjections->projections); - - // The CommandResult can be used to block until projections are up to date. - return new CommandResult($pendingProjections, $commitResult); + return new CommandResult(); } } diff --git a/Neos.ContentRepositoryRegistry/Classes/Factory/ProjectionCatchUpTrigger/CatchUpTriggerWithSynchronousOption.php b/Neos.ContentRepositoryRegistry/Classes/Factory/ProjectionCatchUpTrigger/CatchUpTriggerWithSynchronousOption.php index 2a9e68d90dc..d6b5342d1e9 100644 --- a/Neos.ContentRepositoryRegistry/Classes/Factory/ProjectionCatchUpTrigger/CatchUpTriggerWithSynchronousOption.php +++ b/Neos.ContentRepositoryRegistry/Classes/Factory/ProjectionCatchUpTrigger/CatchUpTriggerWithSynchronousOption.php @@ -23,6 +23,7 @@ * We will hopefully get rid of this class at some point; by introducing a NodeAggregate * which will take care of constraint enforcement then. * + * @deprecated remove me https://github.com/neos/neos-development-collection/pull/4988 * @internal */ class CatchUpTriggerWithSynchronousOption implements ProjectionCatchUpTriggerInterface @@ -33,7 +34,10 @@ class CatchUpTriggerWithSynchronousOption implements ProjectionCatchUpTriggerInt */ protected $contentRepositoryRegistry; - private static bool $synchronousEnabled = false; + /** + * Hack by setting to true to be always sync mode: https://github.com/neos/neos-development-collection/pull/4988 + */ + private static bool $synchronousEnabled = true; /** * INTERNAL