mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 20:57:31 +00:00
fix(eventstore): precise decimal (#8527)
# Which Problems Are Solved Float64 which was used for the event.Position field is [not precise in go and gets rounded](https://github.com/golang/go/issues/47300). This can lead to unprecies position tracking of events and therefore projections especially on cockcoachdb as the position used there is a big number. example of a unprecies position: exact: 1725257931223002628 float64: 1725257931223002624.000000 # How the Problems Are Solved The float64 was replaced by [github.com/jackc/pgx-shopspring-decimal](https://github.com/jackc/pgx-shopspring-decimal). # Additional Changes Correct behaviour of makefile for load tests. Rename `latestSequence`-queries to `latestPosition`
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/api/call"
|
||||
@@ -26,7 +27,7 @@ type Stateful interface {
|
||||
type State struct {
|
||||
LastRun time.Time
|
||||
|
||||
Position float64
|
||||
Position decimal.Decimal
|
||||
EventCreatedAt time.Time
|
||||
AggregateID string
|
||||
AggregateType eventstore.AggregateType
|
||||
@@ -221,7 +222,7 @@ func prepareLatestState(ctx context.Context, db prepareDatabase) (sq.SelectBuild
|
||||
var (
|
||||
creationDate sql.NullTime
|
||||
lastUpdated sql.NullTime
|
||||
position sql.NullFloat64
|
||||
position decimal.NullDecimal
|
||||
)
|
||||
err := row.Scan(
|
||||
&creationDate,
|
||||
@@ -234,7 +235,7 @@ func prepareLatestState(ctx context.Context, db prepareDatabase) (sq.SelectBuild
|
||||
return &State{
|
||||
EventCreatedAt: creationDate.Time,
|
||||
LastRun: lastUpdated.Time,
|
||||
Position: position.Float64,
|
||||
Position: position.Decimal,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -259,7 +260,7 @@ func prepareCurrentStateQuery(ctx context.Context, db prepareDatabase) (sq.Selec
|
||||
var (
|
||||
lastRun sql.NullTime
|
||||
eventDate sql.NullTime
|
||||
currentPosition sql.NullFloat64
|
||||
currentPosition decimal.NullDecimal
|
||||
aggregateType sql.NullString
|
||||
aggregateID sql.NullString
|
||||
sequence sql.NullInt64
|
||||
@@ -280,7 +281,7 @@ func prepareCurrentStateQuery(ctx context.Context, db prepareDatabase) (sq.Selec
|
||||
}
|
||||
currentState.State.EventCreatedAt = eventDate.Time
|
||||
currentState.State.LastRun = lastRun.Time
|
||||
currentState.Position = currentPosition.Float64
|
||||
currentState.Position = currentPosition.Decimal
|
||||
currentState.AggregateType = eventstore.AggregateType(aggregateType.String)
|
||||
currentState.AggregateID = aggregateID.String
|
||||
currentState.Sequence = uint64(sequence.Int64)
|
||||
|
Reference in New Issue
Block a user