Skip to content
Snippets Groups Projects
Unverified Commit e208d9c2 authored by Jonas Theis's avatar Jonas Theis Committed by GitHub
Browse files

Add database plugin to call garbage collection and close DB (#289)

* Add database plugin to call garbage collection and close DB on shutdown #284

* Adjust comment
parent 4b4d761b
No related branches found
No related tags found
No related merge requests found
package shutdown
const (
ShutdownPriorityTangle = iota
ShutdownPriorityDatabase = iota
ShutdownPriorityTangle
ShutdownPriorityRemoteLog
ShutdownPriorityAnalysis
ShutdownPriorityMetrics
......
......@@ -5,6 +5,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/cli"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/goshimmer/plugins/database"
"github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/goshimmer/plugins/gracefulshutdown"
"github.com/iotaledger/goshimmer/plugins/logger"
......@@ -20,6 +21,7 @@ var PLUGINS = node.Plugins(
logger.PLUGIN,
cli.PLUGIN,
portcheck.PLUGIN,
database.PLUGIN,
autopeering.PLUGIN,
tangle.PLUGIN,
gossip.PLUGIN,
......
// database is a plugin that manages the badger database (e.g. garbage collection).
package database
import (
"time"
"github.com/iotaledger/hive.go/timeutil"
"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
)
const (
PLUGIN_NAME = "Database"
)
var (
PLUGIN = node.NewPlugin(PLUGIN_NAME, node.Enabled, configure, run)
log *logger.Logger
)
func configure(plugin *node.Plugin) {
log = logger.NewLogger(PLUGIN_NAME)
_ = database.GetBadgerInstance()
}
func run(plugin *node.Plugin) {
daemon.BackgroundWorker(PLUGIN_NAME+"_GC", func(shutdownSignal <-chan struct{}) {
timeutil.Ticker(func() {
database.CleanupBadgerInstance(log)
}, 5*time.Minute, shutdownSignal)
}, shutdown.ShutdownPriorityBadgerGarbageCollection)
daemon.BackgroundWorker(PLUGIN_NAME, func(shutdownSignal <-chan struct{}) {
<-shutdownSignal
log.Infof("Syncing database to disk...")
database.GetBadgerInstance().Close()
log.Infof("Syncing database to disk... done")
}, shutdown.ShutdownPriorityDatabase)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment