Skip to content

Commit

Permalink
TASK: Remove use of save-points for projections
Browse files Browse the repository at this point in the history
see neos/neos-development-collection#5321 (comment)

the save-point will only be used for REAL projection errors now and never rolled back if catchup errors occur.

With that change in code the save-points are less important because a real projection error should better be thrown at the start before any statements, and even if some statements were issued and a full rollback is done its unlikely that a reactivateSubscription helps that case.

Instead, to repair projections you should replay
  • Loading branch information
mhsdesign committed Dec 10, 2024
1 parent f9a03a2 commit b08a6a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
9 changes: 3 additions & 6 deletions Classes/Subscription/Engine/SubscriptionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,17 @@ private function catchUpSubscriptions(SubscriptionEngineCriteria $criteria, Subs
$errors[] = Error::forSubscription($subscription->id, $e);
}

$this->subscriptionStore->createSavepoint();
try {
$subscriber->projection->apply($domainEvent, $eventEnvelope);
} catch (\Throwable $e) {
// ERROR Case:
$this->logger?->error(sprintf('Subscription Engine: Subscriber "%s" for "%s" could not process the event "%s" (sequence number: %d): %s', $subscriber::class, $subscription->id->value, $eventEnvelope->event->type->value, $eventEnvelope->sequenceNumber->value, $e->getMessage()));
$error = Error::forSubscription($subscription->id, $e);

// 1.) roll back the partially applied event on the subscriber
$this->subscriptionStore->rollbackSavepoint();
// 2.) for the leftover events we are not including this failed subscription for catchup
// for the leftover events we are not including this failed subscription for catchup
$subscriptionsToCatchup = $subscriptionsToCatchup->without($subscription->id);
// 3.) update the subscription error state on either its unchanged or new position (if some events worked)
// update the subscription error state on either its unchanged or new position (if some events worked)
// note that the possibly partially applied event will not be rolled back.
$this->subscriptionStore->update(
$subscription->id,
status: SubscriptionStatus::ERROR,
Expand All @@ -370,7 +368,6 @@ private function catchUpSubscriptions(SubscriptionEngineCriteria $criteria, Subs
}
// HAPPY Case:
$this->logger?->debug(sprintf('Subscription Engine: Subscriber "%s" for "%s" processed the event "%s" (sequence number: %d).', substr(strrchr($subscriber::class, '\\') ?: '', 1), $subscription->id->value, $eventEnvelope->event->type->value, $eventEnvelope->sequenceNumber->value));
$this->subscriptionStore->releaseSavepoint();
$highestSequenceNumberForSubscriber[$subscription->id->value] = $eventEnvelope->sequenceNumber;

try {
Expand Down
6 changes: 0 additions & 6 deletions Classes/Subscription/Store/SubscriptionStoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,4 @@ public function update(
* @return T
*/
public function transactional(\Closure $closure): mixed;

public function createSavepoint(): void;

public function releaseSavepoint(): void;

public function rollbackSavepoint(): void;
}

0 comments on commit b08a6a2

Please sign in to comment.