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

@@ -5,6 +5,7 @@ import (
"database/sql"
"reflect"
"github.com/mitchellh/mapstructure"
"github.com/zitadel/logging"
_ "github.com/zitadel/zitadel/internal/database/cockroach"
@@ -14,8 +15,9 @@ import (
)
type Config struct {
Dialects map[string]interface{} `mapstructure:",remain"`
connector dialect.Connector
Dialects map[string]interface{} `mapstructure:",remain"`
EventPushConnRatio float32
connector dialect.Connector
}
func (c *Config) SetConnector(connector dialect.Connector) {
@@ -87,8 +89,18 @@ func (db *DB) QueryRowContext(ctx context.Context, scan func(row *sql.Row) error
return row.Err()
}
func Connect(config Config, useAdmin bool) (*DB, error) {
client, err := config.connector.Connect(useAdmin)
const (
zitadelAppName = "zitadel"
EventstorePusherAppName = "zitadel_es_pusher"
)
func Connect(config Config, useAdmin, isEventPusher bool) (*DB, error) {
appName := zitadelAppName
if isEventPusher {
appName = EventstorePusherAppName
}
client, err := config.connector.Connect(useAdmin, isEventPusher, config.EventPushConnRatio, appName)
if err != nil {
return nil, err
}
@@ -103,20 +115,20 @@ func Connect(config Config, useAdmin bool) (*DB, error) {
}, nil
}
func DecodeHook(from, to reflect.Value) (interface{}, error) {
func DecodeHook(from, to reflect.Value) (_ interface{}, err error) {
if to.Type() != reflect.TypeOf(Config{}) {
return from.Interface(), nil
}
configuredDialects, ok := from.Interface().(map[string]interface{})
if !ok {
return from.Interface(), nil
config := new(Config)
if err = mapstructure.Decode(from.Interface(), config); err != nil {
return nil, err
}
configuredDialect := dialect.SelectByConfig(configuredDialects)
configs := make([]interface{}, 0, len(configuredDialects)-1)
configuredDialect := dialect.SelectByConfig(config.Dialects)
configs := make([]interface{}, 0, len(config.Dialects)-1)
for name, dialectConfig := range configuredDialects {
for name, dialectConfig := range config.Dialects {
if !configuredDialect.Matcher.MatchName(name) {
continue
}
@@ -124,12 +136,12 @@ func DecodeHook(from, to reflect.Value) (interface{}, error) {
configs = append(configs, dialectConfig)
}
connector, err := configuredDialect.Matcher.Decode(configs)
config.connector, err = configuredDialect.Matcher.Decode(configs)
if err != nil {
return nil, err
}
return Config{connector: connector}, nil
return config, nil
}
func (c Config) DatabaseName() string {