2020-07-14 01:56:29 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2022-02-12 13:33:09 +00:00
|
|
|
"path/filepath"
|
2021-04-19 07:25:26 +00:00
|
|
|
|
2022-05-25 09:22:02 +00:00
|
|
|
"github.com/c2h5oh/datasize"
|
2021-07-29 11:53:13 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
|
|
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/utils"
|
|
|
|
"github.com/ledgerwatch/erigon/internal/debug"
|
|
|
|
"github.com/ledgerwatch/erigon/migrations"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2020-07-14 01:56:29 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "integration",
|
2021-05-26 10:35:39 +00:00
|
|
|
Short: "long and heavy integration tests for Erigon",
|
2020-07-14 01:56:29 +00:00
|
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
2020-08-20 03:52:27 +00:00
|
|
|
if err := utils.SetupCobra(cmd); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-04-19 07:25:26 +00:00
|
|
|
if chaindata == "" {
|
2022-06-07 04:00:37 +00:00
|
|
|
chaindata = filepath.Join(datadirCli, "chaindata")
|
2021-04-19 07:25:26 +00:00
|
|
|
}
|
2020-07-14 01:56:29 +00:00
|
|
|
},
|
2020-08-20 03:52:27 +00:00
|
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
defer utils.StopDebug()
|
|
|
|
},
|
2020-07-14 01:56:29 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 11:46:20 +00:00
|
|
|
func RootCommand() *cobra.Command {
|
|
|
|
utils.CobraFlags(rootCmd, append(debug.Flags, utils.MetricFlags...))
|
|
|
|
return rootCmd
|
2020-07-14 01:56:29 +00:00
|
|
|
}
|
2020-10-13 22:42:04 +00:00
|
|
|
|
2021-07-28 02:47:38 +00:00
|
|
|
func openDB(path string, logger log.Logger, applyMigrations bool) kv.RwDB {
|
|
|
|
label := kv.ChainDB
|
|
|
|
db := openKV(label, logger, path, false)
|
2020-10-28 09:52:15 +00:00
|
|
|
if applyMigrations {
|
2021-07-04 07:50:32 +00:00
|
|
|
has, err := migrations.NewMigrator(label).HasPendingMigrations(db)
|
2021-03-01 04:02:22 +00:00
|
|
|
if err != nil {
|
2020-10-28 09:52:15 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
2021-03-01 04:02:22 +00:00
|
|
|
if has {
|
|
|
|
log.Info("Re-Opening DB in exclusive mode to apply DB migrations")
|
|
|
|
db.Close()
|
2021-07-28 02:47:38 +00:00
|
|
|
db = openKV(label, logger, path, true)
|
2022-06-07 04:00:37 +00:00
|
|
|
if err := migrations.NewMigrator(label).Apply(db, datadirCli); err != nil {
|
2021-03-01 04:02:22 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
db.Close()
|
2021-07-28 02:47:38 +00:00
|
|
|
db = openKV(label, logger, path, false)
|
2021-03-01 04:02:22 +00:00
|
|
|
}
|
2020-10-28 09:52:15 +00:00
|
|
|
}
|
2021-07-04 07:50:32 +00:00
|
|
|
return db
|
2020-10-28 09:52:15 +00:00
|
|
|
}
|
|
|
|
|
2021-07-28 02:47:38 +00:00
|
|
|
func openKV(label kv.Label, logger log.Logger, path string, exclusive bool) kv.RwDB {
|
|
|
|
opts := kv2.NewMDBX(logger).Path(path).Label(label)
|
2022-05-25 09:22:02 +00:00
|
|
|
if label == kv.ChainDB {
|
|
|
|
opts = opts.MapSize(8 * datasize.TB)
|
|
|
|
}
|
2020-10-28 09:52:15 +00:00
|
|
|
if exclusive {
|
|
|
|
opts = opts.Exclusive()
|
2020-10-13 22:42:04 +00:00
|
|
|
}
|
2021-05-10 15:07:22 +00:00
|
|
|
if databaseVerbosity != -1 {
|
2021-07-28 02:47:38 +00:00
|
|
|
opts = opts.DBVerbosity(kv.DBVerbosityLvl(databaseVerbosity))
|
2021-05-10 15:07:22 +00:00
|
|
|
}
|
2021-07-28 02:47:38 +00:00
|
|
|
return opts.MustOpen()
|
2020-10-13 22:42:04 +00:00
|
|
|
}
|