Skip to content

Commit

Permalink
performance options = true if NOT hypersync OR existing data dir (des…
Browse files Browse the repository at this point in the history
  • Loading branch information
lazynina authored Jan 29, 2024
1 parent 6292b83 commit 2dabcb3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,32 @@ func (node *Node) Start(exitChannels ...*chan struct{}) {

// Check to see if this node has already been initialized with performance or default options.
// If so, we should continue to use those options.
// If not, it should be based on the sync type.
// If not and the db directory exists, we will use PerformanceOptions as the default. This is because
// prior to the use of default options for hypersync, all nodes were initialized with performance options.
// So all nodes that are upgrading will want to continue using performance options. Only nodes that are
// hypersyncing from scratch can use default options.
// If not, this means we have a clean data directory and it should be based on the sync type.
// The reason we do this check is because once a badger database is initialized with performance options,
// re-opening it with non-performance options results in a memory error panic. In order to prevent this transition
// from default -> performance -> default settings, we save the db options to a file. This takes the form of a
// boolean which indicates whether the db was initialized with performance options or not. Upon restart, if the
// file exists, we use the same options. If the file does not exist, we use the options based on the sync type.
performanceOptions, err := lib.DbInitializedWithPerformanceOptions(node.Config.DataDirectory)

// If the db options haven't yet been saved, we should base the options on the sync type.
// We hardcode performanceOptions to true if we're not using a hypersync sync-type. This helps
// nodes recover that were running an older version that wrote the incorrect boolean to the file.
if node.Config.SyncType != lib.NodeSyncTypeHyperSync &&
node.Config.SyncType != lib.NodeSyncTypeHyperSyncArchival {
performanceOptions = true
}
// If the db options haven't yet been saved, we should base the options on the existence of the
// data directory and the sync type.
if os.IsNotExist(err) {
performanceOptions = !node.Config.HyperSync
// Check if the db directory exists.
_, err = os.Stat(dbDir)
isHypersync := node.Config.SyncType == lib.NodeSyncTypeHyperSync ||
node.Config.SyncType == lib.NodeSyncTypeHyperSyncArchival
performanceOptions = !os.IsNotExist(err) || !isHypersync
// Save the db options for future runs.
lib.SaveBoolToFile(lib.GetDbPerformanceOptionsFilePath(node.Config.DataDirectory), performanceOptions)
} else if err != nil {
Expand Down

0 comments on commit 2dabcb3

Please sign in to comment.