fix(eventstore): use decimal, correct mirror (#9914)

# Eventstore fixes

- `event.Position` used float64 before which can lead to [precision
loss](https://github.com/golang/go/issues/47300). The type got replaced
by [a type without precision
loss](https://github.com/jackc/pgx-shopspring-decimal)
- the handler reported the wrong error if the current state was updated
and therefore took longer to retry failed events.

# Mirror fixes

- max age of auth requests can be configured to speed up copying data
from `auth.auth_requests` table. Auth requests last updated before the
set age will be ignored. Default is 1 month
- notification projections are skipped because notifications should be
sent by the source system. The projections are set to the latest
position
- ensure that mirror can be executed multiple times

---------

Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
Silvan
2025-05-28 23:54:18 +02:00
committed by GitHub
parent 046b165db8
commit 131f70db34
51 changed files with 436 additions and 236 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"testing"
"github.com/shopspring/decimal"
"github.com/zitadel/zitadel/internal/eventstore"
)
@@ -131,7 +133,7 @@ func TestEventstore_Filter(t *testing.T) {
}
}
func TestEventstore_LatestSequence(t *testing.T) {
func TestEventstore_LatestPosition(t *testing.T) {
type args struct {
searchQuery *eventstore.SearchQueryBuilder
}
@@ -139,7 +141,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
existingEvents []eventstore.Command
}
type res struct {
sequence float64
position decimal.Decimal
}
tests := []struct {
name string
@@ -151,7 +153,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
{
name: "aggregate type filter no sequence",
args: args{
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxSequence).
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxPosition).
AddQuery().
AggregateTypes("not found").
Builder(),
@@ -168,7 +170,7 @@ func TestEventstore_LatestSequence(t *testing.T) {
{
name: "aggregate type filter sequence",
args: args{
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxSequence).
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxPosition).
AddQuery().
AggregateTypes(eventstore.AggregateType(t.Name())).
Builder(),
@@ -202,12 +204,12 @@ func TestEventstore_LatestSequence(t *testing.T) {
return
}
sequence, err := db.LatestSequence(context.Background(), tt.args.searchQuery)
position, err := db.LatestPosition(context.Background(), tt.args.searchQuery)
if (err != nil) != tt.wantErr {
t.Errorf("eventstore.query() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.res.sequence > sequence {
t.Errorf("eventstore.query() expected sequence: %v got %v", tt.res.sequence, sequence)
if tt.res.position.GreaterThan(position) {
t.Errorf("eventstore.query() expected position: %v got %v", tt.res.position, position)
}
})
}