mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37: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:
@@ -1,9 +1,8 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
iam_model "github.com/zitadel/zitadel/internal/iam/model"
|
||||
)
|
||||
@@ -32,8 +31,8 @@ func (p *DomainPolicy) Changes(changed *DomainPolicy) map[string]interface{} {
|
||||
return changes
|
||||
}
|
||||
|
||||
func (p *DomainPolicy) SetData(event *es_models.Event) error {
|
||||
err := json.Unmarshal(event.Data, p)
|
||||
func (p *DomainPolicy) SetData(event eventstore.Event) error {
|
||||
err := event.Unmarshal(p)
|
||||
if err != nil {
|
||||
return errors.ThrowInternal(err, "EVENT-7JS9d", "unable to unmarshal data")
|
||||
}
|
||||
|
@@ -1,20 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/database"
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -37,18 +34,18 @@ type IDPConfigView struct {
|
||||
IDPProviderType int32 `json:"-" gorm:"column:idp_provider_type"`
|
||||
AutoRegister bool `json:"autoRegister" gorm:"column:auto_register"`
|
||||
|
||||
IsOIDC bool `json:"-" gorm:"column:is_oidc"`
|
||||
OIDCClientID string `json:"clientId" gorm:"column:oidc_client_id"`
|
||||
OIDCClientSecret *crypto.CryptoValue `json:"clientSecret" gorm:"column:oidc_client_secret"`
|
||||
OIDCIssuer string `json:"issuer" gorm:"column:oidc_issuer"`
|
||||
OIDCScopes database.StringArray `json:"scopes" gorm:"column:oidc_scopes"`
|
||||
OIDCIDPDisplayNameMapping int32 `json:"idpDisplayNameMapping" gorm:"column:oidc_idp_display_name_mapping"`
|
||||
OIDCUsernameMapping int32 `json:"usernameMapping" gorm:"column:oidc_idp_username_mapping"`
|
||||
OAuthAuthorizationEndpoint string `json:"authorizationEndpoint" gorm:"column:oauth_authorization_endpoint"`
|
||||
OAuthTokenEndpoint string `json:"tokenEndpoint" gorm:"column:oauth_token_endpoint"`
|
||||
JWTEndpoint string `json:"jwtEndpoint" gorm:"jwt_endpoint"`
|
||||
JWTKeysEndpoint string `json:"keysEndpoint" gorm:"jwt_keys_endpoint"`
|
||||
JWTHeaderName string `json:"headerName" gorm:"jwt_header_name"`
|
||||
IsOIDC bool `json:"-" gorm:"column:is_oidc"`
|
||||
OIDCClientID string `json:"clientId" gorm:"column:oidc_client_id"`
|
||||
OIDCClientSecret *crypto.CryptoValue `json:"clientSecret" gorm:"column:oidc_client_secret"`
|
||||
OIDCIssuer string `json:"issuer" gorm:"column:oidc_issuer"`
|
||||
OIDCScopes database.TextArray[string] `json:"scopes" gorm:"column:oidc_scopes"`
|
||||
OIDCIDPDisplayNameMapping int32 `json:"idpDisplayNameMapping" gorm:"column:oidc_idp_display_name_mapping"`
|
||||
OIDCUsernameMapping int32 `json:"usernameMapping" gorm:"column:oidc_idp_username_mapping"`
|
||||
OAuthAuthorizationEndpoint string `json:"authorizationEndpoint" gorm:"column:oauth_authorization_endpoint"`
|
||||
OAuthTokenEndpoint string `json:"tokenEndpoint" gorm:"column:oauth_token_endpoint"`
|
||||
JWTEndpoint string `json:"jwtEndpoint" gorm:"jwt_endpoint"`
|
||||
JWTKeysEndpoint string `json:"keysEndpoint" gorm:"jwt_keys_endpoint"`
|
||||
JWTHeaderName string `json:"headerName" gorm:"jwt_header_name"`
|
||||
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
InstanceID string `json:"instanceID" gorm:"column:instance_id;primary_key"`
|
||||
@@ -86,13 +83,13 @@ func IDPConfigViewToModel(idp *IDPConfigView) *model.IDPConfigView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (i *IDPConfigView) AppendEvent(providerType model.IDPProviderType, event *models.Event) (err error) {
|
||||
i.Sequence = event.Sequence
|
||||
i.ChangeDate = event.CreationDate
|
||||
switch eventstore.EventType(event.Type) {
|
||||
func (i *IDPConfigView) AppendEvent(providerType model.IDPProviderType, event eventstore.Event) (err error) {
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.IDPConfigAddedEventType, org.IDPConfigAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreationDate
|
||||
i.CreationDate = event.CreatedAt()
|
||||
i.IDPProviderType = int32(providerType)
|
||||
err = i.SetData(event)
|
||||
case instance.IDPOIDCConfigAddedEventType, org.IDPOIDCConfigAddedEventType:
|
||||
@@ -111,13 +108,14 @@ func (i *IDPConfigView) AppendEvent(providerType model.IDPProviderType, event *m
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *IDPConfigView) setRootData(event *models.Event) {
|
||||
r.AggregateID = event.AggregateID
|
||||
r.InstanceID = event.InstanceID
|
||||
func (r *IDPConfigView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
r.InstanceID = event.Aggregate().InstanceID
|
||||
}
|
||||
|
||||
func (r *IDPConfigView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
func (r *IDPConfigView) SetData(event eventstore.Event) error {
|
||||
err := event.Unmarshal(r)
|
||||
if err != nil {
|
||||
logging.New().WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-lub6s", "Could not unmarshal data")
|
||||
}
|
||||
|
@@ -1,14 +1,12 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
"github.com/zitadel/zitadel/internal/repository/org"
|
||||
@@ -62,26 +60,26 @@ func IDPProviderViewsToModel(providers []*IDPProviderView) []*model.IDPProviderV
|
||||
return result
|
||||
}
|
||||
|
||||
func (i *IDPProviderView) AppendEvent(event *models.Event) (err error) {
|
||||
i.Sequence = event.Sequence
|
||||
i.ChangeDate = event.CreationDate
|
||||
switch eventstore.EventType(event.Type) {
|
||||
func (i *IDPProviderView) AppendEvent(event eventstore.Event) (err error) {
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.LoginPolicyIDPProviderAddedEventType,
|
||||
org.LoginPolicyIDPProviderAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreationDate
|
||||
i.CreationDate = event.CreatedAt()
|
||||
err = i.SetData(event)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *IDPProviderView) setRootData(event *models.Event) {
|
||||
r.AggregateID = event.AggregateID
|
||||
r.InstanceID = event.InstanceID
|
||||
func (r *IDPProviderView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
r.InstanceID = event.Aggregate().InstanceID
|
||||
}
|
||||
|
||||
func (r *IDPProviderView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
func (r *IDPProviderView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.New().WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
@@ -83,15 +82,15 @@ func (p *LabelPolicyView) ToDomain() *domain.LabelPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
func (i *LabelPolicyView) AppendEvent(event *models.Event) (err error) {
|
||||
func (i *LabelPolicyView) AppendEvent(event eventstore.Event) (err error) {
|
||||
asset := &AssetView{}
|
||||
i.Sequence = event.Sequence
|
||||
i.ChangeDate = event.CreationDate
|
||||
switch eventstore.EventType(event.Type) {
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.LabelPolicyAddedEventType,
|
||||
org.LabelPolicyAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreationDate
|
||||
i.CreationDate = event.CreatedAt()
|
||||
i.State = int32(domain.LabelPolicyStatePreview)
|
||||
err = i.SetData(event)
|
||||
case instance.LabelPolicyChangedEventType,
|
||||
@@ -172,21 +171,21 @@ func (i *LabelPolicyView) AppendEvent(event *models.Event) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *LabelPolicyView) setRootData(event *models.Event) {
|
||||
r.AggregateID = event.AggregateID
|
||||
r.InstanceID = event.InstanceID
|
||||
func (r *LabelPolicyView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
r.InstanceID = event.Aggregate().InstanceID
|
||||
}
|
||||
|
||||
func (r *LabelPolicyView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
func (r *LabelPolicyView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.Log("MODEL-Flp9C").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *AssetView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
func (r *AssetView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.Log("MODEL-Ms8f2").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
|
@@ -1,14 +1,12 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
caos_errs "github.com/zitadel/zitadel/internal/errors"
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/zitadel/zitadel/internal/iam/model"
|
||||
"github.com/zitadel/zitadel/internal/query"
|
||||
"github.com/zitadel/zitadel/internal/repository/instance"
|
||||
@@ -50,14 +48,14 @@ func PasswordComplexityViewToModel(policy *query.PasswordComplexityPolicy) *mode
|
||||
}
|
||||
}
|
||||
|
||||
func (i *PasswordComplexityPolicyView) AppendEvent(event *models.Event) (err error) {
|
||||
i.Sequence = event.Sequence
|
||||
i.ChangeDate = event.CreationDate
|
||||
switch eventstore.EventType(event.Type) {
|
||||
func (i *PasswordComplexityPolicyView) AppendEvent(event eventstore.Event) (err error) {
|
||||
i.Sequence = event.Sequence()
|
||||
i.ChangeDate = event.CreatedAt()
|
||||
switch event.Type() {
|
||||
case instance.PasswordComplexityPolicyAddedEventType,
|
||||
org.PasswordComplexityPolicyAddedEventType:
|
||||
i.setRootData(event)
|
||||
i.CreationDate = event.CreationDate
|
||||
i.CreationDate = event.CreatedAt()
|
||||
err = i.SetData(event)
|
||||
case instance.PasswordComplexityPolicyChangedEventType,
|
||||
org.PasswordComplexityPolicyChangedEventType:
|
||||
@@ -66,12 +64,12 @@ func (i *PasswordComplexityPolicyView) AppendEvent(event *models.Event) (err err
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *PasswordComplexityPolicyView) setRootData(event *models.Event) {
|
||||
r.AggregateID = event.AggregateID
|
||||
func (r *PasswordComplexityPolicyView) setRootData(event eventstore.Event) {
|
||||
r.AggregateID = event.Aggregate().ID
|
||||
}
|
||||
|
||||
func (r *PasswordComplexityPolicyView) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, r); err != nil {
|
||||
func (r *PasswordComplexityPolicyView) SetData(event eventstore.Event) error {
|
||||
if err := event.Unmarshal(r); err != nil {
|
||||
logging.Log("EVEN-Dmi9g").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-Hs8uf", "Could not unmarshal data")
|
||||
}
|
||||
|
Reference in New Issue
Block a user