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

WIP: Replace CatchUpHooks with ContentRepositoryHooks #4995

Conversation

bwaidelich
Copy link
Member

@bwaidelich bwaidelich commented Apr 18, 2024

Resolves: #4992

WIP because

@bwaidelich bwaidelich changed the title WIP: Rework CatchUpHooks WIP: Replace CatchUpHooks with ContentRepositoryHooks Apr 19, 2024
$lock->release();
}

/**
* NOTE: This will NOT trigger hooks!
*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to CatchUpService?

foreach ($this->projections as $projection) {
if (!$projection->getCheckpoint()->equals($expectedCheckpoint)) {
//throw new \RuntimeException(sprintf('Projection %s is at checkpoint %d, but was expected to be at %d', $projection::class, $projection->getCheckpoint()->value, $expectedCheckpoint->value), 1714062281);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed with @skurfuerst :
No reason to "stop the world" here, but we should add some result object that contains the projections that were updated/skipped such that we can inform the user immediately

$event = $this->eventNormalizer->denormalize($eventEnvelope->event);
$hooks->dispatchBeforeEvent($event, $eventEnvelope);
foreach ($projectionsToUpdate as $projection) {
$projection->apply($event, $eventEnvelope);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: try/catch -> collect exceptions and throw one combined exception after releasing the lock in line 85

$contentRepository->catchUpProjections();

$hooks->dispatchBeforeCatchUp();
foreach ($this->eventStore->load($eventsToPublish->streamName)->withMinimumSequenceNumber($expectedCheckpoint->next()) as $eventEnvelope) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might read more events than were published..
I think we also need to specify the max sequence number!?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think it's correct this way. But it means that a newly published event might haven been applied in a separate process already

@mhsdesign mhsdesign mentioned this pull request May 16, 2024
10 tasks
Comment on lines +80 to +81
$hooks->dispatchAfterCatchup();
$lock->release();
Copy link
Member Author

@bwaidelich bwaidelich Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe those lines should be switched to prevent deadlocks (When the hook produces new events)

$eventsToPublish->streamName,
$normalizedEvents,
$eventsToPublish->expectedVersion
);
$hooks = $this->hooksFactory->build($contentRepository);
$lock = $this->lockFactory->createLock($contentRepository->id->value . '_catchup');
$lock->acquire(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detect if the lock was required from the same process (i.e. process is owner of the lock) and fail immediately if that's the case à la:

You must not produce events (or send commands) in catch up hooks (except in the afterCatchUp implementation)

See line 80/81

@bwaidelich
Copy link
Member Author

This is no longer valid. With the updated #4746 the plan is to basically keep CatchUpHooks (maybe with a slight modification that allows them to differentiate between "replay" and "catchup")

@bwaidelich bwaidelich closed this Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants