mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +00:00
fix: scheduling (#3978)
* fix: improve scheduling * build pre-release * fix: locker * fix: user handler and print stack in case of panic in reducer * chore: remove sentry * fix: improve handler projection and implement tests * more tests * fix: race condition in tests * Update internal/eventstore/repository/sql/query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: implemented suggested changes * fix: lock statement Co-authored-by: Silvan <silvan.reusser@gmail.com>
This commit is contained in:
@@ -8,8 +8,8 @@ import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
repository "github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
repository "github.com/zitadel/zitadel/internal/eventstore/repository"
|
||||
)
|
||||
|
||||
// MockRepository is a mock of Repository interface.
|
||||
@@ -78,6 +78,21 @@ func (mr *MockRepositoryMockRecorder) Health(arg0 interface{}) *gomock.Call {
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Health", reflect.TypeOf((*MockRepository)(nil).Health), arg0)
|
||||
}
|
||||
|
||||
// InstanceIDs mocks base method.
|
||||
func (m *MockRepository) InstanceIDs(arg0 context.Context, arg1 *repository.SearchQuery) ([]string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "InstanceIDs", arg0, arg1)
|
||||
ret0, _ := ret[0].([]string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// InstanceIDs indicates an expected call of InstanceIDs.
|
||||
func (mr *MockRepositoryMockRecorder) InstanceIDs(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstanceIDs", reflect.TypeOf((*MockRepository)(nil).InstanceIDs), arg0, arg1)
|
||||
}
|
||||
|
||||
// LatestSequence mocks base method.
|
||||
func (m *MockRepository) LatestSequence(arg0 context.Context, arg1 *repository.SearchQuery) (uint64, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@@ -29,6 +29,16 @@ func (m *MockRepository) ExpectFilterEventsError(err error) *MockRepository {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockRepository) ExpectInstanceIDs(instanceIDs ...string) *MockRepository {
|
||||
m.EXPECT().InstanceIDs(gomock.Any(), gomock.Any()).Return(instanceIDs, nil)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockRepository) ExpectInstanceIDsError(err error) *MockRepository {
|
||||
m.EXPECT().InstanceIDs(gomock.Any(), gomock.Any()).Return(nil, err)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MockRepository) ExpectPush(expectedEvents []*repository.Event, expectedUniqueConstraints ...*repository.UniqueConstraint) *MockRepository {
|
||||
m.EXPECT().Push(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(
|
||||
func(ctx context.Context, events []*repository.Event, uniqueConstraints ...*repository.UniqueConstraint) error {
|
||||
|
@@ -8,14 +8,16 @@ import (
|
||||
type Repository interface {
|
||||
//Health checks if the connection to the storage is available
|
||||
Health(ctx context.Context) error
|
||||
// PushEvents adds all events of the given aggregates to the eventstreams of the aggregates.
|
||||
// Push adds all events of the given aggregates to the event streams of the aggregates.
|
||||
// if unique constraints are pushed, they will be added to the unique table for checking unique constraint violations
|
||||
// This call is transaction save. The transaction will be rolled back if one event fails
|
||||
Push(ctx context.Context, events []*Event, uniqueConstraints ...*UniqueConstraint) error
|
||||
// Filter returns all events matching the given search query
|
||||
Filter(ctx context.Context, searchQuery *SearchQuery) (events []*Event, err error)
|
||||
//LatestSequence returns the latests sequence found by the the search query
|
||||
//LatestSequence returns the latest sequence found by the search query
|
||||
LatestSequence(ctx context.Context, queryFactory *SearchQuery) (uint64, error)
|
||||
//InstanceIDs returns the instance ids found by the search query
|
||||
InstanceIDs(ctx context.Context, queryFactory *SearchQuery) ([]string, error)
|
||||
//CreateInstance creates a new sequence for the given instance
|
||||
CreateInstance(ctx context.Context, instanceID string) error
|
||||
}
|
||||
|
@@ -23,6 +23,8 @@ const (
|
||||
ColumnsEvent = iota + 1
|
||||
//ColumnsMaxSequence represents the latest sequence of the filtered events
|
||||
ColumnsMaxSequence
|
||||
// ColumnsInstanceIDs represents the instance ids of the filtered events
|
||||
ColumnsInstanceIDs
|
||||
|
||||
columnsCount
|
||||
)
|
||||
|
@@ -218,7 +218,7 @@ func (db *CRDB) Filter(ctx context.Context, searchQuery *repository.SearchQuery)
|
||||
return events, nil
|
||||
}
|
||||
|
||||
//LatestSequence returns the latests sequence found by the the search query
|
||||
//LatestSequence returns the latest sequence found by the search query
|
||||
func (db *CRDB) LatestSequence(ctx context.Context, searchQuery *repository.SearchQuery) (uint64, error) {
|
||||
var seq Sequence
|
||||
err := query(ctx, db, searchQuery, &seq)
|
||||
@@ -228,6 +228,16 @@ func (db *CRDB) LatestSequence(ctx context.Context, searchQuery *repository.Sear
|
||||
return uint64(seq), nil
|
||||
}
|
||||
|
||||
//InstanceIDs returns the instance ids found by the search query
|
||||
func (db *CRDB) InstanceIDs(ctx context.Context, searchQuery *repository.SearchQuery) ([]string, error) {
|
||||
var ids []string
|
||||
err := query(ctx, db, searchQuery, &ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
func (db *CRDB) db() *sql.DB {
|
||||
return db.client
|
||||
}
|
||||
@@ -262,6 +272,10 @@ func (db *CRDB) maxSequenceQuery() string {
|
||||
return "SELECT MAX(event_sequence) FROM eventstore.events"
|
||||
}
|
||||
|
||||
func (db *CRDB) instanceIDsQuery() string {
|
||||
return "SELECT DISTINCT instance_id FROM eventstore.events"
|
||||
}
|
||||
|
||||
func (db *CRDB) columnName(col repository.Field) string {
|
||||
switch col {
|
||||
case repository.FieldAggregateID:
|
||||
|
@@ -22,6 +22,7 @@ type querier interface {
|
||||
placeholder(query string) string
|
||||
eventQuery() string
|
||||
maxSequenceQuery() string
|
||||
instanceIDsQuery() string
|
||||
db() *sql.DB
|
||||
orderByEventSequence(desc bool) string
|
||||
}
|
||||
@@ -36,7 +37,7 @@ func query(ctx context.Context, criteria querier, searchQuery *repository.Search
|
||||
}
|
||||
query += where
|
||||
|
||||
if searchQuery.Columns != repository.ColumnsMaxSequence {
|
||||
if searchQuery.Columns == repository.ColumnsEvent {
|
||||
query += criteria.orderByEventSequence(searchQuery.Desc)
|
||||
}
|
||||
|
||||
@@ -76,6 +77,8 @@ func prepareColumns(criteria querier, columns repository.Columns) (string, func(
|
||||
switch columns {
|
||||
case repository.ColumnsMaxSequence:
|
||||
return criteria.maxSequenceQuery(), maxSequenceScanner
|
||||
case repository.ColumnsInstanceIDs:
|
||||
return criteria.instanceIDsQuery(), instanceIDsScanner
|
||||
case repository.ColumnsEvent:
|
||||
return criteria.eventQuery(), eventsScanner
|
||||
default:
|
||||
@@ -95,6 +98,22 @@ func maxSequenceScanner(row scan, dest interface{}) (err error) {
|
||||
return z_errors.ThrowInternal(err, "SQL-bN5xg", "something went wrong")
|
||||
}
|
||||
|
||||
func instanceIDsScanner(scanner scan, dest interface{}) (err error) {
|
||||
ids, ok := dest.(*[]string)
|
||||
if !ok {
|
||||
return z_errors.ThrowInvalidArgument(nil, "SQL-Begh2", "type must be an array of string")
|
||||
}
|
||||
var id string
|
||||
err = scanner(&id)
|
||||
if err != nil {
|
||||
logging.WithError(err).Warn("unable to scan row")
|
||||
return z_errors.ThrowInternal(err, "SQL-DEFGe", "unable to scan row")
|
||||
}
|
||||
*ids = append(*ids, id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func eventsScanner(scanner scan, dest interface{}) (err error) {
|
||||
events, ok := dest.(*[]*repository.Event)
|
||||
if !ok {
|
||||
@@ -157,7 +176,7 @@ func prepareCondition(criteria querier, filters [][]*repository.Filter) (clause
|
||||
var err error
|
||||
value, err = json.Marshal(value)
|
||||
if err != nil {
|
||||
logging.New().WithError(err).Warn("unable to marshal search value")
|
||||
logging.WithError(err).Warn("unable to marshal search value")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user