MongoDB  2.4.4-pre-
Public Member Functions | Protected Member Functions | List of all members
mongo::SyncClusterConnection Class Reference

This is a connection to a cluster of servers that operate as one for super high durability. More...

#include <syncclusterconnection.h>

Inheritance diagram for mongo::SyncClusterConnection:
mongo::DBClientBase mongo::DBClientWithCommands mongo::DBConnector mongo::DBClientInterface

Public Member Functions

 SyncClusterConnection (const list< HostAndPort > &, double socketTimeout=0)
 
 SyncClusterConnection (string commaSeparated, double socketTimeout=0)
 
 SyncClusterConnection (const std::string &a, const std::string &b, const std::string &c, double socketTimeout=0)
 
bool prepare (string &errmsg)
 
bool fsync (string &errmsg)
 runs fsync on all servers
 
virtual BSONObj findOne (const string &ns, const Query &query, const BSONObj *fieldsToReturn, int queryOptions)
 
virtual auto_ptr< DBClientCursorquery (const string &ns, Query query, int nToReturn, int nToSkip, const BSONObj *fieldsToReturn, int queryOptions, int batchSize)
 send a query to the database. More...
 
virtual auto_ptr< DBClientCursorgetMore (const string &ns, long long cursorId, int nToReturn, int options)
 don't use this - called automatically by DBClientCursor for you More...
 
virtual void insert (const string &ns, BSONObj obj, int flags=0)
 insert an object into the database
 
virtual void insert (const string &ns, const vector< BSONObj > &v, int flags=0)
 insert a vector of objects into the database
 
virtual void remove (const string &ns, Query query, int flags)
 
virtual void update (const string &ns, Query query, BSONObj obj, int flags)
 
virtual bool call (Message &toSend, Message &response, bool assertOk, string *actualServer)
 actualServer is set to the actual server where they call went if there was a choice (SlaveOk)
 
virtual void say (Message &toSend, bool isRetry=false, string *actualServer=0)
 
virtual void sayPiggyBack (Message &toSend)
 
virtual void killCursor (long long cursorID)
 
virtual string getServerAddress () const
 
virtual bool isFailed () const
 
virtual string toString ()
 
virtual BSONObj getLastErrorDetailed (const std::string &db, bool fsync=false, bool j=false, int w=0, int wtimeout=0)
 Get error result from the last write operation (insert/update/delete) on this connection. More...
 
virtual BSONObj getLastErrorDetailed (bool fsync=false, bool j=false, int w=0, int wtimeout=0)
 
virtual bool callRead (Message &toSend, Message &response)
 
virtual
ConnectionString::ConnectionType 
type () const
 
void setAllSoTimeouts (double socketTimeout)
 
double getSoTimeout () const
 
virtual bool lazySupported () const
 
- Public Member Functions inherited from mongo::DBClientBase
long long getConnectionId () const
 
WriteConcern getWriteConcern () const
 
void setWriteConcern (WriteConcern w)
 
virtual unsigned long long query (boost::function< void(const BSONObj &)> f, const string &ns, Query query, const BSONObj *fieldsToReturn=0, int queryOptions=0)
 Uses QueryOption_Exhaust, when available. More...
 
virtual unsigned long long query (boost::function< void(DBClientCursorBatchIterator &)> f, const string &ns, Query query, const BSONObj *fieldsToReturn=0, int queryOptions=0)
 
virtual void update (const string &ns, Query query, BSONObj obj, bool upsert=false, bool multi=false)
 updates objects matching query
 
virtual void remove (const string &ns, Query q, bool justOne=0)
 remove matching objects from the database More...
 
virtual uint64_t getSockCreationMicroSec () const
 
- Public Member Functions inherited from mongo::DBClientWithCommands
bool simpleCommand (const string &dbname, BSONObj *info, const string &command)
 helper function. More...
 
virtual bool runCommand (const string &dbname, const BSONObj &cmd, BSONObj &info, int options=0)
 Run a database command. More...
 
void auth (const BSONObj &params)
 Authenticate a user. More...
 
bool auth (const string &dbname, const string &username, const string &pwd, string &errmsg, bool digestPassword=true)
 Authorize access to a particular database. More...
 
virtual void logout (const string &dbname, BSONObj &info)
 Logs out the connection for the given database. More...
 
virtual unsigned long long count (const string &ns, const BSONObj &query=BSONObj(), int options=0, int limit=0, int skip=0)
 count number of objects in collection ns that match the query criteria specified throws UserAssertion if database returns an error
 
string createPasswordDigest (const string &username, const string &clearTextPassword)
 
virtual bool isMaster (bool &isMaster, BSONObj *info=0)
 returns true in isMaster parm if this db is the current master of a replica pair. More...
 
bool createCollection (const string &ns, long long size=0, bool capped=false, int max=0, BSONObj *info=0)
 Create a new collection in the database. More...
 
string getLastError (const std::string &db, bool fsync=false, bool j=false, int w=0, int wtimeout=0)
 Get error result from the last write operation (insert/update/delete) on this connection. More...
 
string getLastError (bool fsync=false, bool j=false, int w=0, int wtimeout=0)
 
BSONObj getPrevError ()
 Return the last error which has occurred, even if not the very last operation. More...
 
bool resetError ()
 Reset the previous error state for this connection (accessed via getLastError and getPrevError). More...
 
virtual bool dropCollection (const string &ns, BSONObj *info=NULL)
 Delete the specified collection. More...
 
bool repairDatabase (const string &dbname, BSONObj *info=0)
 Perform a repair and compaction of the specified database. More...
 
bool copyDatabase (const string &fromdb, const string &todb, const string &fromhost="", BSONObj *info=0)
 Copy database from one server or name to another server or name. More...
 
bool setDbProfilingLevel (const string &dbname, ProfilingLevel level, BSONObj *info=0)
 
bool getDbProfilingLevel (const string &dbname, ProfilingLevel &level, BSONObj *info=0)
 
BSONObj mapreduce (const string &ns, const string &jsmapf, const string &jsreducef, BSONObj query=BSONObj(), MROutput output=MRInline)
 Run a map/reduce job on the server. More...
 
bool eval (const string &dbname, const string &jscode, BSONObj &info, BSONElement &retValue, BSONObj *args=0)
 Run javascript code on the database server. More...
 
bool validate (const string &ns, bool scandata=true)
 validate a collection, checking for errors and reporting back statistics. More...
 
bool eval (const string &dbname, const string &jscode)
 
template<class T >
bool eval (const string &dbname, const string &jscode, T parm1)
 
template<class T , class NumType >
bool eval (const string &dbname, const string &jscode, T parm1, NumType &ret)
 eval invocation with one parm to server and one numeric field (either int or double) returned
 
list< string > getDatabaseNames ()
 get a list of all the current databases uses the { listDatabases : 1 } command. More...
 
list< string > getCollectionNames (const string &db)
 get a list of all the current collections in db
 
bool exists (const string &ns)
 
virtual bool ensureIndex (const string &ns, BSONObj keys, bool unique=false, const string &name="", bool cache=true, bool background=false, int v=-1, int ttl=0)
 Create an index if it does not already exist. More...
 
virtual void resetIndexCache ()
 clears the index cache, so the subsequent call to ensureIndex for any index will go to the server
 
virtual auto_ptr< DBClientCursorgetIndexes (const string &ns)
 
virtual void dropIndex (const string &ns, BSONObj keys)
 
virtual void dropIndex (const string &ns, const string &indexName)
 
virtual void dropIndexes (const string &ns)
 drops all indexes for the collection
 
virtual void reIndex (const string &ns)
 
string genIndexName (const BSONObj &keys)
 
virtual bool dropDatabase (const string &dbname, BSONObj *info=0)
 Erase / drop an entire database.
 
- Public Member Functions inherited from mongo::DBClientInterface
void findN (vector< BSONObj > &out, const string &ns, Query query, int nToReturn, int nToSkip=0, const BSONObj *fieldsToReturn=0, int queryOptions=0)
 query N objects from the database into an array. More...
 
- Public Member Functions inherited from mongo::DBConnector
virtual bool recv (Message &m)
 
virtual void checkResponse (const char *data, int nReturned, bool *retry=NULL, string *targetHost=NULL)
 

Protected Member Functions

virtual void _auth (const BSONObj &params)
 

Additional Inherited Members

- Public Types inherited from mongo::DBClientWithCommands
enum  ProfilingLevel { ProfileOff = 0, ProfileSlow = 1, ProfileAll = 2 }
 The Mongo database provides built-in performance profiling capabilities. More...
 
- Static Public Member Functions inherited from mongo::DBClientWithCommands
static string getLastErrorString (const BSONObj &res)
 Can be called with the returned value from getLastErrorDetailed to extract an error string. More...
 
- Public Attributes inherited from mongo::DBClientWithCommands
int _logLevel
 controls how chatty the client is about network errors & such. More...
 
- Static Public Attributes inherited from mongo::DBClientBase
static const uint64_t INVALID_SOCK_CREATION_TIME
 
- Protected Attributes inherited from mongo::DBClientBase
long long _connectionId
 
WriteConcern _writeConcern
 
- Static Protected Attributes inherited from mongo::DBClientBase
static AtomicInt64 ConnectionIdSequence
 

Detailed Description

This is a connection to a cluster of servers that operate as one for super high durability.

Write operations are two-phase. First, all nodes are asked to fsync. If successful everywhere, the write is sent everywhere and then followed by an fsync. There is no rollback if a problem occurs during the second phase. Naturally, with all these fsyncs, these operations will be quite slow – use sparingly.

Read operations are sent to a single random node.

The class checks if a command is read or write style, and sends to a single node if a read lock command and to all in two phases with a write style command.

Constructor & Destructor Documentation

mongo::SyncClusterConnection::SyncClusterConnection ( const list< HostAndPort > &  L,
double  socketTimeout = 0 
)
Parameters
commaSeparatedshould be 3 hosts comma separated

Member Function Documentation

BSONObj mongo::SyncClusterConnection::findOne ( const string &  ns,
const Query query,
const BSONObj fieldsToReturn,
int  queryOptions 
)
virtual
Returns
a single object that matches the query. if none do, then the object is empty
Exceptions
AssertionException

Reimplemented from mongo::DBClientInterface.

BSONObj mongo::SyncClusterConnection::getLastErrorDetailed ( const std::string &  db,
bool  fsync = false,
bool  j = false,
int  w = 0,
int  wtimeout = 0 
)
virtual

Get error result from the last write operation (insert/update/delete) on this connection.

db doesn't change the command's behavior - it is just for auth checks.

Returns
full error object.

If "w" is -1, wait for propagation to majority of nodes. If "wtimeout" is 0, the operation will block indefinitely if needed.

Reimplemented from mongo::DBClientWithCommands.

auto_ptr< DBClientCursor > mongo::SyncClusterConnection::getMore ( const string &  ns,
long long  cursorId,
int  nToReturn,
int  options 
)
virtual

don't use this - called automatically by DBClientCursor for you

Parameters
cursorIdid of cursor to retrieve
Returns
an handle to a previously allocated cursor
Exceptions
AssertionException

Reimplemented from mongo::DBClientBase.

bool mongo::SyncClusterConnection::prepare ( string &  errmsg)
Returns
true if all servers are up and ready for writes
auto_ptr< DBClientCursor > mongo::SyncClusterConnection::query ( const string &  ns,
Query  query,
int  nToReturn,
int  nToSkip,
const BSONObj fieldsToReturn,
int  queryOptions,
int  batchSize 
)
virtual

send a query to the database.

Parameters
nsnamespace to query, format is <dbname>.<collectname>[.<collectname>]*
queryquery to perform on the collection. this is a BSONObj (binary JSON) You may format as { query: { ... }, orderby: { ... } } to specify a sort order.
nToReturnn to return (i.e., limit). 0 = unlimited
nToSkipstart with the nth item
fieldsToReturnoptional template of which fields to select. if unspecified, returns all fields
queryOptionssee options enum at top of this file
Returns
cursor. 0 if error (connection failure)
Exceptions
AssertionException

Reimplemented from mongo::DBClientBase.


The documentation for this class was generated from the following files: