refactor: merge relational table projections into one handler (#11740)

## Problem description

During tests we found concurrency issues in the relational table
projections. Tests got flaky if a table (e.g. organization domains) had
too many foreign keys to tables which were projected by another handler.

## Resolution

The projections of the relational tables got merged into one handler to
enforce sequential reduction of events.

## Additional info

- closes https://github.com/zitadel/zitadel/issues/11703
- closes https://github.com/zitadel/zitadel/issues/10810

---------

Co-authored-by: Marco Ardizzone <[email protected]>
This commit is contained in:
Silvan
2026-03-10 17:01:46 +00:00
committed by GitHub
co-authored by Marco Ardizzone
parent 689b90d9d9
commit de1cab9976
30 changed files with 4174 additions and 4259 deletions
@@ -16,47 +16,7 @@ import (
"github.com/zitadel/zitadel/internal/zerrors"
)
type instanceDomainRelationalProjection struct{}
func newInstanceDomainRelationalProjection(ctx context.Context, config handler.Config) *handler.Handler {
return handler.NewHandler(ctx, &config, new(instanceDomainRelationalProjection))
}
func (*instanceDomainRelationalProjection) Name() string {
return "zitadel.instance_domains"
}
func (p *instanceDomainRelationalProjection) Reducers() []handler.AggregateReducer {
return []handler.AggregateReducer{
{
Aggregate: instance.AggregateType,
EventReducers: []handler.EventReducer{
{
Event: instance.InstanceDomainAddedEventType,
Reduce: p.reduceCustomDomainAdded,
},
{
Event: instance.InstanceDomainPrimarySetEventType,
Reduce: p.reduceDomainPrimarySet,
},
{
Event: instance.InstanceDomainRemovedEventType,
Reduce: p.reduceCustomDomainRemoved,
},
{
Event: instance.TrustedDomainAddedEventType,
Reduce: p.reduceTrustedDomainAdded,
},
{
Event: instance.TrustedDomainRemovedEventType,
Reduce: p.reduceTrustedDomainRemoved,
},
},
},
}
}
func (p *instanceDomainRelationalProjection) reduceCustomDomainAdded(event eventstore.Event) (*handler.Statement, error) {
func (p *relationalTablesProjection) reduceCustomInstanceDomainAdded(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.DomainAddedEvent)
if !ok {
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-DU0xF", "reduce.wrong.event.type %s", instance.InstanceDomainAddedEventType)
@@ -78,7 +38,7 @@ func (p *instanceDomainRelationalProjection) reduceCustomDomainAdded(event event
}), nil
}
func (p *instanceDomainRelationalProjection) reduceDomainPrimarySet(event eventstore.Event) (*handler.Statement, error) {
func (p *relationalTablesProjection) reduceInstanceDomainPrimarySet(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.DomainPrimarySetEvent)
if !ok {
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-TdEWA", "reduce.wrong.event.type %s", instance.InstanceDomainPrimarySetEventType)
@@ -103,7 +63,7 @@ func (p *instanceDomainRelationalProjection) reduceDomainPrimarySet(event events
}), nil
}
func (p *instanceDomainRelationalProjection) reduceCustomDomainRemoved(event eventstore.Event) (*handler.Statement, error) {
func (p *relationalTablesProjection) reduceCustomInstanceDomainRemoved(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.DomainRemovedEvent)
if !ok {
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-Hhcdl", "reduce.wrong.event.type %s", instance.InstanceDomainRemovedEventType)
@@ -125,7 +85,7 @@ func (p *instanceDomainRelationalProjection) reduceCustomDomainRemoved(event eve
}), nil
}
func (p *instanceDomainRelationalProjection) reduceTrustedDomainAdded(event eventstore.Event) (*handler.Statement, error) {
func (p *relationalTablesProjection) reduceTrustedInstanceDomainAdded(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.TrustedDomainAddedEvent)
if !ok {
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-svHDh", "reduce.wrong.event.type %s", instance.TrustedDomainAddedEventType)
@@ -145,7 +105,7 @@ func (p *instanceDomainRelationalProjection) reduceTrustedDomainAdded(event even
}), nil
}
func (p *instanceDomainRelationalProjection) reduceTrustedDomainRemoved(event eventstore.Event) (*handler.Statement, error) {
func (p *relationalTablesProjection) reduceTrustedInstanceDomainRemoved(event eventstore.Event) (*handler.Statement, error) {
e, ok := event.(*instance.TrustedDomainRemovedEvent)
if !ok {
return nil, zerrors.ThrowInvalidArgumentf(nil, "HANDL-4K74E", "reduce.wrong.event.type %s", instance.TrustedDomainRemovedEventType)