Permalink
Browse files

Actually include newly discovered servers in ring rotation

  • Loading branch information...
1 parent eca5142 commit fa6dd5c8464796bfe3ccff3c5d4557b6b645305e @ozataman ozataman committed Jul 14, 2012
Showing with 7 additions and 4 deletions.
  1. +1 −1 cassy.cabal
  2. +6 −3 src/Database/Cassandra/Pool.hs
View
@@ -1,5 +1,5 @@
Name: cassy
-Version: 0.3.3
+Version: 0.3.4
Synopsis: A high level driver for the Cassandra datastore
License: BSD3
License-file: LICENSE
@@ -25,7 +25,7 @@ import Data.ByteString (ByteString)
import Data.List (find, partition)
import Data.Maybe
import Data.Pool
-import Data.Set (Set)
+import Data.Set (Set)
import qualified Data.Set as S
import Data.Time.Clock (NominalDiffTime, UTCTime, diffUTCTime, getCurrentTime)
import qualified Database.Cassandra.Thrift.Cassandra_Client as C
@@ -132,8 +132,8 @@ serverDiscoveryThread :: TVar (Ring Server)
-> Pool Cassandra
-> IO b
serverDiscoveryThread sring ks pool = forever $ do
- threadDelay 5000000
withResource pool (updateServers sring ks)
+ threadDelay 60000000
------------------------------------------------------------------------------
@@ -173,6 +173,7 @@ next Ring{..}
| (n:rest) <- reverse (current : used)
= Ring allItems n [] rest
+
------------------------------------------------------------------------------
removeServer :: Ord a => a -> Ring a -> Ring a
removeServer s r@Ring{..}
@@ -182,11 +183,13 @@ removeServer s r@Ring{..}
used' = filter (/=s) used
(current':upcoming') = filter (/=s) (current:upcoming)
+
------------------------------------------------------------------------------
addNewServers :: [Server] -> Ring Server -> Ring Server
-addNewServers servers Ring{..} = Ring all' current' used' upcoming'
+addNewServers servers Ring{..} = Ring all' current' used' (new ++ upcoming')
where
all' = S.fromList servers
+ new = S.toList $ all' S.\\ allItems
used' = filter (`S.member` all') used
(current':upcoming') = filter (`S.member` all') (current:upcoming)

0 comments on commit fa6dd5c

Please sign in to comment.