git.iko.soy/distributed-process
on master help sign in
Pass whole node rather than just state to withValidLocalNode.

For better error messages.

commitbae76a7485d859308afeef74cca00186df5efef4 authorMathieu Boespflug <m@tweag.io> dateSun 8 Mar 2015, 21:33 (12 years ago) parentd57e702
3 files changed+17−17
src/Control/Distributed/Process/Internal/Messaging.hs+4−4 src/Control/Distributed/Process/Internal/Types.hs+6−6 src/Control/Distributed/Process/Node.hs+7−7
src/Control/Distributed/Process/Internal/Messaging.hs+4−4
@@ -114,7 +114,7 @@ setupConnBetween node from to implicitReconnect = do
114114 Left _ ->
115115 return Nothing
116116 Right () -> do
117− modifyValidLocalState_ (localState node) $
117+ modifyValidLocalState_ node $
118118 return . (localConnectionBetween from to ^= Just (conn, implicitReconnect))
119119 return $ Just conn
120120 Left _ ->
@@ -126,7 +126,7 @@ connBetween :: LocalNode
126126 -> ImplicitReconnect
127127 -> IO (Maybe NT.Connection)
128128connBetween node from to implicitReconnect = do
129− mConn <- withValidLocalState (localState node) $
129+ mConn <- withValidLocalState node $
130130 return . (^. localConnectionBetween from to)
131131 case mConn of
132132 Just (conn, _) ->
@@ -136,7 +136,7 @@ connBetween node from to implicitReconnect = do
136136
137137disconnect :: LocalNode -> Identifier -> Identifier -> IO ()
138138disconnect node from to =
139− modifyValidLocalState_ (localState node) $ \vst ->
139+ modifyValidLocalState_ node $ \vst ->
140140 case vst ^. localConnectionBetween from to of
141141 Nothing ->
142142 return vst
@@ -146,7 +146,7 @@ disconnect node from to =
146146
147147closeImplicitReconnections :: LocalNode -> Identifier -> IO ()
148148closeImplicitReconnections node to =
149− modifyValidLocalState_ (localState node) $ \vst -> do
149+ modifyValidLocalState_ node $ \vst -> do
150150 let shouldClose (_, to') (_, WithImplicitReconnect) = to `impliesDeathOf` to'
151151 shouldClose _ _ = False
152152 let (affected, unaffected) =
src/Control/Distributed/Process/Internal/Types.hs+6−6
@@ -279,21 +279,21 @@ data ValidLocalNodeState = ValidLocalNodeState
279279
280280-- | Wrapper around 'withMVar' that checks that the local node is still in
281281-- a valid state.
282−withValidLocalState :: StrictMVar LocalNodeState
282+withValidLocalState :: LocalNode
283283 -> (ValidLocalNodeState -> IO r)
284284 -> IO r
285−withValidLocalState mv f = withMVar mv $ \st -> case st of
285+withValidLocalState node f = withMVar (localState node) $ \st -> case st of
286286 LocalNodeValid vst -> f vst
287− LocalNodeClosed -> throwIO $ userError "LocalNode closed"
287+ LocalNodeClosed -> throwIO $ userError $ "Node closed " ++ show (localNodeId node)
288288
289289-- | Wrapper around 'modifyMVar_' that checks that the local node is still in
290290-- a valid state.
291−modifyValidLocalState_ :: StrictMVar LocalNodeState
291+modifyValidLocalState_ :: LocalNode
292292 -> (ValidLocalNodeState -> IO ValidLocalNodeState)
293293 -> IO ()
294−modifyValidLocalState_ mv f = modifyMVar_ mv $ \st -> case st of
294+modifyValidLocalState_ node f = modifyMVar_ (localState node) $ \st -> case st of
295295 LocalNodeValid vst -> LocalNodeValid <$> f vst
296− LocalNodeClosed -> throwIO $ userError "LocalNode closed"
296+ LocalNodeClosed -> throwIO $ userError $ "Node closed " ++ show (localNodeId node)
297297
298298-- | Processes running on our local node
299299data LocalProcess = LocalProcess
src/Control/Distributed/Process/Node.hs+7−7
@@ -383,7 +383,7 @@ forkProcess node proc =
383383 (return . DiedException . (show :: SomeException -> String)))]
384384
385385 -- [Unified: Table 4, rules termination and exiting]
386− modifyValidLocalState_ (localState node) (cleanupProcess pid)
386+ modifyValidLocalState_ node (cleanupProcess pid)
387387 writeChan (localCtrlChan node) NCMsg
388388 { ctrlMsgSender = ProcessIdentifier pid
389389 , ctrlMsgSignal = Died (ProcessIdentifier pid) reason
@@ -510,7 +510,7 @@ handleIncomingMessages node = go initConnectionState
510510 case decode (BSL.fromChunks payload) of
511511 ProcessIdentifier pid -> do
512512 let lpid = processLocalId pid
513− mProc <- withValidLocalState state $ return . (^. localProcessWithId lpid)
513+ mProc <- withValidLocalState node $ return . (^. localProcessWithId lpid)
514514 case mProc of
515515 Just proc ->
516516 go (incomingAt cid ^= Just (src, ToProc pid (processWeakQ proc)) $ st)
@@ -519,7 +519,7 @@ handleIncomingMessages node = go initConnectionState
519519 SendPortIdentifier chId -> do
520520 let lcid = sendPortLocalId chId
521521 lpid = processLocalId (sendPortProcessId chId)
522− mProc <- withValidLocalState state $ return . (^. localProcessWithId lpid)
522+ mProc <- withValidLocalState node $ return . (^. localProcessWithId lpid)
523523 case mProc of
524524 Just proc -> do
525525 mChannel <- withMVar (processState proc) $ return . (^. typedChannelWithId lcid)
@@ -980,7 +980,7 @@ ncEffectGetInfo from pid =
980980 them = (ProcessIdentifier pid)
981981 in do
982982 node <- ask
983− mProc <- liftIO $ withValidLocalState (localState node)
983+ mProc <- liftIO $ withValidLocalState node
984984 $ return . (^. localProcessWithId lpid)
985985 case mProc of
986986 Nothing -> dispatch (isLocal node (ProcessIdentifier from))
@@ -1024,7 +1024,7 @@ ncEffectGetNodeStats :: ProcessId -> NodeId -> NC ()
10241024ncEffectGetNodeStats from _nid = do
10251025 node <- ask
10261026 ncState <- StateT.get
1027− nodeState <- liftIO $ withValidLocalState (localState node) return
1027+ nodeState <- liftIO $ withValidLocalState node return
10281028 let stats =
10291029 NodeStats {
10301030 nodeStatsNode = localNodeId node
@@ -1107,7 +1107,7 @@ unClosure closure = do
11071107isValidLocalIdentifier :: Identifier -> NC Bool
11081108isValidLocalIdentifier ident = do
11091109 node <- ask
1110− liftIO . withValidLocalState (localState node) $ \nSt ->
1110+ liftIO . withValidLocalState node $ \nSt ->
11111111 case ident of
11121112 NodeIdentifier nid ->
11131113 return $ nid == localNodeId node
@@ -1145,7 +1145,7 @@ withLocalProc node pid p =
11451145 -- By [Unified: table 6, rule missing_process] messages to dead processes
11461146 -- can silently be dropped
11471147 let lpid = processLocalId pid in do
1148− withValidLocalState (localState node) $ \vst ->
1148+ withValidLocalState node $ \vst ->
11491149 forM_ (vst ^. localProcessWithId lpid) p
11501150
11511151--------------------------------------------------------------------------------