git.iko.soy/distributed-process
on master help sign in
Delete dead processes from monitor lists. (#294)
d3d3ea0Facundo Domínguez
src/Control/Distributed/Process/Internal/BiMultiMap.hs+15−6
@@ -9,7 +9,8 @@ module Control.Distributed.Process.Internal.BiMultiMap
9 , delete
9 , delete
10 , deleteAllBy1st
10 , deleteAllBy1st
11 , deleteAllBy2nd
11 , deleteAllBy2nd
12− , partitionWithKey
12+ , partitionWithKeyBy1st
13+ , partitionWithKeyBy2nd
13 , flip
14 , flip
14 ) where
15 ) where
15
16
@@ -91,15 +92,23 @@ deleteAllBy2nd b = flip . deleteAllBy1st b . flip
91
92
92-- | Yields the triplets satisfying the given predicate, and a multimap
93-- | Yields the triplets satisfying the given predicate, and a multimap
93-- with all this triplets removed.
94-- with all this triplets removed.
94−partitionWithKey :: (Ord a, Ord b, Ord v)
95+partitionWithKeyBy1st :: (Ord a, Ord b, Ord v)
95− => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
96+ => (a -> Set (b, v) -> Bool) -> BiMultiMap a b v
96− -> (Map a (Set (b, v)), BiMultiMap a b v)
97+ -> (Map a (Set (b, v)), BiMultiMap a b v)
97−partitionWithKey f (BiMultiMap m r) =
98+partitionWithKeyBy1st p (BiMultiMap m r) =
98− let (m0, m1) = Map.partitionWithKey f m
99+ let (m0, m1) = Map.partitionWithKey p m
99 r1 = foldl' (\rr (a, mb) -> reverseDelete a (Set.toList mb) rr) r $
100 r1 = foldl' (\rr (a, mb) -> reverseDelete a (Set.toList mb) rr) r $
100 Map.toList m0
101 Map.toList m0
101 in (m0, BiMultiMap m1 r1)
102 in (m0, BiMultiMap m1 r1)
102
103
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+
103-- | Exchange the first and the second components of all triplets.
112-- | Exchange the first and the second components of all triplets.
104flip :: BiMultiMap a b v -> BiMultiMap b a v
113flip :: BiMultiMap a b v -> BiMultiMap b a v
105flip (BiMultiMap m r) = BiMultiMap r m
114flip (BiMultiMap m r) = BiMultiMap r m
src/Control/Distributed/Process/Node.hs+10−8
@@ -879,13 +879,15 @@ ncEffectDied ident reason = do
879 when (localOnly <= isLocal node (ProcessIdentifier us)) $
879 when (localOnly <= isLocal node (ProcessIdentifier us)) $
880 notifyDied us them reason (Just ref)
880 notifyDied us them reason (Just ref)
881
881
882− let (unaffectedLinks', unaffectedMons') =
882+ let deleteDeads :: (Ord a, Ord v)
883+ => BiMultiMap a ProcessId v -> BiMultiMap a ProcessId v
883− case ident of
884+ deleteDeads = case ident of
884− ProcessIdentifier pid ->
885+ -- deleteAllBy2nd is faster than partitionWithKeyBy2nd
885− ( BiMultiMap.deleteAllBy2nd pid unaffectedLinks
886+ ProcessIdentifier pid -> BiMultiMap.deleteAllBy2nd pid
886− , BiMultiMap.deleteAllBy2nd pid unaffectedMons
887+ _ -> snd . BiMultiMap.partitionWithKeyBy2nd
887− )
888+ (\pid _ -> ident `impliesDeathOf` ProcessIdentifier pid)
888− _ -> (unaffectedLinks, unaffectedMons)
889+ unaffectedLinks' = deleteDeads unaffectedLinks
890+ unaffectedMons' = deleteDeads unaffectedMons
889
891
890 modify' $ (links ^= unaffectedLinks') . (monitors ^= unaffectedMons')
892 modify' $ (links ^= unaffectedLinks') . (monitors ^= unaffectedMons')
891
893
@@ -1260,7 +1262,7 @@ splitNotif :: (Ord a, Ord v)
1260 -> BiMultiMap Identifier a v
1262 -> BiMultiMap Identifier a v
1261 -> (Map Identifier (Set (a,v)), BiMultiMap Identifier a v)
1263 -> (Map Identifier (Set (a,v)), BiMultiMap Identifier a v)
1262splitNotif ident =
1264splitNotif ident =
1263− BiMultiMap.partitionWithKey (\k !_v -> ident `impliesDeathOf` k)
1265+ BiMultiMap.partitionWithKeyBy1st (\k !_v -> ident `impliesDeathOf` k)
1264
1266
1265--------------------------------------------------------------------------------
1267--------------------------------------------------------------------------------
1266-- Auxiliary --
1268-- Auxiliary --