summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-10-22 11:24:00 -0400
committerEric Milkie <milkie@10gen.com>2012-11-06 15:50:50 -0500
commitc8dd82004a6759d3485ad1b2a9d49947c52cbf1a (patch)
treef09413dfba8394e57d5825898936e041e222b4f8
parentfdebd7bae6ca938a80713694ef2dfe360f3dc27f (diff)
downloadmongo-c8dd82004a6759d3485ad1b2a9d49947c52cbf1a.tar.gz
SERVER-7443 - make sure writeback ids are in order
Conflicts: src/mongo/s/d_writeback.h
-rw-r--r--src/mongo/s/d_logic.cpp11
-rw-r--r--src/mongo/s/d_writeback.cpp27
-rw-r--r--src/mongo/s/d_writeback.h8
3 files changed, 18 insertions, 28 deletions
diff --git a/src/mongo/s/d_logic.cpp b/src/mongo/s/d_logic.cpp
index dcf66033428..c58ed173968 100644
--- a/src/mongo/s/d_logic.cpp
+++ b/src/mongo/s/d_logic.cpp
@@ -103,9 +103,6 @@ namespace mongo {
uassert( 9517 , "writeback" , ( d.reservedField() & Reserved_FromWriteback ) == 0 );
- OID writebackID;
- writebackID.initSequential();
-
const OID& clientID = ShardedConnectionInfo::get(false)->getID();
massert( 10422 , "write with bad shard config and no server id!" , clientID.isSet() );
@@ -121,7 +118,6 @@ namespace mongo {
BSONObjBuilder b;
b.appendBool( "writeBack" , true );
b.append( "ns" , ns );
- b.append( "id" , writebackID );
b.append( "connectionId" , cc().getConnectionId() );
b.append( "instanceIdent" , prettyHostName() );
wanted.addToBSON( b );
@@ -130,15 +126,10 @@ namespace mongo {
b.appendBinData( "msg" , m.header()->len , bdtCustom , (char*)(m.singleData()) );
LOG(2) << "writing back msg with len: " << m.header()->len << " op: " << m.operation() << endl;
- // Convert to new BSONObj here just to be safe
- BSONObj wbObj = b.obj();
+ OID writebackID = writeBackManager.queueWriteBack( clientID.str() , b );
- // Don't register the writeback until immediately before we queue it -
- // after this line, mongos will wait for an hour if we don't queue correctly
lastError.getSafe()->writeback( writebackID );
- writeBackManager.queueWriteBack( clientID.str() , wbObj );
-
return true;
}
diff --git a/src/mongo/s/d_writeback.cpp b/src/mongo/s/d_writeback.cpp
index 0278e40f712..441de1a0d65 100644
--- a/src/mongo/s/d_writeback.cpp
+++ b/src/mongo/s/d_writeback.cpp
@@ -42,21 +42,18 @@ namespace mongo {
WriteBackManager::~WriteBackManager() {
}
- void WriteBackManager::queueWriteBack( const string& remote , const BSONObj& o ) {
- static mongo::mutex xxx( "WriteBackManager::queueWriteBack tmp" );
- static OID lastOID;
-
- scoped_lock lk( xxx );
- const BSONElement& e = o["id"];
-
- if ( lastOID.isSet() ) {
- if ( e.OID() < lastOID ) {
- log() << "this could fail" << endl;
- printStackTrace();
- }
- }
- lastOID = e.OID();
- getWritebackQueue( remote )->queue.push( o );
+ OID WriteBackManager::queueWriteBack( const string& remote , BSONObjBuilder& b ) {
+ static mongo::mutex writebackIDOrdering( "WriteBackManager::queueWriteBack id ordering" );
+
+ scoped_lock lk( writebackIDOrdering );
+
+ OID writebackID;
+ writebackID.initSequential();
+ b.append( "id", writebackID );
+
+ getWritebackQueue( remote )->queue.push( b.obj() );
+
+ return writebackID;
}
shared_ptr<WriteBackManager::QueueInfo> WriteBackManager::getWritebackQueue( const string& remote ) {
diff --git a/src/mongo/s/d_writeback.h b/src/mongo/s/d_writeback.h
index fc5d9c19f29..38ce386515b 100644
--- a/src/mongo/s/d_writeback.h
+++ b/src/mongo/s/d_writeback.h
@@ -56,10 +56,12 @@ namespace mongo {
* @param remote server ID this operation came from
* @param op the operation itself
*
- * Enqueues opeartion 'op' in server 'remote's queue. The operation will be written back to
- * remote at a later stager.
+ * Enqueues operation 'op' in server 'remote's queue. The operation will be written back to
+ * remote at a later stage.
+ *
+ * @return the writebackId generated
*/
- void queueWriteBack( const string& remote , const BSONObj& op );
+ OID queueWriteBack( const string& remote , BSONObjBuilder& opBuilder );
/*
* @param remote server ID