2020-05-23 09:19:56 +00:00
|
|
|
package generate
|
2020-04-20 10:35:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2020-05-31 06:57:47 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
|
|
"time"
|
2020-04-20 10:35:33 +00:00
|
|
|
)
|
|
|
|
|
2020-05-31 06:57:47 +00:00
|
|
|
func RegenerateIndex(chaindata string, csBucket []byte) error {
|
2020-04-20 10:35:33 +00:00
|
|
|
db, err := ethdb.NewBoltDatabase(chaindata)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-31 06:57:47 +00:00
|
|
|
ig := core.NewIndexGenerator(db, make(chan struct{}))
|
2020-04-20 10:35:33 +00:00
|
|
|
|
2020-05-31 06:57:47 +00:00
|
|
|
err = ig.DropIndex(dbutils.AccountsHistoryBucket)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-04-20 10:35:33 +00:00
|
|
|
}
|
2020-05-31 06:57:47 +00:00
|
|
|
startTime := time.Now()
|
|
|
|
log.Info("Index generation started", "start time", startTime)
|
|
|
|
err = ig.GenerateIndex(0, csBucket)
|
2020-04-20 10:35:33 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-05-31 06:57:47 +00:00
|
|
|
log.Info("Index is successfully regenerated", "it took", time.Since(startTime))
|
2020-04-20 10:35:33 +00:00
|
|
|
return nil
|
|
|
|
}
|