Skip to content

Commit

Permalink
cmd,sqlite: add rebuild command
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed May 21, 2024
1 parent 107d34c commit b56710b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/hostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ func main() {
log.Fatal("failed to recalculate contract account funding", zap.Error(err))
} else if err := db.CheckContractAccountFunding(); err != nil {
log.Fatal("failed to check contract account funding", zap.Error(err))
} else if err := db.Vacuum(); err != nil {
log.Fatal("failed to vacuum database", zap.Error(err))
}
return
}
Expand Down
9 changes: 9 additions & 0 deletions persist/sqlite/recalc.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,23 @@ func recalcContractAccountFunding(tx txn, _ *zap.Logger) error {
return nil
}

// CheckContractAccountFunding checks that the contract account funding table
// is correct.
func (s *Store) CheckContractAccountFunding() error {
return s.transaction(func(tx txn) error {
return checkContractAccountFunding(tx, s.log)
})
}

// RecalcContractAccountFunding recalculates the contract account funding table.
func (s *Store) RecalcContractAccountFunding() error {
return s.transaction(func(tx txn) error {
return recalcContractAccountFunding(tx, s.log)
})
}

// Vacuum runs the VACUUM command on the database.
func (s *Store) Vacuum() error {
_, err := s.db.Exec(`VACUUM`)
return err
}

0 comments on commit b56710b

Please sign in to comment.