Skip to content

fix(hstream): add recover-tasks-delay-ms option #1758

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions conf/hstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ hserver:
# gossip-interval: 1000000 # 1 sec
# probe-interval: 2000000 # 2 sec
# roundtrip-timeout: 500000 # 0.5 sec
#
# recover-tasks-delay-ms: 0

# TODO: Auth tokens
# - store tokens safely
Expand Down
7 changes: 6 additions & 1 deletion hstream/app/server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{-# LANGUAGE TypeApplications #-}

import Control.Concurrent (forkIO, newEmptyMVar,
putMVar, readMVar)
putMVar, readMVar,
threadDelay)
import qualified Control.Concurrent.Async as Async
import Control.Exception (bracket, handle)
import Control.Monad (forM, forM_, join, void,
Expand Down Expand Up @@ -55,6 +56,7 @@ import HStream.Server.Config (AdvertisedListeners,
FileLoggerSettings (..),
ListenersSecurityProtocolMap,
MetaStoreAddr (..),
RecoverOpts (..),
SecurityProtocolMap,
ServerCli (..),
ServerOpts (..), TlsConfig,
Expand Down Expand Up @@ -219,7 +221,10 @@ serve sc@ServerContext{..} rpcOpts enableStreamV2 = do
_ -> do
getProtoTimestamp >>= \x -> upsertMeta @Proto.Timestamp clusterStartTimeId x metaHandle
handle (\(_ :: RQLiteRowNotFound) -> return ()) $ deleteAllMeta @TaskAllocation metaHandle
Log.info "deleted all TaskAllocation records"
-- recover tasks
when (serverOpts._recover_opts._recover_tasks_delay_ms > 0) $ do
threadDelay $ 1000 * serverOpts._recover_opts._recover_tasks_delay_ms
Log.info "recovering local io tasks"
Cluster.recoverLocalTasks sc scIOWorker
Log.info "recovering local query tasks"
Expand Down
12 changes: 12 additions & 0 deletions hstream/src/HStream/Server/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module HStream.Server.Config
, readProtocol
#endif
, parseHostPorts

, RecoverOpts (..)
) where

import Control.Exception (throwIO)
Expand Down Expand Up @@ -122,6 +124,7 @@ data ServerOpts = ServerOpts

, _gossipOpts :: !GossipOpts
, _ioOptions :: !IO.IOOptions
, _recover_opts :: !RecoverOpts

, _querySnapshotPath :: !FilePath
, experimentalFeatures :: ![ExperimentalFeature]
Expand Down Expand Up @@ -272,6 +275,9 @@ parseJSONToOptions CliOptions{..} obj = do
tokensCfg <- nodeCfgObj .:? "tokens" .!= mempty
let serverTokens = map encodeUtf8 tokensCfg

_recover_tasks_delay_ms <- nodeCfgObj .:? "recover-tasks-delay-ms" .!= 0
let !_recover_opts = RecoverOpts{..}

return ServerOpts {..}

-------------------------------------------------------------------------------
Expand Down Expand Up @@ -325,3 +331,9 @@ readWithErrLog :: Read a => String -> String -> a
readWithErrLog opt v = case readEither v of
Right x -> x
Left _err -> errorWithoutStackTrace $ "Failed to parse value " <> show v <> " for option " <> opt

-------------------------------------------------------------------------------
data RecoverOpts
= RecoverOpts
{ _recover_tasks_delay_ms :: Int
} deriving (Show, Eq)
5 changes: 5 additions & 0 deletions hstream/test/HStream/ConfigSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import HStream.Gossip (GossipOpts (..),
import HStream.IO.Types (IOOptions (..))
import HStream.Server.Config (CliOptions (..),
MetaStoreAddr (..),
RecoverOpts (RecoverOpts),
ServerOpts (..),
TlsConfig (..),
parseHostPorts,
Expand Down Expand Up @@ -124,6 +125,8 @@ defaultConfig = ServerOpts

, _gossipOpts = defaultGossipOpts
, _ioOptions = defaultIOOptions
, _recover_opts = RecoverOpts 0

, _querySnapshotPath = "/data/query_snapshots"
, experimentalFeatures = []
, grpcChannelArgs = []
Expand Down Expand Up @@ -294,6 +297,8 @@ instance Arbitrary ServerOpts where
let experimentalFeatures = []
let grpcChannelArgs = []
let serverTokens = []

let _recover_opts = RecoverOpts 0
pure ServerOpts{..}

instance Arbitrary CliOptions where
Expand Down