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).
- data Server = Server HostName PortID
- data PortID
- server :: HostName -> Server
- showHostPort :: Server -> String
- readHostPort :: String -> Server
- readHostPortF :: Monad m => String -> m Server
- data ReplicaSet
- replicaSet :: [Server] -> IO ReplicaSet
- replicaServers :: ReplicaSet -> IO [Server]
- data MasterOrSlave
- type FailedToConnect = [(Server, IOError)]
- newConnection :: MasterOrSlave -> ReplicaSet -> IO (Either FailedToConnect Connection)
- type Connection = Pipe Handle ByteString
- connect :: Server -> IO (Either IOError Connection)
- class Resource m r where
Read string "host:port" as 'Server host port' or "host" as 'server host' (default port). Error if string does not match either syntax.
Read string "host:port" as 'Server host port' or "host" as 'server host' (default port). Fail if string does not match either syntax.
Reference to a replica set of servers. Ok if really not a replica set and just a stand-alone server, in which case it acts like a replica set of one.
Create a reference to a replica set with servers as the initial seed list (a subset of the servers in the replica set)
Return current list of known servers in replica set. This list is updated on every
All servers tried in replica set along with reason why each failed to connect
Create a connection to a master or slave in the replica set. Don't forget to close connection when you are done using it even if Failure exception is raised when using it. newConnection returns Left if failed to connect to any server in replica set. TODO: prefer slave over master when SlaveOk and both are available.
Thread-safe TCP connection to server with pipelined requests
Create a connection to the given server (as opposed to connecting to some server in a replica set via
newConnection). Return Left IOError if failed to connect.