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:
@@ -2,7 +2,6 @@ package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
@@ -12,7 +11,6 @@ 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/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -56,12 +54,12 @@ type HumanAddedEvent struct {
|
||||
ChangeRequired bool `json:"changeRequired,omitempty"`
|
||||
}
|
||||
|
||||
func (e *HumanAddedEvent) Data() interface{} {
|
||||
func (e *HumanAddedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *HumanAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{NewAddUsernameUniqueConstraint(e.UserName, e.Aggregate().ResourceOwner, e.userLoginMustBeDomain)}
|
||||
func (e *HumanAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return []*eventstore.UniqueConstraint{NewAddUsernameUniqueConstraint(e.UserName, e.Aggregate().ResourceOwner, e.userLoginMustBeDomain)}
|
||||
}
|
||||
|
||||
func (e *HumanAddedEvent) AddAddressData(
|
||||
@@ -124,13 +122,13 @@ func NewHumanAddedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func HumanAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
humanAdded := &HumanAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, humanAdded)
|
||||
err := event.Unmarshal(humanAdded)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "USER-5Gm9s", "unable to unmarshal human added")
|
||||
return nil, errors.ThrowInternal(err, "USER-vGlhy", "unable to unmarshal human added")
|
||||
}
|
||||
|
||||
return humanAdded, nil
|
||||
@@ -161,12 +159,12 @@ type HumanRegisteredEvent struct {
|
||||
ChangeRequired bool `json:"changeRequired,omitempty"`
|
||||
}
|
||||
|
||||
func (e *HumanRegisteredEvent) Data() interface{} {
|
||||
func (e *HumanRegisteredEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *HumanRegisteredEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{NewAddUsernameUniqueConstraint(e.UserName, e.Aggregate().ResourceOwner, e.userLoginMustBeDomain)}
|
||||
func (e *HumanRegisteredEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return []*eventstore.UniqueConstraint{NewAddUsernameUniqueConstraint(e.UserName, e.Aggregate().ResourceOwner, e.userLoginMustBeDomain)}
|
||||
}
|
||||
|
||||
func (e *HumanRegisteredEvent) AddAddressData(
|
||||
@@ -229,11 +227,11 @@ func NewHumanRegisteredEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func HumanRegisteredEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanRegisteredEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
humanRegistered := &HumanRegisteredEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, humanRegistered)
|
||||
err := event.Unmarshal(humanRegistered)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "USER-3Vm9s", "unable to unmarshal human registered")
|
||||
}
|
||||
@@ -248,11 +246,11 @@ type HumanInitialCodeAddedEvent struct {
|
||||
TriggeredAtOrigin string `json:"triggerOrigin,omitempty"`
|
||||
}
|
||||
|
||||
func (e *HumanInitialCodeAddedEvent) Data() interface{} {
|
||||
func (e *HumanInitialCodeAddedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *HumanInitialCodeAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *HumanInitialCodeAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -278,11 +276,11 @@ func NewHumanInitialCodeAddedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func HumanInitialCodeAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanInitialCodeAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
humanRegistered := &HumanInitialCodeAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, humanRegistered)
|
||||
err := event.Unmarshal(humanRegistered)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "USER-bM9se", "unable to unmarshal human initial code added")
|
||||
}
|
||||
@@ -294,11 +292,11 @@ type HumanInitialCodeSentEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
}
|
||||
|
||||
func (e *HumanInitialCodeSentEvent) Data() interface{} {
|
||||
func (e *HumanInitialCodeSentEvent) Payload() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *HumanInitialCodeSentEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *HumanInitialCodeSentEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -312,7 +310,7 @@ func NewHumanInitialCodeSentEvent(ctx context.Context, aggregate *eventstore.Agg
|
||||
}
|
||||
}
|
||||
|
||||
func HumanInitialCodeSentEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanInitialCodeSentEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
return &HumanInitialCodeSentEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
@@ -322,11 +320,11 @@ type HumanInitializedCheckSucceededEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
}
|
||||
|
||||
func (e *HumanInitializedCheckSucceededEvent) Data() interface{} {
|
||||
func (e *HumanInitializedCheckSucceededEvent) Payload() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *HumanInitializedCheckSucceededEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *HumanInitializedCheckSucceededEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -340,7 +338,7 @@ func NewHumanInitializedCheckSucceededEvent(ctx context.Context, aggregate *even
|
||||
}
|
||||
}
|
||||
|
||||
func HumanInitializedCheckSucceededEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanInitializedCheckSucceededEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
return &HumanInitializedCheckSucceededEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
@@ -350,11 +348,11 @@ type HumanInitializedCheckFailedEvent struct {
|
||||
eventstore.BaseEvent `json:"-"`
|
||||
}
|
||||
|
||||
func (e *HumanInitializedCheckFailedEvent) Data() interface{} {
|
||||
func (e *HumanInitializedCheckFailedEvent) Payload() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *HumanInitializedCheckFailedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *HumanInitializedCheckFailedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -368,7 +366,7 @@ func NewHumanInitializedCheckFailedEvent(ctx context.Context, aggregate *eventst
|
||||
}
|
||||
}
|
||||
|
||||
func HumanInitializedCheckFailedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanInitializedCheckFailedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
return &HumanInitializedCheckFailedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}, nil
|
||||
@@ -380,11 +378,11 @@ type HumanSignedOutEvent struct {
|
||||
UserAgentID string `json:"userAgentID"`
|
||||
}
|
||||
|
||||
func (e *HumanSignedOutEvent) Data() interface{} {
|
||||
func (e *HumanSignedOutEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *HumanSignedOutEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *HumanSignedOutEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -403,11 +401,11 @@ func NewHumanSignedOutEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func HumanSignedOutEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func HumanSignedOutEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
signedOut := &HumanSignedOutEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
err := json.Unmarshal(event.Data, signedOut)
|
||||
err := event.Unmarshal(signedOut)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "USER-WFS3g", "unable to unmarshal human signed out")
|
||||
}
|
||||
|
Reference in New Issue
Block a user