Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add retryCas, specialied retrying for Cassandra exceptions

  • Loading branch information...
commit 7693e0709ab6271bc48c6d69c077724176974356 1 parent 8e1108b
@ozataman ozataman authored
View
21 src/Database/Cassandra/Basic.hs
@@ -34,6 +34,11 @@ module Database.Cassandra.Basic
, insert
, delete
+ -- * Retrying Queries
+ , R.RetrySettings (..)
+ , R.retrying
+ , retryCas
+
-- * Filtering
, Selector(..)
, range
@@ -87,6 +92,7 @@ import Control.Applicative
import Control.Concurrent.Async
import Control.Exception
import Control.Monad
+import qualified Control.Monad.CatchIO as MCIO
import Control.Monad.Reader
import Data.ByteString.Lazy (ByteString)
import Data.Map (Map)
@@ -101,6 +107,7 @@ import Prelude hiding (catch)
-------------------------------------------------------------------------------
import Database.Cassandra.Pack
import Database.Cassandra.Pool
+import qualified Database.Cassandra.Retry as R
import Database.Cassandra.Types
-------------------------------------------------------------------------------
@@ -370,3 +377,17 @@ throwing f = do
case res of
Left e -> throw e
Right a -> return a
+
+
+-- | 'retrying' with direct cassandra support. Server-related failures
+-- will be retried.
+--
+-- 'UnavailableException', 'TimedOutException' and
+-- 'SchemaDisagreementException' will be automatically retried.
+retryCas :: (Functor m, MCIO.MonadCatchIO m)
+ => R.RetrySettings
+ -- ^ For default settings, just use 'def'
+ -> m b
+ -- ^ Action to perform
+ -> m b
+retryCas set f = R.retrying set shouldRetry f
View
9 src/Database/Cassandra/Marshall.hs
@@ -66,8 +66,9 @@ module Database.Cassandra.Marshall
, delete
-- * Retrying Queries
- , RetrySettings (..)
- , retrying
+ , R.RetrySettings (..)
+ , R.retrying
+ , CB.retryCas
-- * Necessary Types
, ColumnName
@@ -123,7 +124,7 @@ import Database.Cassandra.Basic hiding (KeySelector (..), delete,
get, getCol, getMulti)
import qualified Database.Cassandra.Basic as CB
import Database.Cassandra.Pack
-import Database.Cassandra.Retry
+import Database.Cassandra.Retry as R
import Database.Cassandra.Types
-------------------------------------------------------------------------------
@@ -431,3 +432,5 @@ paginate m cf k rng@(Range from to ord per) cl = do
(cn, _) = head cs
in return $ PMore (reverse (drop 1 cs)) cont
paginate _ _ _ _ _ = error "Must call paginate with a Range selector"
+
+
View
10 src/Database/Cassandra/Types.hs
@@ -242,6 +242,16 @@ data CassandraException =
instance Exception CassandraException
+
+shouldRetry :: CassandraException -> Bool
+shouldRetry e =
+ case e of
+ UnavailableException{} -> True
+ TimedOutException{} -> True
+ SchemaDisagreementException{} -> True
+ _ -> False
+
+
------------------------------------------------------------------------------
-- | Cassandra is VERY sensitive to its timestamp values. As a convention,
-- timestamps are always in microseconds
Please sign in to comment.
Something went wrong with that request. Please try again.