mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 19:07:30 +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:
@@ -1,27 +1,24 @@
|
||||
package idpconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"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 (
|
||||
UniqueIDPConfigNameType = "idp_config_names"
|
||||
)
|
||||
|
||||
func NewAddIDPConfigNameUniqueConstraint(idpConfigName, resourceOwner string) *eventstore.EventUniqueConstraint {
|
||||
func NewAddIDPConfigNameUniqueConstraint(idpConfigName, resourceOwner string) *eventstore.UniqueConstraint {
|
||||
return eventstore.NewAddEventUniqueConstraint(
|
||||
UniqueIDPConfigNameType,
|
||||
idpConfigName+resourceOwner,
|
||||
"Errors.IDPConfig.AlreadyExists")
|
||||
}
|
||||
|
||||
func NewRemoveIDPConfigNameUniqueConstraint(idpConfigName, resourceOwner string) *eventstore.EventUniqueConstraint {
|
||||
return eventstore.NewRemoveEventUniqueConstraint(
|
||||
func NewRemoveIDPConfigNameUniqueConstraint(idpConfigName, resourceOwner string) *eventstore.UniqueConstraint {
|
||||
return eventstore.NewRemoveUniqueConstraint(
|
||||
UniqueIDPConfigNameType,
|
||||
idpConfigName+resourceOwner)
|
||||
}
|
||||
@@ -54,20 +51,20 @@ func NewIDPConfigAddedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func (e *IDPConfigAddedEvent) Data() interface{} {
|
||||
func (e *IDPConfigAddedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *IDPConfigAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{NewAddIDPConfigNameUniqueConstraint(e.Name, e.Aggregate().ResourceOwner)}
|
||||
func (e *IDPConfigAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return []*eventstore.UniqueConstraint{NewAddIDPConfigNameUniqueConstraint(e.Name, e.Aggregate().ResourceOwner)}
|
||||
}
|
||||
|
||||
func IDPConfigAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func IDPConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &IDPConfigAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
@@ -85,15 +82,15 @@ type IDPConfigChangedEvent struct {
|
||||
oldName string `json:"-"`
|
||||
}
|
||||
|
||||
func (e *IDPConfigChangedEvent) Data() interface{} {
|
||||
func (e *IDPConfigChangedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *IDPConfigChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *IDPConfigChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
if e.oldName == "" {
|
||||
return nil
|
||||
}
|
||||
return []*eventstore.EventUniqueConstraint{
|
||||
return []*eventstore.UniqueConstraint{
|
||||
NewRemoveIDPConfigNameUniqueConstraint(e.oldName, e.Aggregate().ResourceOwner),
|
||||
NewAddIDPConfigNameUniqueConstraint(*e.Name, e.Aggregate().ResourceOwner),
|
||||
}
|
||||
@@ -139,12 +136,12 @@ func ChangeAutoRegister(autoRegister bool) func(*IDPConfigChangedEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
func IDPConfigChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func IDPConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &IDPConfigChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
@@ -169,20 +166,20 @@ func NewIDPConfigDeactivatedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func (e *IDPConfigDeactivatedEvent) Data() interface{} {
|
||||
func (e *IDPConfigDeactivatedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *IDPConfigDeactivatedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *IDPConfigDeactivatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func IDPConfigDeactivatedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func IDPConfigDeactivatedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &IDPConfigDeactivatedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
@@ -207,20 +204,20 @@ func NewIDPConfigReactivatedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func (e *IDPConfigReactivatedEvent) Data() interface{} {
|
||||
func (e *IDPConfigReactivatedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *IDPConfigReactivatedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *IDPConfigReactivatedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
func IDPConfigReactivatedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func IDPConfigReactivatedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &IDPConfigReactivatedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
@@ -248,20 +245,20 @@ func NewIDPConfigRemovedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func (e *IDPConfigRemovedEvent) Data() interface{} {
|
||||
func (e *IDPConfigRemovedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *IDPConfigRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
return []*eventstore.EventUniqueConstraint{NewRemoveIDPConfigNameUniqueConstraint(e.name, e.Aggregate().ResourceOwner)}
|
||||
func (e *IDPConfigRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return []*eventstore.UniqueConstraint{NewRemoveIDPConfigNameUniqueConstraint(e.name, e.Aggregate().ResourceOwner)}
|
||||
}
|
||||
|
||||
func IDPConfigRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func IDPConfigRemovedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &IDPConfigRemovedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
|
@@ -1,12 +1,9 @@
|
||||
package idpconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,11 +21,11 @@ type JWTConfigAddedEvent struct {
|
||||
HeaderName string `json:"headerName,omitempty"`
|
||||
}
|
||||
|
||||
func (e *JWTConfigAddedEvent) Data() interface{} {
|
||||
func (e *JWTConfigAddedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *JWTConfigAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *JWTConfigAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -50,12 +47,12 @@ func NewJWTConfigAddedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func JWTConfigAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func JWTConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &JWTConfigAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "JWT-m0fwf", "unable to unmarshal event")
|
||||
}
|
||||
@@ -74,11 +71,11 @@ type JWTConfigChangedEvent struct {
|
||||
HeaderName *string `json:"headerName,omitempty"`
|
||||
}
|
||||
|
||||
func (e *JWTConfigChangedEvent) Data() interface{} {
|
||||
func (e *JWTConfigChangedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *JWTConfigChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *JWTConfigChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -126,12 +123,12 @@ func ChangeHeaderName(headerName string) func(*JWTConfigChangedEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
func JWTConfigChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func JWTConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &JWTConfigChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "JWT-fk3fs", "unable to unmarshal event")
|
||||
}
|
||||
|
@@ -1,14 +1,10 @@
|
||||
package idpconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,11 +27,11 @@ type OIDCConfigAddedEvent struct {
|
||||
UserNameMapping domain.OIDCMappingField `json:"usernameMapping,omitempty"`
|
||||
}
|
||||
|
||||
func (e *OIDCConfigAddedEvent) Data() interface{} {
|
||||
func (e *OIDCConfigAddedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *OIDCConfigAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *OIDCConfigAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,12 +62,12 @@ func NewOIDCConfigAddedEvent(
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCConfigAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func OIDCConfigAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &OIDCConfigAddedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
@@ -95,11 +91,11 @@ type OIDCConfigChangedEvent struct {
|
||||
UserNameMapping *domain.OIDCMappingField `json:"usernameMapping,omitempty"`
|
||||
}
|
||||
|
||||
func (e *OIDCConfigChangedEvent) Data() interface{} {
|
||||
func (e *OIDCConfigChangedEvent) Payload() interface{} {
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *OIDCConfigChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
|
||||
func (e *OIDCConfigChangedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -171,12 +167,12 @@ func ChangeScopes(scopes []string) func(*OIDCConfigChangedEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
func OIDCConfigChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
||||
func OIDCConfigChangedEventMapper(event eventstore.Event) (eventstore.Event, error) {
|
||||
e := &OIDCConfigChangedEvent{
|
||||
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(event.Data, e)
|
||||
err := event.Unmarshal(e)
|
||||
if err != nil {
|
||||
return nil, errors.ThrowInternal(err, "OIDC-plaBZ", "unable to unmarshal event")
|
||||
}
|
||||
|
Reference in New Issue
Block a user