Skip to content

Commit

Permalink
Add log for ungraceful shutdown on startup (#2215)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim authored Oct 25, 2023
1 parent cd77a1e commit de168b1
Showing 1 changed file with 27 additions and 1 deletion.
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

0 comments on commit de168b1

Please sign in to comment.