-
-
Notifications
You must be signed in to change notification settings - Fork 20
Feat: Async Batched Backfill #606
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c93473e
feat: async batched projection backfills
dgafka 68adb04
stream filtering
dgafka af22851
backfill batch
dgafka 83426c4
naming
dgafka 4ffbf3c
fixes
dgafka d4c54e9
async backfill
dgafka bd19bef
fixes
dgafka 0d51369
use stream filter
dgafka 18dd300
fixes
dgafka 05c9f4b
merge with main
dgafka 4828971
fixes
dgafka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
Monorepo/ExampleAppEventSourcing/EcotoneProjection/EcotoneConfiguration.php
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 11 additions & 14 deletions
25
...ing/src/Attribute/FromAggregateStream.php → ...ourcing/Attribute/FromAggregateStream.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,37 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * licence Enterprise | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ecotone\EventSourcing\Attribute; | ||
|
|
||
| use Attribute; | ||
| use Ecotone\EventSourcing\EventStore; | ||
| use Ecotone\Modelling\Attribute\EventSourcingAggregate; | ||
|
|
||
| /* | ||
| /** | ||
| * Configures a projection to read from an aggregate's event stream. | ||
| * Automatically reads Stream and AggregateType attributes from the aggregate class. | ||
| * | ||
| * This simplifies projection configuration by avoiding duplication of stream | ||
| * and aggregate type configuration that is already defined on the aggregate. | ||
| * Automatically resolves Stream and AggregateType from the aggregate class. | ||
| * | ||
| * Example usage: | ||
| * ```php | ||
| * #[ProjectionV2('order_list')] | ||
| * #[AggregateStream(Order::class)] | ||
| * #[FromAggregateStream(Order::class)] | ||
| * class OrderListProjection { ... } | ||
| * ``` | ||
| * | ||
| * licence Enterprise | ||
| */ | ||
| #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] | ||
| class FromAggregateStream | ||
| readonly class FromAggregateStream | ||
| { | ||
| /** | ||
| * @param class-string $aggregateClass The aggregate class to read Stream and AggregateType from. | ||
| * @param class-string $aggregateClass The aggregate class to read stream info from. | ||
| * Must be an EventSourcingAggregate. | ||
| * @param string $eventStoreReferenceName Reference name for the event store | ||
| */ | ||
| public function __construct( | ||
| public readonly string $aggregateClass, | ||
| public readonly string $eventStoreReferenceName = EventStore::class | ||
| public string $aggregateClass, | ||
| public string $eventStoreReferenceName = EventStore::class | ||
| ) { | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/Ecotone/src/Projecting/Attribute/ProjectionBackfill.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * licence Enterprise | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ecotone\Projecting\Attribute; | ||
|
|
||
| use Attribute; | ||
| use InvalidArgumentException; | ||
|
|
||
| /** | ||
| * Configure projection backfill settings. | ||
| * This attribute controls how partitions are batched during backfill operations. | ||
| */ | ||
| #[Attribute(Attribute::TARGET_CLASS)] | ||
| class ProjectionBackfill | ||
| { | ||
| public function __construct( | ||
| /** | ||
| * Number of partitions to process in a single batch during backfill. | ||
| * Must be at least 1. | ||
| */ | ||
| public readonly int $backfillPartitionBatchSize = 100, | ||
| /** | ||
| * Async channel name for backfill operations. | ||
| * When set, backfill batches are sent to this channel first, then routed to the backfill handler. | ||
| * When null, backfill executes synchronously. | ||
| */ | ||
| public readonly ?string $asyncChannelName = null, | ||
| ) { | ||
| if ($this->backfillPartitionBatchSize < 1) { | ||
| throw new InvalidArgumentException('Backfill partition batch size must be at least 1'); | ||
| } | ||
| } | ||
| } | ||
|
|
18 changes: 0 additions & 18 deletions
18
packages/Ecotone/src/Projecting/Attribute/ProjectionBatchSize.php
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
packages/Ecotone/src/Projecting/Attribute/ProjectionExecution.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * licence Enterprise | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ecotone\Projecting\Attribute; | ||
|
|
||
| use Attribute; | ||
|
|
||
| #[Attribute(Attribute::TARGET_CLASS)] | ||
| class ProjectionExecution | ||
| { | ||
| public function __construct( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed from ProjectionBatchSize attribute |
||
| /** | ||
| * Configure the batch size for loading events during projection execution. | ||
| * * This controls how many events are loaded from the stream in a single batch. | ||
| */ | ||
| public readonly int $eventLoadingBatchSize | ||
| ) | ||
| { | ||
| } | ||
| } | ||
56 changes: 56 additions & 0 deletions
56
packages/Ecotone/src/Projecting/BackfillExecutorHandler.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * licence Enterprise | ||
| */ | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Ecotone\Projecting; | ||
|
|
||
| use Ecotone\Messaging\Endpoint\Interceptor\TerminationListener; | ||
|
|
||
| /** | ||
| * Handles execution of projection backfill batches. | ||
| * This handler is invoked via MessagingEntrypoint to execute backfill operations | ||
| * for a given projection with specified limit and offset parameters. | ||
| */ | ||
| class BackfillExecutorHandler | ||
| { | ||
| public const BACKFILL_EXECUTOR_CHANNEL = 'ecotone.projection.backfill.executor'; | ||
|
|
||
| public function __construct( | ||
| private ProjectionRegistry $projectionRegistry, | ||
| private TerminationListener $terminationListener, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * Execute backfill for a specific partition batch. | ||
| * | ||
| * @param string $projectionName The name of the projection to backfill | ||
| * @param int|null $limit The maximum number of partitions to process in this batch (null for unlimited) | ||
| * @param int $offset The offset to start from | ||
| * @param string $streamName The stream name to filter partitions | ||
| * @param string|null $aggregateType The aggregate type to filter partitions (optional) | ||
| * @param string $eventStoreReferenceName The event store reference name | ||
| */ | ||
| public function executeBackfillBatch( | ||
| string $projectionName, | ||
| ?int $limit = null, | ||
| int $offset = 0, | ||
| string $streamName = '', | ||
| ?string $aggregateType = null, | ||
| string $eventStoreReferenceName = '', | ||
| ): void { | ||
| $projectingManager = $this->projectionRegistry->get($projectionName); | ||
| $streamFilter = new StreamFilter($streamName, $aggregateType, $eventStoreReferenceName); | ||
|
|
||
| foreach ($projectingManager->getPartitionProvider()->partitions($streamFilter, $limit, $offset) as $partition) { | ||
| $projectingManager->execute($partition, true); | ||
| if ($this->terminationListener->shouldTerminate()) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, those attributes are related to the pdo event sourcing module. If you want to project from another event source (let's say another event store implementation), you would create another attribute that would register its event store as an event source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They do not hold any database (pdo) specific, they just stand what stream should be used (maybe the aggregate-type is a bit specific, but it could be delivered as separate attribute).
So I think it's fine to allow it to be part of generic Projecton API?