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

@@ -8,22 +8,19 @@ import (
"github.com/jackc/pgtype"
)
type StringArray []string
type TextArray[t ~string] []t
// Scan implements the [database/sql.Scanner] interface.
func (s *StringArray) Scan(src any) error {
func (s *TextArray[t]) Scan(src any) error {
array := new(pgtype.TextArray)
if err := array.Scan(src); err != nil {
return err
}
if err := array.AssignTo(s); err != nil {
return err
}
return nil
return array.AssignTo(s)
}
// Value implements the [database/sql/driver.Valuer] interface.
func (s StringArray) Value() (driver.Value, error) {
func (s TextArray[t]) Value() (driver.Value, error) {
if len(s) == 0 {
return nil, nil
}
@@ -36,37 +33,37 @@ func (s StringArray) Value() (driver.Value, error) {
return array.Value()
}
type enumField interface {
type arrayField interface {
~int8 | ~uint8 | ~int16 | ~uint16 | ~int32 | ~uint32
}
type EnumArray[F enumField] []F
type Array[F arrayField] []F
// Scan implements the [database/sql.Scanner] interface.
func (s *EnumArray[F]) Scan(src any) error {
array := new(pgtype.Int2Array)
func (a *Array[F]) Scan(src any) error {
array := new(pgtype.Int8Array)
if err := array.Scan(src); err != nil {
return err
}
ints := make([]int32, 0, len(array.Elements))
if err := array.AssignTo(&ints); err != nil {
elements := make([]int64, len(array.Elements))
if err := array.AssignTo(&elements); err != nil {
return err
}
*s = make([]F, len(ints))
for i, a := range ints {
(*s)[i] = F(a)
*a = make([]F, len(elements))
for i, element := range elements {
(*a)[i] = F(element)
}
return nil
}
// Value implements the [database/sql/driver.Valuer] interface.
func (s EnumArray[F]) Value() (driver.Value, error) {
if len(s) == 0 {
func (a Array[F]) Value() (driver.Value, error) {
if len(a) == 0 {
return nil, nil
}
array := pgtype.Int2Array{}
if err := array.Set(s); err != nil {
array := pgtype.Int8Array{}
if err := array.Set(a); err != nil {
return nil, err
}