Safe Haskell | Safe-Infered |
---|
Implementation of the Ganeti confd server functionality.
- type CRef = IORef (Result (ConfigData, LinkIpMap))
- type FStat = (EpochTime, FileID, FileOffset)
- nullFStat :: FStat
- type StatusAnswer = (ConfdReplyStatus, JSValue)
- data ReloadModel
- = ReloadNotify
- | ReloadPoll Int
- data ServerState = ServerState {
- reloadModel :: ReloadModel
- reloadTime :: Integer
- reloadFStat :: FStat
- maxIdlePollRounds :: Int
- watchInterval :: Int
- pollInterval :: Int
- reloadRatelimit :: Integer
- initialPoll :: ReloadModel
- data ConfigReload
- queryUnknownEntry :: StatusAnswer
- queryArgumentError :: StatusAnswer
- gntErrorToResult :: ErrorResult a -> Result a
- nodeRole :: ConfigData -> String -> Result ConfdNodeRole
- getNodePipByInstanceIp :: ConfigData -> LinkIpMap -> String -> String -> StatusAnswer
- buildResponse :: (ConfigData, LinkIpMap) -> ConfdRequest -> Result StatusAnswer
- serializeResponse :: Result StatusAnswer -> ConfdReply
- moveToPolling :: String -> INotify -> FilePath -> CRef -> MVar ServerState -> IO ReloadModel
- moveToNotify :: IO ReloadModel
- updateConfig :: FilePath -> CRef -> IO ()
- safeUpdateConfig :: FilePath -> FStat -> CRef -> IO (FStat, ConfigReload)
- buildFileStatus :: FileStatus -> FStat
- getFStat :: FilePath -> IO FStat
- needsReload :: FStat -> FilePath -> IO (Maybe FStat)
- onWatcherTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
- onWatcherInner :: FilePath -> CRef -> ServerState -> IO ServerState
- onPollTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
- onPollInner :: IO Bool -> FilePath -> CRef -> ServerState -> IO (ServerState, Bool)
- addNotifier :: INotify -> FilePath -> CRef -> MVar ServerState -> IO Bool
- onInotify :: INotify -> String -> CRef -> MVar ServerState -> Event -> IO ()
- responder :: CRef -> Socket -> HashKey -> String -> SockAddr -> IO ()
- respondInner :: Result (ConfigData, LinkIpMap) -> HashKey -> ConfdRequest -> String
- listener :: Socket -> HashKey -> (Socket -> HashKey -> String -> SockAddr -> IO ()) -> IO ()
- configReader :: CRef -> IO (Result ConfigData)
- type PrepResult = (Socket, (FilePath, Socket), IORef (Result (ConfigData, LinkIpMap)))
- checkMain :: CheckFn (Family, SockAddr)
- prepMain :: PrepFn (Family, SockAddr) PrepResult
- main :: MainFn (Family, SockAddr) PrepResult
Types and constants definitions
type CRef = IORef (Result (ConfigData, LinkIpMap))Source
type StatusAnswer = (ConfdReplyStatus, JSValue)Source
data ServerState Source
ServerState | |
|
maxIdlePollRounds :: IntSource
watchInterval :: IntSource
pollInterval :: IntSource
reloadRatelimit :: IntegerSource
gntErrorToResult :: ErrorResult a -> Result aSource
Confd base functionality
nodeRole :: ConfigData -> String -> Result ConfdNodeRoleSource
getNodePipByInstanceIp :: ConfigData -> LinkIpMap -> String -> String -> StatusAnswerSource
buildResponse :: (ConfigData, LinkIpMap) -> ConfdRequest -> Result StatusAnswerSource
Configuration handling
Helper functions
moveToPolling :: String -> INotify -> FilePath -> CRef -> MVar ServerState -> IO ReloadModelSource
Configuration loading
updateConfig :: FilePath -> CRef -> IO ()Source
safeUpdateConfig :: FilePath -> FStat -> CRef -> IO (FStat, ConfigReload)Source
buildFileStatus :: FileStatus -> FStatSource
needsReload :: FStat -> FilePath -> IO (Maybe FStat)Source
Watcher threads
We have three threads/functions that can mutate the server state:
- the long-interval watcher (
onWatcherTimer
) - the polling watcher (
onPollTimer
) - the inotify event handler (
onInotify
)
All of these will mutate the server state under modifyMVar
or
modifyMVar_
, so that server transitions are more or less
atomic. The inotify handler remains active during polling mode, but
checks for polling mode and doesn't do anything in this case (this
check is needed even if we would unregister the event handler due
to how events are serialised).
onWatcherTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()Source
onWatcherInner :: FilePath -> CRef -> ServerState -> IO ServerStateSource
onPollTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()Source
onPollInner :: IO Bool -> FilePath -> CRef -> ServerState -> IO (ServerState, Bool)Source
addNotifier :: INotify -> FilePath -> CRef -> MVar ServerState -> IO BoolSource
onInotify :: INotify -> String -> CRef -> MVar ServerState -> Event -> IO ()Source
Client input/output handlers
respondInner :: Result (ConfigData, LinkIpMap) -> HashKey -> ConfdRequest -> StringSource
configReader :: CRef -> IO (Result ConfigData)Source
type PrepResult = (Socket, (FilePath, Socket), IORef (Result (ConfigData, LinkIpMap)))Source
prepMain :: PrepFn (Family, SockAddr) PrepResultSource
Prepare function for confd.
main :: MainFn (Family, SockAddr) PrepResultSource
Main function.