Skip to content
Snippets Groups Projects
Commit c62df702 authored by Iustin Pop's avatar Iustin Pop
Browse files

Start confd in notify mode if we can


This patch changes the default model—where confd is always started in
polling mode—to a model where if possible we enable inotify mode
before starting any of the background threads.

There are some tricky details here: if we enable inotify, we should
not modify the server state after wards, as inotify events could have
already fired and took ownership; therefore we presume that inotify
will work and set reloadModel=ReloadNotify, and only if we fail to
enable it we change it back to polling mode.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 3190ad64
No related branches found
No related tags found
No related merge requests found
...@@ -33,7 +33,7 @@ module Ganeti.Confd.Server ...@@ -33,7 +33,7 @@ module Ganeti.Confd.Server
import Control.Concurrent import Control.Concurrent
import Control.Exception import Control.Exception
import Control.Monad (forever, liftM, when) import Control.Monad (forever, liftM, when, unless)
import Data.IORef import Data.IORef
import Data.List import Data.List
import qualified Data.Map as M import qualified Data.Map as M
...@@ -112,6 +112,7 @@ initialPoll = ReloadPoll 0 ...@@ -112,6 +112,7 @@ initialPoll = ReloadPoll 0
data ConfigReload = ConfigToDate -- ^ No need to reload data ConfigReload = ConfigToDate -- ^ No need to reload
| ConfigReloaded -- ^ Configuration reloaded | ConfigReloaded -- ^ Configuration reloaded
| ConfigIOError -- ^ Error during configuration reload | ConfigIOError -- ^ Error during configuration reload
deriving (Eq)
-- | Unknown entry standard response. -- | Unknown entry standard response.
queryUnknownEntry :: StatusAnswer queryUnknownEntry :: StatusAnswer
...@@ -522,19 +523,31 @@ prepMain _ (af_family, bindaddr) = do ...@@ -522,19 +523,31 @@ prepMain _ (af_family, bindaddr) = do
-- | Main function. -- | Main function.
main :: MainFn (S.Family, S.SockAddr) PrepResult main :: MainFn (S.Family, S.SockAddr) PrepResult
main _ _ (s, query_data, cref) = do main _ _ (s, query_data, cref) = do
-- Inotify setup
inotify <- initINotify
-- try to load the configuration, if possible -- try to load the configuration, if possible
conf_file <- Path.clusterConfFile conf_file <- Path.clusterConfFile
(fstat, _) <- safeUpdateConfig conf_file nullFStat cref (fstat, reloaded) <- safeUpdateConfig conf_file nullFStat cref
ctime <- getCurrentTime ctime <- getCurrentTime
statemvar <- newMVar $ ServerState initialPoll ctime fstat statemvar <- newMVar $ ServerState ReloadNotify ctime fstat
hmac <- getClusterHmac
-- Inotify setup
inotify <- initINotify
let inotiaction = addNotifier inotify conf_file cref statemvar let inotiaction = addNotifier inotify conf_file cref statemvar
has_inotify <- if reloaded == ConfigReloaded
then inotiaction
else return False
if has_inotify
then logInfo "Starting up in inotify mode"
else do
-- inotify was not enabled, we need to update the reload model
logInfo "Starting up in polling mode"
modifyMVar_ statemvar
(\state -> return state { reloadModel = initialPoll })
hmac <- getClusterHmac
-- fork the timeout timer -- fork the timeout timer
_ <- forkIO $ onTimeoutTimer inotiaction conf_file cref statemvar _ <- forkIO $ onTimeoutTimer inotiaction conf_file cref statemvar
-- fork the polling timer -- fork the polling timer
_ <- forkIO $ onReloadTimer inotiaction conf_file cref statemvar unless has_inotify $ do
_ <- forkIO $ onReloadTimer inotiaction conf_file cref statemvar
return ()
-- launch the queryd listener -- launch the queryd listener
_ <- forkIO $ runQueryD query_data (configReader cref) _ <- forkIO $ runQueryD query_data (configReader cref)
-- and finally enter the responder loop -- and finally enter the responder loop
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment