mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:47: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"
|
||||
"github.com/zitadel/zitadel/internal/repository/policy"
|
||||
@@ -29,41 +29,42 @@ const (
|
||||
AgePolicyOwnerRemovedCol = "owner_removed"
|
||||
)
|
||||
|
||||
type passwordAgeProjection struct {
|
||||
crdb.StatementHandler
|
||||
type passwordAgeProjection struct{}
|
||||
|
||||
func newPasswordAgeProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(passwordAgeProjection))
|
||||
}
|
||||
|
||||
func newPasswordAgeProjection(ctx context.Context, config crdb.StatementHandlerConfig) *passwordAgeProjection {
|
||||
p := new(passwordAgeProjection)
|
||||
config.ProjectionName = PasswordAgeTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(AgePolicyIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AgePolicyCreationDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AgePolicyChangeDateCol, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(AgePolicySequenceCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AgePolicyStateCol, crdb.ColumnTypeEnum),
|
||||
crdb.NewColumn(AgePolicyIsDefaultCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
crdb.NewColumn(AgePolicyResourceOwnerCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AgePolicyInstanceIDCol, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(AgePolicyExpireWarnDaysCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AgePolicyMaxAgeDaysCol, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(AgePolicyOwnerRemovedCol, crdb.ColumnTypeBool, crdb.Default(false)),
|
||||
func (*passwordAgeProjection) Name() string {
|
||||
return PasswordAgeTable
|
||||
}
|
||||
|
||||
func (*passwordAgeProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(AgePolicyIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AgePolicyCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AgePolicyChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(AgePolicySequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AgePolicyStateCol, handler.ColumnTypeEnum),
|
||||
handler.NewColumn(AgePolicyIsDefaultCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
handler.NewColumn(AgePolicyResourceOwnerCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AgePolicyInstanceIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(AgePolicyExpireWarnDaysCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AgePolicyMaxAgeDaysCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(AgePolicyOwnerRemovedCol, handler.ColumnTypeBool, handler.Default(false)),
|
||||
},
|
||||
crdb.NewPrimaryKey(AgePolicyInstanceIDCol, AgePolicyIDCol),
|
||||
crdb.WithIndex(crdb.NewIndex("owner_removed", []string{AgePolicyOwnerRemovedCol})),
|
||||
handler.NewPrimaryKey(AgePolicyInstanceIDCol, AgePolicyIDCol),
|
||||
handler.WithIndex(handler.NewIndex("owner_removed", []string{AgePolicyOwnerRemovedCol})),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *passwordAgeProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *passwordAgeProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: org.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: org.PasswordAgePolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -84,7 +85,7 @@ func (p *passwordAgeProjection) reducers() []handler.AggregateReducer {
|
||||
},
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.PasswordAgePolicyAddedEventType,
|
||||
Reduce: p.reduceAdded,
|
||||
@@ -115,7 +116,7 @@ func (p *passwordAgeProjection) reduceAdded(event eventstore.Event) (*handler.St
|
||||
default:
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-CJqF0", "reduce.wrong.event.type %v", []eventstore.EventType{org.PasswordAgePolicyAddedEventType, instance.PasswordAgePolicyAddedEventType})
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
&policyEvent,
|
||||
[]handler.Column{
|
||||
handler.NewCol(AgePolicyCreationDateCol, policyEvent.CreationDate()),
|
||||
@@ -151,7 +152,7 @@ func (p *passwordAgeProjection) reduceChanged(event eventstore.Event) (*handler.
|
||||
if policyEvent.MaxAgeDays != nil {
|
||||
cols = append(cols, handler.NewCol(AgePolicyMaxAgeDaysCol, *policyEvent.MaxAgeDays))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
&policyEvent,
|
||||
cols,
|
||||
[]handler.Condition{
|
||||
@@ -165,7 +166,7 @@ func (p *passwordAgeProjection) reduceRemoved(event eventstore.Event) (*handler.
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-EtHWB", "reduce.wrong.event.type %s", org.PasswordAgePolicyRemovedEventType)
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
policyEvent,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AgePolicyIDCol, policyEvent.Aggregate().ID),
|
||||
@@ -179,7 +180,7 @@ func (p *passwordAgeProjection) reduceOwnerRemoved(event eventstore.Event) (*han
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "PROJE-edLs2", "reduce.wrong.event.type %s", org.OrgRemovedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(AgePolicyInstanceIDCol, e.Aggregate().InstanceID),
|
||||
|
Reference in New Issue
Block a user