From 70cfe4ee69aaaddf27b1ac2a866e5af5bd0dacf0 Mon Sep 17 00:00:00 2001 From: Acha Bill <57879913+acha-bill@users.noreply.github.com> Date: Mon, 20 Jul 2020 14:08:51 +0100 Subject: [PATCH] adds a cli to override database dirty flag (#629) * adds a cli to override database dirty flag * gofmt --- plugins/database/parameters.go | 3 +++ plugins/database/plugin.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/plugins/database/parameters.go b/plugins/database/parameters.go index c860dd8b..d550522a 100644 --- a/plugins/database/parameters.go +++ b/plugins/database/parameters.go @@ -9,9 +9,12 @@ const ( CfgDatabaseDir = "database.directory" // CfgDatabaseInMemory defines whether to use an in-memory database. CfgDatabaseInMemory = "database.inMemory" + // CfgDatabaseDirty defines whether to override the database dirty flag. + CfgDatabaseDirty = "database.dirty" ) func init() { 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.String(CfgDatabaseDirty, "", "set the dirty flag of the database") } diff --git a/plugins/database/plugin.go b/plugins/database/plugin.go index a3f4d25c..4e82ec67 100644 --- a/plugins/database/plugin.go +++ b/plugins/database/plugin.go @@ -3,6 +3,7 @@ package database import ( "errors" + "strconv" "sync" "time" @@ -77,6 +78,17 @@ func configure(_ *node.Plugin) { 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() { log.Fatal("The database is marked as not properly shutdown/corrupted, please delete the database folder and restart.") } -- GitLab