Skip to content

Commit

Permalink
fix cutoff and update
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-crespo-fdc committed Aug 30, 2024
1 parent ea393c2 commit 10c16c0
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions services/cd-service/pkg/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,31 +855,23 @@ func (r *repository) ApplyTransformersInternal(ctx context.Context, transaction
}
t.SetEslVersion(db.TransformerID(internal.EslVersion))

if r.DB.WriteEslOnly {
if r.DB != nil && r.DB.WriteEslOnly {
// if we were previously running with `db.writeEslTableOnly=true`, but now are running with
// `db.writeEslTableOnly=false` (which is the recommended way to enable the database),
// then we would have many events in the event_sourcing_light table that have not been processed.
// So, if there is no cutoff yet, we write the current transformer to the cutoff, so it doesn't get processed:
// So, we write the cutoff if we are only writing to the esl table. Then, when the database is fully
// enabled, the cutoff is found and determined to be the latest transformer. When this happens,
// the export service takes over the duties of writing the cutoff

eslVersion, err := db.DBReadCutoff(r.DB, ctx, transaction)
err = db.DBWriteCutoff(r.DB, ctx, transaction, internal.EslVersion)
if err != nil {
applyErr := TransformerBatchApplyError{
TransformerError: err,
Index: i,
}
return nil, nil, nil, &applyErr
}
// only write if there is no cutoff yet:
if eslVersion == nil {
err = db.DBWriteCutoff(r.DB, ctx, transaction, internal.EslVersion)
if err != nil {
applyErr := TransformerBatchApplyError{
TransformerError: err,
Index: i,
}
return nil, nil, nil, &applyErr
}
}

}
}

Expand Down

0 comments on commit 10c16c0

Please sign in to comment.