fix(setup): init projections (#7194)

Even though this is a feature it's released as fix so that we can back port to earlier revisions.

As reported by multiple users startup of ZITADEL after leaded to downtime and worst case rollbacks to the previously deployed version.

The problem starts rising when there are too many events to process after the start of ZITADEL. The root cause are changes on projections (database tables) which must be recomputed. This PR solves this problem by adding a new step to the setup phase which prefills the projections. The step can be enabled by adding the `--init-projections`-flag to `setup`, `start-from-init` and `start-from-setup`. Setting this flag results in potentially longer duration of the setup phase but reduces the risk of the problems mentioned in the paragraph above.

(cherry picked from commit 17953e9040)
This commit is contained in:
Silvan
2024-01-25 17:28:20 +01:00
committed by Livio Spring
parent 50faf37921
commit d3bb9c9b3b
80 changed files with 1296 additions and 962 deletions

View File

@@ -19,7 +19,6 @@ type SearchQueryBuilder struct {
resourceOwner string
instanceID *string
instanceIDs []string
excludedInstanceIDs []string
editorUser string
queries []*SearchQuery
tx *sql.Tx
@@ -83,10 +82,6 @@ func (b SearchQueryBuilder) GetAwaitOpenTransactions() bool {
return b.awaitOpenTransactions
}
func (q SearchQueryBuilder) GetExcludedInstanceIDs() []string {
return q.excludedInstanceIDs
}
func (q SearchQueryBuilder) GetEventSequenceGreater() uint64 {
return q.eventSequenceGreater
}
@@ -289,12 +284,6 @@ func (builder *SearchQueryBuilder) SequenceGreater(sequence uint64) *SearchQuery
return builder
}
// ExcludedInstanceID filters for events not having the given instanceIDs
func (builder *SearchQueryBuilder) ExcludedInstanceID(instanceIDs ...string) *SearchQueryBuilder {
builder.excludedInstanceIDs = instanceIDs
return builder
}
// CreationDateAfter filters for events which happened after the specified time
func (builder *SearchQueryBuilder) CreationDateAfter(creationDate time.Time) *SearchQueryBuilder {
if creationDate.IsZero() || creationDate.Unix() == 0 {