git.iko.soy/distributed-process
on master help sign in
Delete dead processes from monitor lists. (#294)
commitd3d3ea0ace228756c6ba6ee178ff602463a97ea7 authorFacundo Domínguez <facundominguez@gmail.com> dateThu 25 Aug 2016, 10:03 (10 years ago) parenta19f7f7
2 files changed+25−14
src/Control/Distributed/Process/Internal/BiMultiMap.hs+15−6 src/Control/Distributed/Process/Node.hs+10−8
src/Control/Distributed/Process/Internal/BiMultiMap.hs+15−6
@@ -9,7 +9,8 @@ module Control.Distributed.Process.Internal.BiMultiMap
99 , delete
1010 , deleteAllBy1st
1111 , deleteAllBy2nd
12− , partitionWithKey
12+ , partitionWithKeyBy1st
13+ , partitionWithKeyBy2nd
1314 , flip
1415 ) where
1516
@@ -91,15 +92,23 @@ deleteAllBy2nd b = flip . deleteAllBy1st b . flip
9192
9293-- | Yields the triplets satisfying the given predicate, and a multimap
9394-- with all this triplets removed.
94−partitionWithKey :: (Ord a, Ord b, Ord v)
95− => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
96− -> (Map a (Set (b, v)), BiMultiMap a b v)
97−partitionWithKey f (BiMultiMap m r) =
98− let (m0, m1) = Map.partitionWithKey f m
95+partitionWithKeyBy1st :: (Ord a, Ord b, Ord v)
96+ => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
97+ -> (Map a (Set (b, v)), BiMultiMap a b v)
98+partitionWithKeyBy1st p (BiMultiMap m r) =
99+ let (m0, m1) = Map.partitionWithKey p m
99100 r1 = foldl' (\rr (a, mb) -> reverseDelete a (Set.toList mb) rr) r $
100101 Map.toList m0
101102 in (m0, BiMultiMap m1 r1)
102103
104+-- | Like 'partitionWithKeyBy1st' but the predicates takes the second component
105+-- of the triplets as first argument.
106+partitionWithKeyBy2nd :: (Ord a, Ord b, Ord v)
107+ => (b -> Set (a, v) -> Bool) -> BiMultiMap a b v
108+ -> (Map b (Set (a, v)), BiMultiMap a b v)
109+partitionWithKeyBy2nd p b = let (m, b') = partitionWithKeyBy1st p $ flip b
110+ in (m, flip b')
111+
103112-- | Exchange the first and the second components of all triplets.
104113flip :: BiMultiMap a b v -> BiMultiMap b a v
105114flip (BiMultiMap m r) = BiMultiMap r m
src/Control/Distributed/Process/Node.hs+10−8
@@ -879,13 +879,15 @@ ncEffectDied ident reason = do
879879 when (localOnly <= isLocal node (ProcessIdentifier us)) $
880880 notifyDied us them reason (Just ref)
881881
882− let (unaffectedLinks', unaffectedMons') =
883− case ident of
884− ProcessIdentifier pid ->
885− ( BiMultiMap.deleteAllBy2nd pid unaffectedLinks
886− , BiMultiMap.deleteAllBy2nd pid unaffectedMons
887− )
888− _ -> (unaffectedLinks, unaffectedMons)
882+ let deleteDeads :: (Ord a, Ord v)
883+ => BiMultiMap a ProcessId v -> BiMultiMap a ProcessId v
884+ deleteDeads = case ident of
885+ -- deleteAllBy2nd is faster than partitionWithKeyBy2nd
886+ ProcessIdentifier pid -> BiMultiMap.deleteAllBy2nd pid
887+ _ -> snd . BiMultiMap.partitionWithKeyBy2nd
888+ (\pid _ -> ident `impliesDeathOf` ProcessIdentifier pid)
889+ unaffectedLinks' = deleteDeads unaffectedLinks
890+ unaffectedMons' = deleteDeads unaffectedMons
889891
890892 modify' $ (links ^= unaffectedLinks') . (monitors ^= unaffectedMons')
891893
@@ -1260,7 +1262,7 @@ splitNotif :: (Ord a, Ord v)
12601262 -> BiMultiMap Identifier a v
12611263 -> (Map Identifier (Set (a,v)), BiMultiMap Identifier a v)
12621264splitNotif ident =
1263− BiMultiMap.partitionWithKey (\k !_v -> ident `impliesDeathOf` k)
1265+ BiMultiMap.partitionWithKeyBy1st (\k !_v -> ident `impliesDeathOf` k)
12641266
12651267--------------------------------------------------------------------------------
12661268-- Auxiliary --