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:
Silvan
2023-10-19 12:19:10 +02:00
committed by GitHub
parent 259faba3f0
commit b5564572bc
791 changed files with 30326 additions and 43202 deletions

View File

@@ -2,13 +2,11 @@ package instance
import (
"context"
"encoding/json"
"time"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
)
const (
@@ -19,15 +17,15 @@ const (
SecretGeneratorRemovedEventType = instanceEventTypePrefix + secretGeneratorPrefix + "removed"
)
func NewAddSecretGeneratorTypeUniqueConstraint(generatorType domain.SecretGeneratorType) *eventstore.EventUniqueConstraint {
func NewAddSecretGeneratorTypeUniqueConstraint(generatorType domain.SecretGeneratorType) *eventstore.UniqueConstraint {
return eventstore.NewAddEventUniqueConstraint(
UniqueSecretGeneratorType,
string(generatorType),
"Errors.SecretGenerator.AlreadyExists")
}
func NewRemoveSecretGeneratorTypeUniqueConstraint(generatorType domain.SecretGeneratorType) *eventstore.EventUniqueConstraint {
return eventstore.NewRemoveEventUniqueConstraint(
func NewRemoveSecretGeneratorTypeUniqueConstraint(generatorType domain.SecretGeneratorType) *eventstore.UniqueConstraint {
return eventstore.NewRemoveUniqueConstraint(
UniqueSecretGeneratorType,
string(generatorType))
}
@@ -71,19 +69,19 @@ func NewSecretGeneratorAddedEvent(
}
}
func (e *SecretGeneratorAddedEvent) Data() interface{} {
func (e *SecretGeneratorAddedEvent) Payload() interface{} {
return e
}
func (e *SecretGeneratorAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return []*eventstore.EventUniqueConstraint{NewAddSecretGeneratorTypeUniqueConstraint(e.GeneratorType)}
func (e *SecretGeneratorAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return []*eventstore.UniqueConstraint{NewAddSecretGeneratorTypeUniqueConstraint(e.GeneratorType)}
}
func SecretGeneratorAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
func SecretGeneratorAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
secretGeneratorAdded := &SecretGeneratorAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, secretGeneratorAdded)
err := event.Unmarshal(secretGeneratorAdded)
if err != nil {
return nil, errors.ThrowInternal(err, "IAM-en9f4", "unable to unmarshal secret generator added")
}
@@ -103,11 +101,11 @@ type SecretGeneratorChangedEvent struct {
IncludeSymbols *bool `json:"includeSymbols,omitempty"`
}
func (e *SecretGeneratorChangedEvent) Data() interface{} {
func (e *SecretGeneratorChangedEvent) Payload() interface{} {
return e
}
func (e *SecretGeneratorChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
func (e *SecretGeneratorChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
@@ -172,12 +170,12 @@ func ChangeSecretGeneratorIncludeSymbols(includeSymbols bool) func(event *Secret
}
}
func SecretGeneratorChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
func SecretGeneratorChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &SecretGeneratorChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
err := event.Unmarshal(e)
if err != nil {
return nil, errors.ThrowInternal(err, "IAM-2m09e", "unable to unmarshal secret generator changed")
}
@@ -191,12 +189,12 @@ type SecretGeneratorRemovedEvent struct {
GeneratorType domain.SecretGeneratorType `json:"generatorType"`
}
func (e *SecretGeneratorRemovedEvent) Data() interface{} {
func (e *SecretGeneratorRemovedEvent) Payload() interface{} {
return e
}
func (e *SecretGeneratorRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return []*eventstore.EventUniqueConstraint{NewRemoveSecretGeneratorTypeUniqueConstraint(e.GeneratorType)}
func (e *SecretGeneratorRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return []*eventstore.UniqueConstraint{NewRemoveSecretGeneratorTypeUniqueConstraint(e.GeneratorType)}
}
func NewSecretGeneratorRemovedEvent(
@@ -214,12 +212,12 @@ func NewSecretGeneratorRemovedEvent(
}
}
func SecretGeneratorRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
func SecretGeneratorRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
e := &SecretGeneratorRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
err := event.Unmarshal(e)
if err != nil {
return nil, errors.ThrowInternal(err, "IAM-m09ke", "unable to unmarshal secret generator removed")
}