mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:27:42 +00:00
feat(eventstore): increase parallel write capabilities (#5940)
This implementation increases parallel write capabilities of the eventstore. Please have a look at the technical advisories: [05](https://zitadel.com/docs/support/advisory/a10005) and [06](https://zitadel.com/docs/support/advisory/a10006). The implementation of eventstore.push is rewritten and stored events are migrated to a new table `eventstore.events2`. If you are using cockroach: make sure that the database user of ZITADEL has `VIEWACTIVITY` grant. This is used to query events.
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/crdb"
|
||||
old_handler "github.com/zitadel/zitadel/internal/eventstore/handler"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -45,55 +45,56 @@ const (
|
||||
LabelPolicyDarkIconURLCol = "dark_icon_url"
|
||||
)
|
||||
|
||||
type labelPolicyProjection struct {
|
||||
crdb.StatementHandler
|
||||
type labelPolicyProjection struct{}
|
||||
|
||||
func newLabelPolicyProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(labelPolicyProjection))
|
||||
}
|
||||
|
||||
func newLabelPolicyProjection(ctx context.Context, config crdb.StatementHandlerConfig) *labelPolicyProjection {
|
||||
p := new(labelPolicyProjection)
|
||||
config.ProjectionName = LabelPolicyTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(LabelPolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LabelPolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(LabelPolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(LabelPolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(LabelPolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(LabelPolicyHideLoginNameSuffixCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyWatermarkDisabledCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyShouldErrorPopupCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(LabelPolicyFontURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightPrimaryColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightWarnColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightBackgroundColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightFontColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightLogoURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyLightIconURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkPrimaryColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkWarnColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkBackgroundColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkFontColorCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkLogoURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyDarkIconURLCol, crdb.ColumnTypeText, crdb.Nullable()),
|
||||
crdb.NewColumn(LabelPolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*labelPolicyProjection) Name() string {
|
||||
return LabelPolicyTable
|
||||
}
|
||||
|
||||
func (*labelPolicyProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(LabelPolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LabelPolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LabelPolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(LabelPolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(LabelPolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(LabelPolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LabelPolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(LabelPolicyHideLoginNameSuffixCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyWatermarkDisabledCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyShouldErrorPopupCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(LabelPolicyFontURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightPrimaryColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightWarnColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightBackgroundColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightFontColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightLogoURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyLightIconURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkPrimaryColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkWarnColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkBackgroundColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkFontColorCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkLogoURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyDarkIconURLCol, handler.ColumnTypeText, handler.Nullable()),
|
||||
handler.NewColumn(LabelPolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(LabelPolicyInstanceIDCol, LabelPolicyIDCol, LabelPolicyStateCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{LabelPolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(LabelPolicyInstanceIDCol, LabelPolicyIDCol, LabelPolicyStateCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{LabelPolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *labelPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *labelPolicyProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.LabelPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -162,7 +163,7 @@ func (p *labelPolicyProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.LabelPolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -241,11 +242,11 @@ func (p *labelPolicyProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CSE7A", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyAddedEventType, instance.LabelPolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LabelPolicyCreationDateCol, policyEvent.CreatedAt()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, policyEvent.Sequence()),
|
||||
handler.NewCol(LabelPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
handler.NewCol(LabelPolicyStateCol, domain.LabelPolicyStatePreview),
|
||||
@@ -277,7 +278,7 @@ func (p *labelPolicyProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-qgVug", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyChangedEventType, instance.LabelPolicyChangedEventType})
|
||||
}
|
||||
cols := []handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, policyEvent.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, policyEvent.Sequence()),
|
||||
}
|
||||
if policyEvent.PrimaryColor != nil {
|
||||
@@ -313,7 +314,7 @@ func (p *labelPolicyProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
if policyEvent.DisableWatermark != nil {
|
||||
cols = append(cols, handler.NewCol(LabelPolicyWatermarkDisabledCol, *policyEvent.DisableWatermark))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -328,7 +329,7 @@ func (p *labelPolicyProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-ATMBz", "reduce.wrong.event.type %s", org.LabelPolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LabelPolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -343,7 +344,7 @@ func (p *labelPolicyProjection) reduceActivated(event eventstore.Event) (*handle
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dldEU", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyActivatedEventType, instance.LabelPolicyActivatedEventType})
|
||||
}
|
||||
return crdb.NewCopyStatement(
|
||||
return handler.NewCopyStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyInstanceIDCol, nil),
|
||||
@@ -351,7 +352,7 @@ func (p *labelPolicyProjection) reduceActivated(event eventstore.Event) (*handle
|
||||
handler.NewCol(LabelPolicyStateCol, nil),
|
||||
},
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(LabelPolicyStateCol, domain.LabelPolicyStateActive),
|
||||
handler.NewCol(LabelPolicyCreationDateCol, nil),
|
||||
@@ -424,10 +425,10 @@ func (p *labelPolicyProjection) reduceLogoAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-4wbOI", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyLogoAddedEventType, instance.LabelPolicyLogoAddedEventType, org.LabelPolicyLogoDarkAddedEventType, instance.LabelPolicyLogoDarkAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
storeKey,
|
||||
},
|
||||
@@ -453,10 +454,10 @@ func (p *labelPolicyProjection) reduceLogoRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-kg8H4", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyLogoRemovedEventType, instance.LabelPolicyLogoRemovedEventType, org.LabelPolicyLogoDarkRemovedEventType, instance.LabelPolicyLogoDarkRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(col, nil),
|
||||
},
|
||||
@@ -482,10 +483,10 @@ func (p *labelPolicyProjection) reduceIconAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-e2JFz", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyIconAddedEventType, instance.LabelPolicyIconAddedEventType, org.LabelPolicyIconDarkAddedEventType, instance.LabelPolicyIconDarkAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
storeKey,
|
||||
},
|
||||
@@ -511,10 +512,10 @@ func (p *labelPolicyProjection) reduceIconRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-gfgbY", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyIconRemovedEventType, instance.LabelPolicyIconRemovedEventType, org.LabelPolicyIconDarkRemovedEventType, instance.LabelPolicyIconDarkRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(col, nil),
|
||||
},
|
||||
@@ -536,10 +537,10 @@ func (p *labelPolicyProjection) reduceFontAdded(event eventstore.Event) (*handle
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-65i9W", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyFontAddedEventType, instance.LabelPolicyFontAddedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
storeKey,
|
||||
},
|
||||
@@ -561,10 +562,10 @@ func (p *labelPolicyProjection) reduceFontRemoved(event eventstore.Event) (*hand
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-xf32J", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyFontRemovedEventType, instance.LabelPolicyFontRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(col, nil),
|
||||
},
|
||||
@@ -583,10 +584,10 @@ func (p *labelPolicyProjection) reduceAssetsRemoved(event eventstore.Event) (*ha
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-qi39A", "reduce.wrong.event.type %v", []eventstore.EventType{org.LabelPolicyAssetsRemovedEventType, instance.LabelPolicyAssetsRemovedEventType})
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreationDate()),
|
||||
handler.NewCol(LabelPolicyChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(LabelPolicySequenceCol, event.Sequence()),
|
||||
handler.NewCol(LabelPolicyLightLogoURLCol, nil),
|
||||
handler.NewCol(LabelPolicyLightIconURLCol, nil),
|
||||
@@ -607,7 +608,7 @@ func (p *labelPolicyProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-Su6pX", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(LabelPolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
Reference in New Issue
Block a user