A replica set is a set of servers that mirror each other (a non-replicated server can act like a replica set of one). One server in a replica set is the master and the rest are slaves. When the master goes down, one of the slaves becomes master. The ReplicaSet object in this client maintains a list of servers that it currently knows are in the set. It refreshes this list every time it establishes a new connection with one of the servers in the set. Each server in the set knows who the other member in the set are, and who is master. The user asks the ReplicaSet object for a new master or slave connection. When a connection fails, the user must ask the ReplicaSet for a new connection (which most likely will connect to another server since the previous one failed). When connecting to a new server you loose all session state that was stored with the old server, which includes open cursors and temporary map-reduce output collections. Attempting to read from a lost cursor on a new server will raise a ServerFailure exception. Attempting to read a lost map-reduce temp output on a new server will return an empty set (not an error, like it maybe should).
- runNet :: ErrorT IOError m a -> m (Either IOError a)
- data Host = Host HostName PortID
- data PortID
- host :: HostName -> Host
- showHostPort :: Host -> String
- readHostPort :: String -> Host
- readHostPortM :: Monad m => String -> m Host
- data ReplicaSet
- replicaSet :: [Host] -> IO ReplicaSet
- replicas :: ReplicaSet -> IO [Host]
- newConnection :: (Throw IOError m, MonadIO' m) => MasterOrSlaveOk -> ReplicaSet -> m Connection
- data MasterOrSlaveOk
- type Connection = Pipe Handle ByteString
- connect :: (Throw IOError m, MonadIO' m) => Host -> m Connection
- class Resource m r where
Documentation
runNet :: ErrorT IOError m a -> m (Either IOError a)Source
Execute action that raises IOError only on network problem. Other IOErrors like file access errors are not caught by this.
Host
showHostPort :: Host -> StringSource
Display host as "host:port"
readHostPort :: String -> HostSource
Read string "hostname:port" as Host hostname port
or "hostname" as host hostname
(default port). Error if string does not match either syntax.
readHostPortM :: Monad m => String -> m HostSource
Read string "hostname:port" as Host hosthame port
or "hostname" as host hostname
(default port). Fail if string does not match either syntax.
ReplicaSet
data ReplicaSet Source
Reference to a replica set of hosts. Ok if really not a replica set and just a stand-alone server, in which case it acts like a replica set of one.
replicaSet :: [Host] -> IO ReplicaSetSource
Create a reference to a replica set with given hosts as the initial seed list (a subset of the hosts in the replica set)
replicas :: ReplicaSet -> IO [Host]Source
Return current list of known hosts in replica set. This list is updated on every newConnection
.
newConnection :: (Throw IOError m, MonadIO' m) => MasterOrSlaveOk -> ReplicaSet -> m ConnectionSource
Create a connection to a master or slave in the replica set. Throw IOError if failed to connect to any host in replica set that is the right master/slave type. close
connection when you are done using it even if a failure is raised. Garbage collected connections will be closed automatically (but don't rely on this when creating many connections).
TODO: prefer slave over master when SlaveOk and both are available.
MasterOrSlaveOk
data MasterOrSlaveOk Source
Connection
type Connection = Pipe Handle ByteStringSource
Thread-safe TCP connection to server with pipelined requests
connect :: (Throw IOError m, MonadIO' m) => Host -> m ConnectionSource
Create a connection to the given host (as opposed to connecting to some host in a replica set via newConnection
). Throw IOError if can't connect.