mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +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:
@@ -29,6 +29,11 @@ type Migration interface {
|
||||
Execute(context.Context) error
|
||||
}
|
||||
|
||||
type errCheckerMigration interface {
|
||||
Migration
|
||||
ContinueOnErr(err error) bool
|
||||
}
|
||||
|
||||
type RepeatableMigration interface {
|
||||
Migration
|
||||
SetLastExecution(lastRun map[string]interface{})
|
||||
@@ -38,20 +43,33 @@ type RepeatableMigration interface {
|
||||
func Migrate(ctx context.Context, es *eventstore.Eventstore, migration Migration) (err error) {
|
||||
logging.WithFields("name", migration.String()).Info("verify migration")
|
||||
|
||||
if should, err := checkExec(ctx, es, migration); !should || err != nil {
|
||||
return err
|
||||
continueOnErr := func(err error) bool {
|
||||
return false
|
||||
}
|
||||
errChecker, ok := migration.(errCheckerMigration)
|
||||
if ok {
|
||||
continueOnErr = errChecker.ContinueOnErr
|
||||
}
|
||||
|
||||
if _, err = es.Push(ctx, setupStartedCmd(migration)); err != nil {
|
||||
// if should, err := checkExec(ctx, es, migration); !should || err != nil {
|
||||
should, err := checkExec(ctx, es, migration)
|
||||
if err != nil && !continueOnErr(err) {
|
||||
return err
|
||||
}
|
||||
if !should {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err = es.Push(ctx, setupStartedCmd(ctx, migration)); err != nil && !continueOnErr(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.WithFields("name", migration.String()).Info("starting migration")
|
||||
err = migration.Execute(ctx)
|
||||
logging.OnError(err).Error("migration failed")
|
||||
logging.WithFields("name", migration.String()).OnError(err).Error("migration failed")
|
||||
|
||||
_, pushErr := es.Push(ctx, setupDoneCmd(ctx, migration, err))
|
||||
logging.OnError(pushErr).Error("migration failed")
|
||||
logging.WithFields("name", migration.String()).OnError(pushErr).Error("migration finish failed")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -127,6 +145,7 @@ func checkExec(ctx context.Context, es *eventstore.Eventstore, migration Migrati
|
||||
func shouldExec(ctx context.Context, es *eventstore.Eventstore, migration Migration) (should bool, err error) {
|
||||
events, err := es.Filter(ctx, eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
OrderAsc().
|
||||
InstanceID("").
|
||||
AddQuery().
|
||||
AggregateTypes(aggregateType).
|
||||
AggregateIDs(aggregateID).
|
||||
|
Reference in New Issue
Block a user