Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix horizon db reap command #2336

Merged
merged 4 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

* Fix `horizon db reap` bug which caused the command to exit without deleting any history table rows.
* The horizon reap system now also deletes rows from `history_trades`. Previously, the reap system only deleted rows from `history_operation_participants`, `history_operations`, `history_transaction_participants`, `history_transactions`, `history_ledgers`, and `history_effects`.

## 1.0.0

### Before you upgrade
Expand Down
4 changes: 3 additions & 1 deletion services/horizon/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ var dbReapCmd = &cobra.Command{
Short: "reaps (i.e. removes) any reapable history data",
Long: "reap removes any historical data that is earlier than the configured retention cutoff",
Run: func(cmd *cobra.Command, args []string) {
err := initApp().DeleteUnretainedHistory()
app := initApp()
app.UpdateLedgerState()
err := app.DeleteUnretainedHistory()
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions services/horizon/internal/reap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ package reap
import (
"time"

"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/support/db"
)

// System represents the history reaping subsystem of horizon.
type System struct {
HorizonDB *db.Session
HistoryQ *history.Q
RetentionCount uint

nextRun time.Time
}

// New initializes the reaper, causing it to begin polling the stellar-core
// database for now ledgers and ingesting data into the horizon database.
func New(retention uint, horizon *db.Session) *System {
func New(retention uint, dbSession *db.Session) *System {
r := &System{
HorizonDB: horizon,
HistoryQ: &history.Q{dbSession},
RetentionCount: retention,
}

Expand Down
24 changes: 3 additions & 21 deletions services/horizon/internal/reap/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,12 @@ func (r *System) runOnce() {
func (r *System) clearBefore(seq int32) error {
log.WithField("new_elder", seq).Info("reaper: clearing")

clear := r.HorizonDB.DeleteRange
end := toid.New(seq, 0, 0).ToInt64()

err := clear(0, end, "history_effects", "history_operation_id")
if err != nil {
return err
}
err = clear(0, end, "history_operation_participants", "history_operation_id")
if err != nil {
return err
}
err = clear(0, end, "history_operations", "id")
start, end, err := toid.LedgerRangeInclusive(1, seq-1)
if err != nil {
return err
}
err = clear(0, end, "history_transaction_participants", "history_transaction_id")
if err != nil {
return err
}
err = clear(0, end, "history_transactions", "id")
if err != nil {
return err
}
err = clear(0, end, "history_ledgers", "id")

err = r.HistoryQ.DeleteRangeAll(start, end)
if err != nil {
return err
}
Expand Down