Skip to content

Commit

Permalink
Add a DB version to auto-change the datadir when major updates are ma…
Browse files Browse the repository at this point in the history
…de (#349)
  • Loading branch information
diamondhands0 authored Apr 30, 2022
1 parent f4e020c commit 615c275
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/golang/glog"
"github.com/spf13/viper"
"os"
"path/filepath"
)

type Config struct {
Expand Down Expand Up @@ -81,10 +82,11 @@ func LoadConfig() *Config {
config.ProtocolPort = config.Params.DefaultSocketPort
}

config.DataDirectory = viper.GetString("data-dir")
if config.DataDirectory == "" {
config.DataDirectory = lib.GetDataDir(config.Params)
dataDir := viper.GetString("data-dir")
if dataDir == "" {
dataDir = lib.GetDataDir(config.Params)
}
config.DataDirectory = filepath.Join(dataDir, lib.DBVersionString)
if err := os.MkdirAll(config.DataDirectory, os.ModePerm); err != nil {
glog.Fatalf("Could not create data directories (%s): %v", config.DataDirectory, err)
}
Expand Down
6 changes: 6 additions & 0 deletions lib/db_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const (
// store the badgerdb database by default.
BadgerDbFolder = "badgerdb"
MaxPrefixLen = 1
// This string is added as a subdirectory of --data-dir flag that contains
// everything our node is doing. We use it in order to force a "fresh sync"
// of a node when making major updates. Not having this structure would
// require node operators like Coinbase to change their --data-dir flag when
// deploying a non-backwards-compatible version of the node.
DBVersionString = "v-00000"
)

// -------------------------------------------------------------------------------------
Expand Down

0 comments on commit 615c275

Please sign in to comment.