Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log for ungraceful shutdown on startup #2215

Merged
merged 7 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ import (
)

var (
genesisHashKey = []byte("genesisID")
genesisHashKey = []byte("genesisID")
ungracefulShutdown = []byte("ungracefulShutdown")

indexerDBPrefix = []byte{0x00}

errInvalidTLSKey = errors.New("invalid TLS key")
Expand Down Expand Up @@ -556,6 +558,23 @@ func (n *Node) initDatabase() error {
if genesisHash != expectedGenesisHash {
return fmt.Errorf("db contains invalid genesis hash. DB Genesis: %s Generated Genesis: %s", genesisHash, expectedGenesisHash)
}

ok, err := n.DB.Has(ungracefulShutdown)
if err != nil {
return fmt.Errorf("failed to read ungraceful shutdown key: %w", err)
}

if ok {
n.Log.Warn("detected previous ungraceful shutdown")
}

if err := n.DB.Put(ungracefulShutdown, nil); err != nil {
return fmt.Errorf(
"failed to write ungraceful shutdown key at: %w",
err,
)
}

return nil
}

Expand Down Expand Up @@ -1530,6 +1549,13 @@ func (n *Node) shutdown() {
n.runtimeManager.Stop(context.TODO())

if n.DBManager != nil {
if err := n.DB.Delete(ungracefulShutdown); err != nil {
n.Log.Error(
"failed to delete ungraceful shutdown key",
zap.Error(err),
)
}

if err := n.DBManager.Close(); err != nil {
n.Log.Warn("error during DB shutdown",
zap.Error(err),
Expand Down
Loading