Skip to content

Commit

Permalink
services/horizon: Fix reingestion for the `history_{transaction,opera…
Browse files Browse the repository at this point in the history
…tion}_claimable_balances` tables (#3661)

* Update the db setup (migrations, tables, indexes, etc) for kahuna to match base

* refactor DeleteRangeAll to simplify it

* Also clear the history_*_claimable_balances tables in DeleteRangeAll for reingestion

Fixes #3659

* Update changelog

* Try with a map to clean up the loop
  • Loading branch information
Paul Bellamy authored Jun 7, 2021
1 parent 151c61e commit 1a050fd
Show file tree
Hide file tree
Showing 4 changed files with 407 additions and 55 deletions.
4 changes: 4 additions & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Code Changes

* Fix bug in `horizon db reingest range` command, which would throw a duplicate entry conflict error from the DB. ([3661](https://github.com/stellar/go/pull/3661)).

## v2.4.0

**Upgrading to this version from <= v2.1.1 will trigger a state rebuild. During this process (which can take up to 20 minutes), Horizon will not ingest new ledgers.**
Expand Down
43 changes: 15 additions & 28 deletions services/horizon/internal/db2/history/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,34 +826,21 @@ func (q *Q) CloneIngestionQ() IngestionQ {
// DeleteRangeAll deletes a range of rows from all history tables between
// `start` and `end` (exclusive).
func (q *Q) DeleteRangeAll(ctx context.Context, start, end int64) error {
err := q.DeleteRange(ctx, start, end, "history_effects", "history_operation_id")
if err != nil {
return errors.Wrap(err, "Error clearing history_effects")
for table, column := range map[string]string{
"history_effects": "history_operation_id",
"history_ledgers": "id",
"history_operation_claimable_balances": "history_operation_id",
"history_operation_participants": "history_operation_id",
"history_operations": "id",
"history_trades": "history_operation_id",
"history_transaction_claimable_balances": "history_transaction_id",
"history_transaction_participants": "history_transaction_id",
"history_transactions": "id",
} {
err := q.DeleteRange(ctx, start, end, table, column)
if err != nil {
return errors.Wrapf(err, "Error clearing %s", table)
}
}
err = q.DeleteRange(ctx, start, end, "history_operation_participants", "history_operation_id")
if err != nil {
return errors.Wrap(err, "Error clearing history_operation_participants")
}
err = q.DeleteRange(ctx, start, end, "history_operations", "id")
if err != nil {
return errors.Wrap(err, "Error clearing history_operations")
}
err = q.DeleteRange(ctx, start, end, "history_transaction_participants", "history_transaction_id")
if err != nil {
return errors.Wrap(err, "Error clearing history_transaction_participants")
}
err = q.DeleteRange(ctx, start, end, "history_transactions", "id")
if err != nil {
return errors.Wrap(err, "Error clearing history_transactions")
}
err = q.DeleteRange(ctx, start, end, "history_ledgers", "id")
if err != nil {
return errors.Wrap(err, "Error clearing history_ledgers")
}
err = q.DeleteRange(ctx, start, end, "history_trades", "history_operation_id")
if err != nil {
return errors.Wrap(err, "Error clearing history_trades")
}

return nil
}
6 changes: 3 additions & 3 deletions services/horizon/internal/test/scenarios/bindata.go

Large diffs are not rendered by default.

Loading

0 comments on commit 1a050fd

Please sign in to comment.