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

@@ -6,11 +6,6 @@ import (
"time"
)
type Config struct {
Dialects map[string]interface{} `mapstructure:",remain"`
Dialect Matcher
}
type Dialect struct {
Matcher Matcher
Config Connector
@@ -29,7 +24,7 @@ type Matcher interface {
}
type Connector interface {
Connect(useAdmin bool) (*sql.DB, error)
Connect(useAdmin, isEventPusher bool, pusherRatio float32, appName string) (*sql.DB, error)
Password() string
Database
}

View File

@@ -0,0 +1,39 @@
package dialect
import "errors"
type ConnectionInfo struct {
EventstorePusher ConnectionConfig
ZITADEL ConnectionConfig
}
type ConnectionConfig struct {
MaxOpenConns,
MaxIdleConns uint32
}
func NewConnectionInfo(openConns, idleConns uint32, pusherRatio float64) (*ConnectionInfo, error) {
if pusherRatio < 0 || pusherRatio > 1 {
return nil, errors.New("EventPushConnRatio must be between 0 and 1")
}
if openConns < 2 {
return nil, errors.New("MaxOpenConns of the database must be higher that 1")
}
info := new(ConnectionInfo)
info.EventstorePusher.MaxOpenConns = uint32(pusherRatio * float64(openConns))
info.EventstorePusher.MaxIdleConns = uint32(pusherRatio * float64(idleConns))
if info.EventstorePusher.MaxOpenConns < 1 && pusherRatio > 0 {
info.EventstorePusher.MaxOpenConns = 1
}
if info.EventstorePusher.MaxIdleConns < 1 && pusherRatio > 0 {
info.EventstorePusher.MaxIdleConns = 1
}
info.ZITADEL.MaxOpenConns = openConns - info.EventstorePusher.MaxOpenConns
info.ZITADEL.MaxIdleConns = idleConns - info.EventstorePusher.MaxIdleConns
return info, nil
}