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,10 @@ package user
import (
"context"
"encoding/json"
"time"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore"
)
const (
@@ -33,11 +30,11 @@ type HumanRefreshTokenAddedEvent struct {
PreferredLanguage string `json:"preferredLanguage"`
}
func (e *HumanRefreshTokenAddedEvent) Data() interface{} {
func (e *HumanRefreshTokenAddedEvent) Payload() interface{} {
return e
}
func (e *HumanRefreshTokenAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
func (e *HumanRefreshTokenAddedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
@@ -78,11 +75,11 @@ func NewHumanRefreshTokenAddedEvent(
}
}
func HumanRefreshTokenAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
func HumanRefreshTokenAddedEventMapper(event eventstore.Event) (eventstore.Event, error) {
refreshTokenAdded := &HumanRefreshTokenAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, refreshTokenAdded)
err := event.Unmarshal(refreshTokenAdded)
if err != nil {
return nil, errors.ThrowInternal(err, "USER-DGr14", "unable to unmarshal refresh token added")
}
@@ -98,11 +95,11 @@ type HumanRefreshTokenRenewedEvent struct {
IdleExpiration time.Duration `json:"idleExpiration"`
}
func (e *HumanRefreshTokenRenewedEvent) Data() interface{} {
func (e *HumanRefreshTokenRenewedEvent) Payload() interface{} {
return e
}
func (e *HumanRefreshTokenRenewedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
func (e *HumanRefreshTokenRenewedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
@@ -129,11 +126,11 @@ func NewHumanRefreshTokenRenewedEvent(
}
}
func HumanRefreshTokenRenewedEventEventMapper(event *repository.Event) (eventstore.Event, error) {
func HumanRefreshTokenRenewedEventEventMapper(event eventstore.Event) (eventstore.Event, error) {
tokenAdded := &HumanRefreshTokenRenewedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, tokenAdded)
err := event.Unmarshal(tokenAdded)
if err != nil {
return nil, errors.ThrowInternal(err, "USER-GBt21", "unable to unmarshal refresh token renewed")
}
@@ -147,11 +144,11 @@ type HumanRefreshTokenRemovedEvent struct {
TokenID string `json:"tokenId"`
}
func (e *HumanRefreshTokenRemovedEvent) Data() interface{} {
func (e *HumanRefreshTokenRemovedEvent) Payload() interface{} {
return e
}
func (e *HumanRefreshTokenRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
func (e *HumanRefreshTokenRemovedEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
return nil
}
@@ -174,11 +171,11 @@ func NewHumanRefreshTokenRemovedEvent(
}
}
func HumanRefreshTokenRemovedEventEventMapper(event *repository.Event) (eventstore.Event, error) {
func HumanRefreshTokenRemovedEventEventMapper(event eventstore.Event) (eventstore.Event, error) {
tokenAdded := &HumanRefreshTokenRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, tokenAdded)
err := event.Unmarshal(tokenAdded)
if err != nil {
return nil, errors.ThrowInternal(err, "USER-Dggs2", "unable to unmarshal refresh token removed")
}