mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 13:01:38 +00:00
fix(mirror): ensure multiple runs (#9899)
1. After second execution, mirror starts to fail because of Primary key constraints on the events table. Because mirror always took the the first `system.mirror.succeeded` instead of the newest one 2. Mirror panicked during migration of fields tables 1. Adjusted the database query to order descending and limit 1 2. added missing assignment - detailed logging if the copy from statement failed.
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -172,6 +173,10 @@ func copyEvents(ctx context.Context, source, dest *db.DB, bulkSize uint32) {
|
||||
tag, err := conn.PgConn().CopyFrom(ctx, reader, "COPY eventstore.events2 FROM STDIN")
|
||||
eventCount = tag.RowsAffected()
|
||||
if err != nil {
|
||||
pgErr := new(pgconn.PgError)
|
||||
errors.As(err, &pgErr)
|
||||
|
||||
logging.WithError(err).WithField("pg_err_details", pgErr.Detail).Error("unable to copy events into destination")
|
||||
return zerrors.ThrowUnknown(err, "MIGRA-DTHi7", "unable to copy events into destination")
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,10 @@ func projections(
|
||||
logging.OnError(err).Fatal("unable create static storage")
|
||||
|
||||
config.Eventstore.Querier = old_es.NewCRDB(client)
|
||||
config.Eventstore.Pusher = new_es.NewEventstore(client)
|
||||
newES := new_es.NewEventstore(client)
|
||||
config.Eventstore.Pusher = newES
|
||||
config.Eventstore.Searcher = newES
|
||||
|
||||
es := eventstore.NewEventstore(config.Eventstore)
|
||||
esV4 := es_v4.NewEventstoreFromOne(es_v4_pg.New(client, &es_v4_pg.Config{
|
||||
MaxRetries: config.Eventstore.MaxRetries,
|
||||
|
@@ -36,6 +36,7 @@ func (p *LastSuccessfulMirror) Filter() *eventstore.Filter {
|
||||
),
|
||||
eventstore.FilterPagination(
|
||||
eventstore.Descending(),
|
||||
eventstore.Limit(1),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user