mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +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"
|
||||
)
|
||||
@@ -27,40 +27,41 @@ const (
|
||||
OrgDomainOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type orgDomainProjection struct {
|
||||
crdb.StatementHandler
|
||||
type orgDomainProjection struct{}
|
||||
|
||||
func newOrgDomainProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(orgDomainProjection))
|
||||
}
|
||||
|
||||
func newOrgDomainProjection(ctx context.Context, config crdb.StatementHandlerConfig) *orgDomainProjection {
|
||||
p := new(orgDomainProjection)
|
||||
config.ProjectionName = OrgDomainTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(OrgDomainOrgIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgDomainInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgDomainCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgDomainChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(OrgDomainSequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(OrgDomainDomainCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(OrgDomainIsVerifiedCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(OrgDomainIsPrimaryCol, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(OrgDomainValidationTypeCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(OrgDomainOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*orgDomainProjection) Name() string {
|
||||
return OrgDomainTable
|
||||
}
|
||||
|
||||
func (*orgDomainProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(OrgDomainOrgIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgDomainInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgDomainCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgDomainChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(OrgDomainSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(OrgDomainDomainCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(OrgDomainIsVerifiedCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(OrgDomainIsPrimaryCol, handler.ColumnTypeBool),
|
||||
handler.NewColumn(OrgDomainValidationTypeCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(OrgDomainOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(OrgDomainOrgIDCol, OrgDomainDomainCol, OrgDomainInstanceIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{OrgDomainOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(OrgDomainOrgIDCol, OrgDomainDomainCol, OrgDomainInstanceIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{OrgDomainOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *orgDomainProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *orgDomainProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.OrgDomainAddedEventType,
|
||||
Reduce: p.reduceDomainAdded,
|
||||
@@ -89,7 +90,7 @@ func (p *orgDomainProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.InstanceRemovedEventType,
|
||||
Reduce: reduceInstanceRemovedHelper(OrgDomainInstanceIDCol),
|
||||
@@ -104,7 +105,7 @@ func (p *orgDomainProjection) reduceDomainAdded(event eventstore.Event) (*handle
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-DM2DI", "reduce.wrong.event.type %s", org.OrgDomainAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainCreationDateCol, e.CreationDate()),
|
||||
@@ -125,7 +126,7 @@ func (p *orgDomainProjection) reduceDomainVerificationAdded(event eventstore.Eve
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-EBzyu", "reduce.wrong.event.type %s", org.OrgDomainVerificationAddedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
@@ -145,7 +146,7 @@ func (p *orgDomainProjection) reduceDomainVerified(event eventstore.Event) (*han
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-3Rvkr", "reduce.wrong.event.type %s", org.OrgDomainVerifiedEventType)
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
@@ -165,9 +166,9 @@ func (p *orgDomainProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-aIuei", "reduce.wrong.event.type %s", org.OrgDomainPrimarySetEventType)
|
||||
}
|
||||
return crdb.NewMultiStatement(
|
||||
return handler.NewMultiStatement(
|
||||
e,
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
|
||||
@@ -179,7 +180,7 @@ func (p *orgDomainProjection) reducePrimaryDomainSet(event eventstore.Event) (*h
|
||||
handler.NewCond(OrgDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
},
|
||||
),
|
||||
crdb.AddUpdateStatement(
|
||||
handler.AddUpdateStatement(
|
||||
[]handler.Column{
|
||||
handler.NewCol(OrgDomainChangeDateCol, e.CreationDate()),
|
||||
handler.NewCol(OrgDomainSequenceCol, e.Sequence()),
|
||||
@@ -199,7 +200,7 @@ func (p *orgDomainProjection) reduceDomainRemoved(event eventstore.Event) (*hand
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-gh1Mx", "reduce.wrong.event.type %s", org.OrgDomainRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgDomainDomainCol, e.Domain),
|
||||
@@ -215,7 +216,7 @@ func (p *orgDomainProjection) reduceOwnerRemoved(event eventstore.Event) (*handl
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-dMUKJ", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(OrgDomainInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
Reference in New Issue
Block a user