summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/dbclient.h20
-rw-r--r--client/syncclusterconnection.cpp17
-rw-r--r--client/syncclusterconnection.h2
-rw-r--r--db/instance.h8
-rw-r--r--jstests/sharding/sync2.js10
-rw-r--r--jstests/sharding/sync4.js19
-rw-r--r--s/strategy.cpp11
-rw-r--r--s/strategy_single.cpp12
8 files changed, 76 insertions, 23 deletions
diff --git a/client/dbclient.h b/client/dbclient.h
index 7b78cfc90e4..39a2753e0e1 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -726,6 +726,11 @@ namespace mongo {
n++;
return n;
}
+
+ virtual bool callRead( Message& toSend , Message& response ) = 0;
+ // virtual bool callWrite( Message& toSend , Message& response ) = 0; // TODO: add this if needed
+ virtual void say( Message& toSend ) = 0;
+
}; // DBClientBase
class DBClientPaired;
@@ -831,15 +836,20 @@ namespace mongo {
virtual void killCursor( long long cursorID );
+ virtual bool callRead( Message& toSend , Message& response ){
+ return call( toSend , response );
+ }
+
+ virtual void say( Message &toSend );
+
protected:
friend class SyncClusterConnection;
virtual void recv( Message& m );
virtual bool call( Message &toSend, Message &response, bool assertOk = true );
- virtual void say( Message &toSend );
virtual void sayPiggyBack( Message &toSend );
virtual void checkResponse( const char *data, int nReturned );
};
-
+
/** Use this class to connect to a replica pair of servers. The class will manage
checking for which server in a replica pair is master, and do failover automatically.
@@ -926,13 +936,17 @@ namespace mongo {
DBClientConnection& masterConn();
DBClientConnection& slaveConn();
-
+
/* TODO - not yet implemented. mongos may need these. */
virtual bool call( Message &toSend, Message &response, bool assertOk=true ) { assert(false); return false; }
virtual void say( Message &toSend ) { assert(false); }
virtual void sayPiggyBack( Message &toSend ) { assert(false); }
virtual void checkResponse( const char *data, int nReturned ) { assert(false); }
+ virtual bool callRead( Message& toSend , Message& response ){
+ return call( toSend , response );
+ }
+
bool isFailed() const {
// TODO: this really should check isFailed on current master as well
return master < Left;
diff --git a/client/syncclusterconnection.cpp b/client/syncclusterconnection.cpp
index bb3178567f8..f32586bdc28 100644
--- a/client/syncclusterconnection.cpp
+++ b/client/syncclusterconnection.cpp
@@ -148,6 +148,11 @@ namespace mongo {
_conns.push_back( c );
}
+ bool SyncClusterConnection::callRead( Message& toSend , Message& response ){
+ // TODO: need to save state of which one to go back to somehow...
+ return _conns[0]->callRead( toSend , response );
+ }
+
BSONObj SyncClusterConnection::findOne(const string &ns, Query query, const BSONObj *fieldsToReturn, int queryOptions) {
if ( ns.find( ".$cmd" ) != string::npos ){
@@ -158,7 +163,7 @@ namespace mongo {
if ( lockType > 0 ){ // write $cmd
string errmsg;
if ( ! prepare( errmsg ) )
- throw UserException( 13104 , (string)"SyncClusterConnection::insert prepare failed: " + errmsg );
+ throw UserException( 13104 , (string)"SyncClusterConnection::findOne prepare failed: " + errmsg );
vector<BSONObj> all;
for ( size_t i=0; i<_conns.size(); i++ ){
@@ -327,7 +332,15 @@ namespace mongo {
}
void SyncClusterConnection::say( Message &toSend ){
- assert(0);
+ string errmsg;
+ if ( ! prepare( errmsg ) )
+ throw UserException( 13397 , (string)"SyncClusterConnection::say prepare failed: " + errmsg );
+
+ for ( size_t i=0; i<_conns.size(); i++ ){
+ _conns[i]->say( toSend );
+ }
+
+ _checkLast();
}
void SyncClusterConnection::sayPiggyBack( Message &toSend ){
diff --git a/client/syncclusterconnection.h b/client/syncclusterconnection.h
index e6d93b17c6f..9b0974c06c6 100644
--- a/client/syncclusterconnection.h
+++ b/client/syncclusterconnection.h
@@ -86,6 +86,8 @@ namespace mongo {
virtual BSONObj getLastErrorDetailed();
+ virtual bool callRead( Message& toSend , Message& response );
+
private:
SyncClusterConnection( SyncClusterConnection& prev );
string _toString() const;
diff --git a/db/instance.h b/db/instance.h
index 92593ea978a..16d7057f0af 100644
--- a/db/instance.h
+++ b/db/instance.h
@@ -119,7 +119,7 @@ namespace mongo {
public:
virtual auto_ptr<DBClientCursor> query(const string &ns, Query query, int nToReturn = 0, int nToSkip = 0,
const BSONObj *fieldsToReturn = 0, int queryOptions = 0);
-
+
virtual bool isFailed() const {
return false;
}
@@ -135,8 +135,12 @@ namespace mongo {
// don't need to piggy back when connected locally
return say( toSend );
}
-
+
virtual void killCursor( long long cursorID );
+
+ virtual bool callRead( Message& toSend , Message& response ){
+ return call( toSend , response );
+ }
};
extern int lockFile;
diff --git a/jstests/sharding/sync2.js b/jstests/sharding/sync2.js
index d7741ad1dfc..a5cc06c1b89 100644
--- a/jstests/sharding/sync2.js
+++ b/jstests/sharding/sync2.js
@@ -45,6 +45,16 @@ for ( var i=0; i<10; i++ ){
assert.eq( 7 , s2.getDB( "test" ).foo.find().toArray().length , "other B " + i );
}
+assert.eq( 0 , s.config.big.find().itcount() , "C1" );
+for ( i=0; i<50; i++ ){
+ s.config.big.insert( { _id : i } );
+}
+s.config.getLastError();
+assert.eq( 50 , s.config.big.find().itcount() , "C2" );
+assert.eq( 50 , s.config.big.find().count() , "C3" );
+assert.eq( 50 , s.config.big.find().batchSize(5).itcount() , "C4" );
+
+
hashes = []
for ( i=0; i<3; i++ ){
diff --git a/jstests/sharding/sync4.js b/jstests/sharding/sync4.js
new file mode 100644
index 00000000000..6733f07089d
--- /dev/null
+++ b/jstests/sharding/sync4.js
@@ -0,0 +1,19 @@
+
+test = new SyncCCTest( "sync4" )
+
+db = test.conn.getDB( "test" )
+t = db.sync4
+
+for ( i=0; i<1000; i++ ){
+ t.insert( { _id : i , x : "asdasdsdasdas" } )
+}
+db.getLastError();
+
+test.checkHashes( "test" , "A0" );
+assert.eq( 1000 , t.find().count() , "A1" )
+assert.eq( 1000 , t.find().itcount() , "A2" )
+assert.eq( 1000 , t.find().snapshot().batchSize(10).itcount() , "A2" )
+
+
+
+test.stop();
diff --git a/s/strategy.cpp b/s/strategy.cpp
index 3a73e5f8dd5..8ce27346862 100644
--- a/s/strategy.cpp
+++ b/s/strategy.cpp
@@ -28,14 +28,9 @@ namespace mongo {
// ----- Strategy ------
void Strategy::doWrite( int op , Request& r , const Shard& shard ){
- ShardConnection dbcon( shard , r.getns() );
- DBClientBase &_c = dbcon.conn();
-
- /* TODO FIX - do not case and call DBClientBase::say() */
- DBClientConnection&c = dynamic_cast<DBClientConnection&>(_c);
- c.port().say( r.m() );
-
- dbcon.done();
+ ShardConnection conn( shard , r.getns() );
+ conn->say( r.m() );
+ conn.done();
}
void Strategy::doQuery( Request& r , const Shard& shard ){
diff --git a/s/strategy_single.cpp b/s/strategy_single.cpp
index ddda15f7611..11a373106af 100644
--- a/s/strategy_single.cpp
+++ b/s/strategy_single.cpp
@@ -81,18 +81,14 @@ namespace mongo {
log(3) << "single getmore: " << ns << endl;
- ShardConnection dbcon( r.primaryShard() , ns );
- DBClientBase& _c = dbcon.conn();
-
- // TODO
- DBClientConnection &c = dynamic_cast<DBClientConnection&>(_c);
+ ShardConnection conn( r.primaryShard() , ns );
Message response;
- bool ok = c.port().call( r.m() , response);
+ bool ok = conn->callRead( r.m() , response);
uassert( 10204 , "dbgrid: getmore: error calling db", ok);
- r.reply( response , c.getServerAddress() );
+ r.reply( response , conn->getServerAddress() );
- dbcon.done();
+ conn.done();
}