Skip to content
Snippets Groups Projects
Unverified Commit 70cfe4ee authored by Acha Bill's avatar Acha Bill Committed by GitHub
Browse files

adds a cli to override database dirty flag (#629)

* adds a cli to override database dirty flag

* gofmt
parent bbd89929
Branches
Tags
No related merge requests found
...@@ -9,9 +9,12 @@ const ( ...@@ -9,9 +9,12 @@ const (
CfgDatabaseDir = "database.directory" CfgDatabaseDir = "database.directory"
// CfgDatabaseInMemory defines whether to use an in-memory database. // CfgDatabaseInMemory defines whether to use an in-memory database.
CfgDatabaseInMemory = "database.inMemory" CfgDatabaseInMemory = "database.inMemory"
// CfgDatabaseDirty defines whether to override the database dirty flag.
CfgDatabaseDirty = "database.dirty"
) )
func init() { func init() {
flag.String(CfgDatabaseDir, "mainnetdb", "path to the database folder") flag.String(CfgDatabaseDir, "mainnetdb", "path to the database folder")
flag.Bool(CfgDatabaseInMemory, false, "whether the database is only kept in memory and not persisted") flag.Bool(CfgDatabaseInMemory, false, "whether the database is only kept in memory and not persisted")
flag.String(CfgDatabaseDirty, "", "set the dirty flag of the database")
} }
...@@ -3,6 +3,7 @@ package database ...@@ -3,6 +3,7 @@ package database
import ( import (
"errors" "errors"
"strconv"
"sync" "sync"
"time" "time"
...@@ -77,6 +78,17 @@ func configure(_ *node.Plugin) { ...@@ -77,6 +78,17 @@ func configure(_ *node.Plugin) {
log.Fatalf("Failed to check database version: %s", err) log.Fatalf("Failed to check database version: %s", err)
} }
if str := config.Node().GetString(CfgDatabaseDirty); str != "" {
val, err := strconv.ParseBool(str)
if err != nil {
log.Warnf("Invalid %s: %s", CfgDatabaseDirty, err)
} else if val {
MarkDatabaseUnhealthy()
} else {
MarkDatabaseHealthy()
}
}
if IsDatabaseUnhealthy() { if IsDatabaseUnhealthy() {
log.Fatal("The database is marked as not properly shutdown/corrupted, please delete the database folder and restart.") log.Fatal("The database is marked as not properly shutdown/corrupted, please delete the database folder and restart.")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment