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: Publishing Version 3 #5301

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c0d6478
WIP task/schnappsidee-rebase-and-partial-publish-in-memory-event-stream
mhsdesign Oct 19, 2024
7190f83
WIP: Commit for command handling in inSimulation
mhsdesign Oct 21, 2024
f47a5e6
WIP: handlePublishIndividualNodesFromWorkspace with remaining events …
mhsdesign Oct 21, 2024
3f9d534
WIP: move handleRebaseWorkspace to run inSimulation
mhsdesign Oct 21, 2024
5f72ead
WIP: refactor handleDiscardIndividualNodesFromWorkspace to run inSimu…
mhsdesign Oct 21, 2024
686d522
WIP todos
mhsdesign Oct 21, 2024
40cebe8
Merge remote-tracking branch 'origin/9.0' into task/schnappsidee-reba…
mhsdesign Oct 22, 2024
b99a498
TASK: Adjustments after merge of cr first level projection
mhsdesign Oct 22, 2024
6847e5c
Merge branch 'task/schnappsidee-zwo-yield-events-to-publish-in-worksp…
mhsdesign Oct 23, 2024
13de53c
TASK: Introduce CommandSimulator and refactor publish partially and r…
mhsdesign Oct 23, 2024
3f0db1d
TASK: Remove now obsolete `ForkContentStream` command
mhsdesign Oct 23, 2024
c766f0b
TASK: Adjust todo comments
mhsdesign Oct 23, 2024
f1c8af6
BUGFIX: Partial publish breaks uri and change Projection
kitsunet Oct 16, 2024
605715b
TASK: Adjust test 02-RebasingWithAutoCreatedNodes.feature
mhsdesign Oct 23, 2024
3b85cf8
TASK: Adjust exceptions to be a noop if PublishIndividualNodesFromWor…
mhsdesign Oct 23, 2024
20c3827
TASK: Introduce test for quick path if rebased commands emitted 0 events
mhsdesign Oct 23, 2024
6343694
TASK: Add quick paths for partial discarding with tests
mhsdesign Oct 23, 2024
e0815bc
Add todos to optimise partial publish to full publish and discard all
mhsdesign Oct 23, 2024
824ca76
TASK: Make publish all a no-op if there are no changes and also ensur…
mhsdesign Oct 23, 2024
96e58ea
TASK: Remove PublishIndividualNodesFromWorkspace::contentStreamIdForM…
mhsdesign Oct 23, 2024
31cfcc5
Workspace aware simulation
kitsunet Oct 23, 2024
aeee478
TASK: Remove outdated comments and adjust variable namings
mhsdesign Oct 23, 2024
77719c9
Cosmetics & Nagellack
mhsdesign Oct 23, 2024
a54a081
TASK: Remove obsolete check to skip events
mhsdesign Oct 24, 2024
653bb8b
Merge remote-tracking branch 'origin/9.0' into task/schnappsidee-reba…
mhsdesign Oct 24, 2024
a0dd931
TASK: Remove extra interface for workspace command handler and combin…
mhsdesign Oct 24, 2024
40233dc
TASK: Use `currentSequenceNumber` instead of calculating it ourselves
mhsdesign Oct 24, 2024
e345f7c
BUGFIX: Move workspace pointer BEFORE remaining events are emitted
mhsdesign Oct 24, 2024
0d0da5c
TASK: Remove old content-stream after rebase
mhsdesign Oct 24, 2024
c63b019
TASK: Ensure that dangling content streams are removed after publish …
mhsdesign Oct 24, 2024
9c06afc
TASK: Simplify CommandSimulator by exposing handle function only duri…
mhsdesign Oct 24, 2024
25d79d3
TASK: Adjust content stream prune test as rebase is a noop without ch…
mhsdesign Oct 25, 2024
29a27de
TASK: Always rebase during publication and do not copy events directly
mhsdesign Oct 25, 2024
e2b5652
DimensionSpacePoint events enriched
kitsunet Oct 25, 2024
0167efd
Just some linter happiness
kitsunet Oct 25, 2024
359a74e
TASK: Consistently use workspace instead of content graph in workspac…
mhsdesign Oct 25, 2024
4ee595e
TASK: Introduce `InitiatingEventMetadata` utility to centralise acces…
mhsdesign Oct 26, 2024
56fd230
TASK: Introduce ExtractedCommand vo to collect original commands AND …
mhsdesign Oct 26, 2024
f7c39ec
TASK: Combine `NodeAggregateEventPublisher` and `ExtractedCommand` to…
mhsdesign Oct 26, 2024
7430bbc
TASK: Add test that rebase keeps the originalCreated intact
mhsdesign Oct 26, 2024
4e26f33
TASK: Move `CommandHandlingDependencies` to CommandHandler namespace
mhsdesign Oct 26, 2024
f0ba01a
TASK: Dont pass `CommandHandlingDependencies` through half of the world
mhsdesign Oct 26, 2024
c62e6db
TASK: Update todos and require base content stream to be not closed d…
mhsdesign Oct 26, 2024
f6742de
TASK: Remove obsolete `ContentGraphReadModelInterface::buildContentGr…
mhsdesign Oct 26, 2024
d2d9faa
TASK: Turn partial publish into full publish if all nodes are about t…
mhsdesign Oct 26, 2024
936f39d
TASK: Update documentation
mhsdesign Oct 26, 2024
3679157
TASK: Revert currently unused error handling strategy from workspace …
mhsdesign Oct 26, 2024
8ad0a3e
FEATURE: Throw `WorkspaceRebaseFailed` during publication or partial …
mhsdesign Oct 26, 2024
49d5870
BUGFIX: Dont discard remaining user changes if $matchingCommands is e…
mhsdesign Oct 26, 2024
34395d8
TASK: Minor cosmetic adjustments and documentation
mhsdesign Oct 27, 2024
5339f97
TASK: Use `setRollbackOnly` to ensure nothing is commited during the …
mhsdesign Oct 28, 2024
f0e088e
TASK: Make publish a no-op if there are no changes instead of a rebase
mhsdesign Oct 28, 2024
5e12a48
TASK: Turn full discard also into a no-op if there are no changes
mhsdesign Oct 28, 2024
38835ca
TASK: Adjust comments to not reference renamed `NodeAggregateEventPub…
mhsdesign Oct 28, 2024
d442544
TASK: Make `CommandsThatFailed::sequenceNumber` internal only for tes…
mhsdesign Oct 28, 2024
08a0d67
Apply suggestions from code review
mhsdesign Oct 28, 2024
3761fc2
TASK: Declare `$handlers` of `CommandBus` private
mhsdesign Oct 28, 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 @@ -260,6 +260,24 @@ public function apply(EventInterface $event, EventEnvelope $eventEnvelope): void
}
}

/**
* @template T
* @param \Closure(): T $fn
* @return T
*/
public function inSimulation(\Closure $fn): mixed
{
if ($this->dbal->isTransactionActive()) {
kitsunet marked this conversation as resolved.
Show resolved Hide resolved
throw new \RuntimeException();
}
$this->dbal->beginTransaction();
try {
return $fn();
} finally {
$this->dbal->rollBack();
}
}

private function whenContentStreamWasClosed(ContentStreamWasClosed $event): void
{
$this->updateContentStreamStatus($event->contentStreamId, ContentStreamStatus::CLOSED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Feature: Rebasing auto-created nodes works
| propertyValues | {"text": {"value":"Modified","type":"string"}} |
| propertiesToUnset | {} |

# rebase of SetSerializedNodeProperties
# More than one node anchor point for content stream: b2a1d336-38a7-4183-815c-c49b2c7eba8c, node aggregate id: 7ef3c166-16d5-4aed-b8cb-5a44670607b7 and origin dimension space point: [] – this should not happen and might be a conceptual problem!
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
When the command RebaseWorkspace is executed with payload:
| Key | Value |
| workspaceName | "user-test" |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Feature: Individual node publication
Scenario: It is possible to publish a single node; and only this one is live.
# create nodes in user WS
Given I am in workspace "user-test"
And I am in workspace "user-test"
And I am in dimension space point {}
And the following CreateNodeAggregateWithNode commands are executed:
| nodeAggregateId | nodeTypeName | parentNodeAggregateId | nodeName | tetheredDescendantNodeAggregateIds |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,40 @@ Feature: Publishing individual nodes (basics)
| Key | Value |
| image | "Modified image" |

Scenario: It is possible to publish no node
When the command PublishIndividualNodesFromWorkspace is executed with payload:
| Key | Value |
| workspaceName | "user-test" |
| nodesToPublish | [] |
| contentStreamIdForRemainingPart | "user-cs-identifier-remaining" |

When I am in workspace "live" and dimension space point {}
Then I expect node aggregate identifier "sir-david-nodenborough" to lead to node cs-identifier;sir-david-nodenborough;{}
And I expect this node to have the following properties:
| Key | Value |
| text | "Initial t1" |
And I expect node aggregate identifier "nody-mc-nodeface" to lead to node cs-identifier;nody-mc-nodeface;{}
And I expect this node to have the following properties:
| Key | Value |
| text | "Initial t2" |
And I expect node aggregate identifier "sir-nodeward-nodington-iii" to lead to node cs-identifier;sir-nodeward-nodington-iii;{}
And I expect this node to have the following properties:
| Key | Value |
| image | "Initial image" |

When I am in workspace "user-test" and dimension space point {}
Then I expect node aggregate identifier "sir-david-nodenborough" to lead to node user-cs-identifier-remaining;sir-david-nodenborough;{}
And I expect this node to have the following properties:
| Key | Value |
| text | "Modified t1" |
Then I expect node aggregate identifier "nody-mc-nodeface" to lead to node user-cs-identifier-remaining;nody-mc-nodeface;{}
And I expect this node to have the following properties:
| Key | Value |
| text | "Modified t2" |
Then I expect node aggregate identifier "sir-nodeward-nodington-iii" to lead to node user-cs-identifier-remaining;sir-nodeward-nodington-iii;{}
And I expect this node to have the following properties:
| Key | Value |
| image | "Modified image" |
# Scenario: It is possible to publish no node
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
# When the command PublishIndividualNodesFromWorkspace is executed with payload:
# | Key | Value |
# | workspaceName | "user-test" |
# | nodesToPublish | [] |
# | contentStreamIdForRemainingPart | "user-cs-identifier-remaining" |
#
# When I am in workspace "live" and dimension space point {}
# Then I expect node aggregate identifier "sir-david-nodenborough" to lead to node cs-identifier;sir-david-nodenborough;{}
# And I expect this node to have the following properties:
# | Key | Value |
# | text | "Initial t1" |
# And I expect node aggregate identifier "nody-mc-nodeface" to lead to node cs-identifier;nody-mc-nodeface;{}
# And I expect this node to have the following properties:
# | Key | Value |
# | text | "Initial t2" |
# And I expect node aggregate identifier "sir-nodeward-nodington-iii" to lead to node cs-identifier;sir-nodeward-nodington-iii;{}
# And I expect this node to have the following properties:
# | Key | Value |
# | image | "Initial image" |
#
# When I am in workspace "user-test" and dimension space point {}
# Then I expect node aggregate identifier "sir-david-nodenborough" to lead to node user-cs-identifier-remaining;sir-david-nodenborough;{}
# And I expect this node to have the following properties:
# | Key | Value |
# | text | "Modified t1" |
# Then I expect node aggregate identifier "nody-mc-nodeface" to lead to node user-cs-identifier-remaining;nody-mc-nodeface;{}
# And I expect this node to have the following properties:
# | Key | Value |
# | text | "Modified t2" |
# Then I expect node aggregate identifier "sir-nodeward-nodington-iii" to lead to node user-cs-identifier-remaining;sir-nodeward-nodington-iii;{}
# And I expect this node to have the following properties:
# | Key | Value |
# | image | "Modified image" |

Scenario: It is possible to publish all nodes
When the command PublishIndividualNodesFromWorkspace is executed with payload:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

namespace Neos\ContentRepository\Core;

use Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjection;
use Neos\ContentRepository\Core\CommandHandler\CommandBus;
use Neos\ContentRepository\Core\CommandHandler\CommandInterface;
use Neos\ContentRepository\Core\CommandHandler\CommandResult;
use Neos\ContentRepository\Core\EventStore\EventNormalizer;
use Neos\ContentRepository\Core\EventStore\EventPersister;
use Neos\ContentRepository\Core\EventStore\EventsToPublish;
use Neos\ContentRepository\Core\Projection\ContentGraph\ContentGraphInterface;
Expand All @@ -24,6 +27,11 @@
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId;
use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamStatus;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\EventStore\Helper\InMemoryEventStore;
use Neos\EventStore\Model\Event\SequenceNumber;
use Neos\EventStore\Model\Events;
use Neos\EventStore\Model\EventStream\ExpectedVersion;
use Neos\EventStore\Model\EventStream\VirtualStreamName;
use Neos\EventStore\Model\Event\Version;

/**
Expand All @@ -40,15 +48,88 @@ final class CommandHandlingDependencies
*/
private array $overriddenContentGraphInstances = [];

private InMemoryEventStore|null $inMemoryStoreForSimulation = null;

public function __construct(
private readonly ContentRepository $contentRepository,
private readonly EventPersister $eventPersister
private readonly EventPersister $eventPersister,
private readonly CommandBus $commandBus,
private readonly EventNormalizer $eventNormalizer,
// todo use GraphProjectionInterface!!!
private readonly DoctrineDbalContentGraphProjection $contentRepositoryProjection
) {
}


public function handle(CommandInterface $command): CommandResult
{
return $this->contentRepository->handle($command);
if ($this->inMemoryStoreForSimulation !== null) {
$this->hanldeInSimulation($command, $this->inMemoryStoreForSimulation);
} else {
$this->contentRepository->handle($command);
}
return new CommandResult();
}

/**
* @template T
* @param \Closure(): T $fn
* @return T
*/
public function inSimulation(\Closure $fn, InMemoryEventStore $inMemoryEventStore): mixed
{
if ($this->inMemoryStoreForSimulation) {
throw new \RuntimeException();
}
$this->inMemoryStoreForSimulation = $inMemoryEventStore;
try {
return $this->contentRepositoryProjection->inSimulation($fn);
} finally {
$this->inMemoryStoreForSimulation = null;
}
}

private function hanldeInSimulation(CommandInterface $command, InMemoryEventStore $inMemoryEventStore): CommandResult
mhsdesign marked this conversation as resolved.
Show resolved Hide resolved
{
$eventsToPublish = $this->commandBus->handle($command, $this);

if ($eventsToPublish->events->isEmpty()) {
return new CommandResult();
}

// the following logic could also be done in an AppEventStore::commit method (being called
// directly from the individual Command Handlers).
$normalizedEvents = Events::fromArray(
$eventsToPublish->events->map($this->eventNormalizer->normalize(...))
);

$commitResult = $inMemoryEventStore->commit(
$eventsToPublish->streamName,
$normalizedEvents,
ExpectedVersion::ANY() // The version of the stream in the IN MEMORY event store does not matter to us,
// because this is only used in memory during the partial publish or rebase operation; so it cannot be written to
// concurrently.
// HINT: We cannot use $eventsToPublish->expectedVersion, because this is based on the PERSISTENT event stream (having different numbers)
);


$eventStream = $inMemoryEventStore->load(VirtualStreamName::all())->withMinimumSequenceNumber(
// fetch all events that were now committed. Plus one because the first sequence number is one too otherwise we get one event to many.
// (all elephants shall be placed shamefully placed on my head)
SequenceNumber::fromInteger($commitResult->highestCommittedSequenceNumber->value - $eventsToPublish->events->count() + 1)
);

foreach ($eventStream as $eventEnvelope) {
$event = $this->eventNormalizer->denormalize($eventEnvelope->event);

if (!$this->contentRepositoryProjection->canHandle($event)) {
continue;
}

$this->contentRepositoryProjection->apply($event, $eventEnvelope);
}

return new CommandResult();
}

public function publishEvents(EventsToPublish $eventsToPublish): void
Expand Down
3 changes: 2 additions & 1 deletion Neos.ContentRepository.Core/Classes/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Neos\ContentRepository\Core;

use Neos\ContentGraph\DoctrineDbalAdapter\DoctrineDbalContentGraphProjection;
use Neos\ContentRepository\Core\CommandHandler\CommandBus;
use Neos\ContentRepository\Core\CommandHandler\CommandInterface;
use Neos\ContentRepository\Core\CommandHandler\CommandResult;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function __construct(
private readonly UserIdProviderInterface $userIdProvider,
private readonly ClockInterface $clock,
) {
$this->commandHandlingDependencies = new CommandHandlingDependencies($this, $eventPersister);
$this->commandHandlingDependencies = new CommandHandlingDependencies($this, $eventPersister, $this->commandBus, $this->eventNormalizer, $this->projectionsAndCatchUpHooks->projections->get(DoctrineDbalContentGraphProjection::class));
}

/**
Expand Down
Loading
Loading