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

horizon db reap command does nothing #2307

Closed
efritze opened this issue Feb 21, 2020 · 2 comments · Fixed by #2336
Closed

horizon db reap command does nothing #2307

efritze opened this issue Feb 21, 2020 · 2 comments · Fixed by #2336
Assignees
Labels
Milestone

Comments

@efritze
Copy link

efritze commented Feb 21, 2020

What version are you using?

horizon v0.24.1

What did you do?

I ran:

horizon --history-retention-count 10000 db reap

including all other necessary command line arguments.

What did you expect to see?

I expected to see feedback that the reaper actually reaped older unnecessary ledger entries in the horizon database.

What did you see instead?

Nothing. The command line returned with no error messages.

@efritze efritze added the bug label Feb 21, 2020
@efritze
Copy link
Author

efritze commented Feb 21, 2020

After looking at the Go source code, I found this under services/horizon/cmd/db.go:

var dbReapCmd = &cobra.Command{
	Use:   "reap",
	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()
		if err != nil {
			log.Fatal(err)
		}
	},
}

I believe the issue arises because the db reap command is calling initApp().DeleteUnretainedHistory() without an updated view of the current state of the ledger. Without an updated view of the current state of the ledger, the DeleteUnretainedHistory will fail because the latest ledger number will be Zero, making the target ledger number to have an invalid negative value.

Indeed, adding the following line of code completely solves the issue on my end: initApp().UpdateLedgerState()

var dbReapCmd = &cobra.Command{
	Use:   "reap",
	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) {
                //Adding the following line prior to calling DeleteUnretainedHistory  fixed the issue on my end.
		initApp().UpdateLedgerState()
		
		err := initApp().DeleteUnretainedHistory()
		if err != nil {
			log.Fatal(err)
		}
	},
}

@tamirms
Copy link
Contributor

tamirms commented Feb 27, 2020

@efritze Your diagnosis is correct, thanks for filing the issue! I have created a PR #2336 to fix this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants