feat: Wait shutdown-grace-seconds to flush async db writes to disk (#17094)

Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
Chill Validation 2023-09-15 18:19:34 +10:00 committed by GitHub
parent f99a6242a9
commit c92b25784c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#14224](https://github.com/cosmos/cosmos-sdk/pull/14224) Allow injection of restrictions on transfers using `AppendSendRestriction` or `PrependSendRestriction`.
* (x/bank) [#17569](https://github.com/cosmos/cosmos-sdk/pull/17569) Introduce a new message type, `MsgBurn `, to burn coins.
* (genutil) [#17571](https://github.com/cosmos/cosmos-sdk/pull/17571) Allow creation of `AppGenesis` without a file lookup.
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit.
### Improvements

View File

@ -7,6 +7,7 @@ import (
"net"
"os"
"runtime/pprof"
"time"
"github.com/cometbft/cometbft/abci/server"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
@ -63,6 +64,7 @@ const (
FlagMinRetainBlocks = "min-retain-blocks"
FlagIAVLCacheSize = "iavl-cache-size"
FlagDisableIAVLFastNode = "iavl-disable-fastnode"
FlagShutdownGrace = "shutdown-grace"
// state sync-related flags
FlagStateSyncSnapshotInterval = "state-sync.snapshot-interval"
@ -167,9 +169,19 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
serverCtx.Logger.Info("starting ABCI without CometBFT")
}
return wrapCPUProfile(serverCtx, func() error {
err = wrapCPUProfile(serverCtx, func() error {
return start(serverCtx, clientCtx, appCreator, withCMT, opts)
})
serverCtx.Logger.Debug("received quit signal")
graceDuration, _ := cmd.Flags().GetDuration(FlagShutdownGrace)
if graceDuration > 0 {
serverCtx.Logger.Info("graceful shutdown start", FlagShutdownGrace, graceDuration)
<-time.After(graceDuration)
serverCtx.Logger.Info("graceful shutdown complete")
}
return err
},
}
@ -206,6 +218,7 @@ is performed. Note, when enabled, gRPC will also be automatically enabled.
cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep")
cmd.Flags().Bool(FlagDisableIAVLFastNode, false, "Disable fast node for IAVL tree")
cmd.Flags().Int(FlagMempoolMaxTxs, mempool.DefaultMaxTx, "Sets MaxTx value for the app-side mempool")
cmd.Flags().Duration(FlagShutdownGrace, 0*time.Second, "On Shutdown, duration to wait for resource clean up")
// support old flags name for backwards compatibility
cmd.Flags().SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {