packages feed

legion 0.9.0.0 → 0.9.0.1

raw patch · 2 files changed

+26/−9 lines, 2 files

Files

legion.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                legion-version:             0.9.0.0+version:             0.9.0.1 synopsis:            Distributed, stateful, homogeneous microservice framework. description:         Legion is a framework for writing distributed,                      homogeneous, stateful microservices in Haskell.
src/Network/Legion/Runtime.hs view
@@ -48,11 +48,12 @@ import Network.Legion.Distribution (Peer, newPeer) import Network.Legion.Fork (forkC) import Network.Legion.Index (IndexRecord(IndexRecord), irTag, irKey,-  SearchTag(SearchTag))+  SearchTag(SearchTag), indexEntries, Indexable) import Network.Legion.LIO (LIO) import Network.Legion.Lift (lift2,  lift3) import Network.Legion.PartitionKey (PartitionKey) import Network.Legion.PartitionState (PartitionPowerState)+import Network.Legion.PowerState (Event) import Network.Legion.Runtime.ConnectionManager (newConnectionManager,   ConnectionManager, newPeers) import Network.Legion.Runtime.PeerMessage (PeerMessage(PeerMessage),@@ -66,7 +67,7 @@   newNodeState, UserResponse(Forward, Respond), userRequest, eject,   minimumCompleteServiceSet, joinNext, joinNextResponse) import Network.Legion.StateMachine.Monad (NodeState, runSM, ClusterAction,-  SM, popActions)+  SM, popActions, nsIndex) import Network.Legion.UUID (getUUID) import Network.Socket (Family(AF_INET, AF_INET6, AF_UNIX, AF_CAN),   SocketOption(ReuseAddr), SocketType(Stream), accept, bind,@@ -520,8 +521,8 @@   {- | Figure out how to construct the initial node state.  -}-makeNodeState-  :: Persistence e o s+makeNodeState :: (Event e o s, Indexable s)+  => Persistence e o s   -> RuntimeSettings   -> StartupMode   -> LIO (Peer, NodeState e o s, Map Peer BSockAddr)@@ -573,10 +574,26 @@             return (self, cps)  makeNodeState persistence _ (Recover self cluster) = do-  let-    nodeState = newNodeState self cluster-  liftIO $ saveCluster persistence self cluster-  return (self, nodeState, C.getPeers cluster)+    {- Make sure to rebuild the index in the case of recovery. -}+    index <- runConduit . transPipe liftIO $+      list persistence+      =$= CL.fold addIndexRecords Set.empty+    let+      nodeState = (newNodeState self cluster) {nsIndex = index}+    liftIO $ saveCluster persistence self cluster+    return (self, nodeState, C.getPeers cluster)+  where+    addIndexRecords :: (Indexable s, Event e o s)+      => Set IndexRecord+      -> (PartitionKey, PartitionPowerState e o s)+      -> Set IndexRecord+    addIndexRecords index (key, partition) =+      let+        newRecords =+          Set.map+            (`IndexRecord` key)+            (indexEntries (PS.projectedValue partition))+      in Set.union index newRecords   {- |