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,8 +5,7 @@ import (
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/handler"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/zitadel/internal/eventstore/handler/v2"
"github.com/zitadel/zitadel/internal/repository/instance"
"github.com/zitadel/zitadel/internal/repository/org"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -25,21 +24,21 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "reduceAdded",
args: args{
event: getEvent(testEvent(
repository.EventType(user.UserIDPLinkAddedType),
user.AggregateType,
[]byte(`{
event: getEvent(
testEvent(
user.UserIDPLinkAddedType,
user.AggregateType,
[]byte(`{
"idpConfigId": "idp-config-id",
"userId": "external-user-id",
"displayName": "gigi@caos.ch"
}`),
), user.UserIDPLinkAddedEventMapper),
), user.UserIDPLinkAddedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceAdded,
want: wantReduce{
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: user.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -63,20 +62,20 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "reduceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(user.UserIDPLinkRemovedType),
user.AggregateType,
[]byte(`{
event: getEvent(
testEvent(
user.UserIDPLinkRemovedType,
user.AggregateType,
[]byte(`{
"idpConfigId": "idp-config-id",
"userId": "external-user-id"
}`),
), user.UserIDPLinkRemovedEventMapper),
), user.UserIDPLinkRemovedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceRemoved,
want: wantReduce{
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: user.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -95,20 +94,20 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "reduceCascadeRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(user.UserIDPLinkCascadeRemovedType),
user.AggregateType,
[]byte(`{
event: getEvent(
testEvent(
user.UserIDPLinkCascadeRemovedType,
user.AggregateType,
[]byte(`{
"idpConfigId": "idp-config-id",
"userId": "external-user-id"
}`),
), user.UserIDPLinkCascadeRemovedEventMapper),
), user.UserIDPLinkCascadeRemovedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceCascadeRemoved,
want: wantReduce{
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: user.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -127,17 +126,17 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "reduceOwnerRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(org.OrgRemovedEventType),
org.AggregateType,
[]byte(`{}`),
), org.OrgRemovedEventMapper),
event: getEvent(
testEvent(
org.OrgRemovedEventType,
org.AggregateType,
[]byte(`{}`),
), org.OrgRemovedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceOwnerRemoved,
want: wantReduce{
aggregateType: org.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: org.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -154,17 +153,17 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "instance reduceInstanceRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.InstanceRemovedEventType),
instance.AggregateType,
nil,
), instance.InstanceRemovedEventMapper),
event: getEvent(
testEvent(
instance.InstanceRemovedEventType,
instance.AggregateType,
nil,
), instance.InstanceRemovedEventMapper),
},
reduce: reduceInstanceRemovedHelper(IDPUserLinkInstanceIDCol),
want: wantReduce{
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
previousSequence: 10,
aggregateType: eventstore.AggregateType("instance"),
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -180,17 +179,17 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "reduceUserRemoved",
args: args{
event: getEvent(testEvent(
repository.EventType(user.UserRemovedType),
user.AggregateType,
[]byte(`{}`),
), user.UserRemovedEventMapper),
event: getEvent(
testEvent(
user.UserRemovedType,
user.AggregateType,
[]byte(`{}`),
), user.UserRemovedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceUserRemoved,
want: wantReduce{
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: user.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -208,7 +207,7 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
name: "reduceExternalIDMigrated",
args: args{
event: getEvent(testEvent(
repository.EventType(user.UserIDPExternalIDMigratedType),
user.UserIDPExternalIDMigratedType,
user.AggregateType,
[]byte(`{
"idpConfigId": "idp-config-id",
@@ -219,9 +218,8 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
},
reduce: (&idpUserLinkProjection{}).reduceExternalIDMigrated,
want: wantReduce{
aggregateType: user.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: user.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -243,19 +241,19 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "org IDPConfigRemovedEvent",
args: args{
event: getEvent(testEvent(
repository.EventType(org.IDPConfigRemovedEventType),
org.AggregateType,
[]byte(`{
event: getEvent(
testEvent(
org.IDPConfigRemovedEventType,
org.AggregateType,
[]byte(`{
"idpConfigId": "idp-config-id"
}`),
), org.IDPConfigRemovedEventMapper),
), org.IDPConfigRemovedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceIDPConfigRemoved,
want: wantReduce{
aggregateType: org.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: org.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{
@@ -273,19 +271,19 @@ func TestIDPUserLinkProjection_reduces(t *testing.T) {
{
name: "iam IDPConfigRemovedEvent",
args: args{
event: getEvent(testEvent(
repository.EventType(instance.IDPConfigRemovedEventType),
instance.AggregateType,
[]byte(`{
event: getEvent(
testEvent(
instance.IDPConfigRemovedEventType,
instance.AggregateType,
[]byte(`{
"idpConfigId": "idp-config-id"
}`),
), instance.IDPConfigRemovedEventMapper),
), instance.IDPConfigRemovedEventMapper),
},
reduce: (&idpUserLinkProjection{}).reduceIDPConfigRemoved,
want: wantReduce{
aggregateType: instance.AggregateType,
sequence: 15,
previousSequence: 10,
aggregateType: instance.AggregateType,
sequence: 15,
executer: &testExecuter{
executions: []execution{
{