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:
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -28,42 +28,43 @@ const (
|
||||
SMTPConfigColumnSMTPPassword = "password"
|
||||
)
|
||||
|
||||
type smtpConfigProjection struct {
|
||||
crdb.StatementHandler
|
||||
type smtpConfigProjection struct{}
|
||||
|
||||
func newSMTPConfigProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
return handler.NewHandler(ctx, &config, new(smtpConfigProjection))
|
||||
}
|
||||
|
||||
func newSMTPConfigProjection(ctx context.Context, config crdb.StatementHandlerConfig) *smtpConfigProjection {
|
||||
p := new(smtpConfigProjection)
|
||||
config.ProjectionName = SMTPConfigProjectionTable
|
||||
config.Reducers = p.reducers()
|
||||
config.InitCheck = crdb.NewTableCheck(
|
||||
crdb.NewTable([]*crdb.Column{
|
||||
crdb.NewColumn(SMTPConfigColumnAggregateID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnCreationDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SMTPConfigColumnChangeDate, crdb.ColumnTypeTimestamp),
|
||||
crdb.NewColumn(SMTPConfigColumnSequence, crdb.ColumnTypeInt64),
|
||||
crdb.NewColumn(SMTPConfigColumnResourceOwner, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnInstanceID, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnTLS, crdb.ColumnTypeBool),
|
||||
crdb.NewColumn(SMTPConfigColumnSenderAddress, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSenderName, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnReplyToAddress, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSMTPHost, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSMTPUser, crdb.ColumnTypeText),
|
||||
crdb.NewColumn(SMTPConfigColumnSMTPPassword, crdb.ColumnTypeJSONB, crdb.Nullable()),
|
||||
func (*smtpConfigProjection) Name() string {
|
||||
return SMTPConfigProjectionTable
|
||||
}
|
||||
|
||||
func (*smtpConfigProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(SMTPConfigColumnAggregateID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnCreationDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SMTPConfigColumnChangeDate, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(SMTPConfigColumnSequence, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(SMTPConfigColumnResourceOwner, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnInstanceID, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnTLS, handler.ColumnTypeBool),
|
||||
handler.NewColumn(SMTPConfigColumnSenderAddress, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSenderName, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnReplyToAddress, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSMTPHost, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSMTPUser, handler.ColumnTypeText),
|
||||
handler.NewColumn(SMTPConfigColumnSMTPPassword, handler.ColumnTypeJSONB, handler.Nullable()),
|
||||
},
|
||||
crdb.NewPrimaryKey(SMTPConfigColumnInstanceID, SMTPConfigColumnAggregateID),
|
||||
handler.NewPrimaryKey(SMTPConfigColumnInstanceID, SMTPConfigColumnAggregateID),
|
||||
),
|
||||
)
|
||||
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *smtpConfigProjection) reducers() []handler.AggregateReducer {
|
||||
func (p *smtpConfigProjection) Reducers() []handler.AggregateReducer {
|
||||
return []handler.AggregateReducer{
|
||||
{
|
||||
Aggregate: instance.AggregateType,
|
||||
EventRedusers: []handler.EventReducer{
|
||||
EventReducers: []handler.EventReducer{
|
||||
{
|
||||
Event: instance.SMTPConfigAddedEventType,
|
||||
Reduce: p.reduceSMTPConfigAdded,
|
||||
@@ -94,7 +95,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigAdded(event eventstore.Event) (*h
|
||||
if !ok {
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-sk99F", "reduce.wrong.event.type %s", instance.SMTPConfigAddedEventType)
|
||||
}
|
||||
return crdb.NewCreateStatement(
|
||||
return handler.NewCreateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMTPConfigColumnAggregateID, e.Aggregate().ID),
|
||||
@@ -141,7 +142,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigChanged(event eventstore.Event) (
|
||||
if e.User != nil {
|
||||
columns = append(columns, handler.NewCol(SMTPConfigColumnSMTPUser, *e.User))
|
||||
}
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
columns,
|
||||
[]handler.Condition{
|
||||
@@ -157,7 +158,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigPasswordChanged(event eventstore.
|
||||
return nil, errors.ThrowInvalidArgumentf(nil, "HANDL-fk02f", "reduce.wrong.event.type %s", instance.SMTPConfigChangedEventType)
|
||||
}
|
||||
|
||||
return crdb.NewUpdateStatement(
|
||||
return handler.NewUpdateStatement(
|
||||
e,
|
||||
[]handler.Column{
|
||||
handler.NewCol(SMTPConfigColumnChangeDate, e.CreationDate()),
|
||||
@@ -176,7 +177,7 @@ func (p *smtpConfigProjection) reduceSMTPConfigRemoved(event eventstore.Event) (
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return crdb.NewDeleteStatement(
|
||||
return handler.NewDeleteStatement(
|
||||
e,
|
||||
[]handler.Condition{
|
||||
handler.NewCond(SMTPConfigColumnAggregateID, e.Aggregate().ID),
|
||||
|
Reference in New Issue
Block a user