Skip to content

Commit

Permalink
SERVER-7443 - make sure writeback ids are in order
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Oct 24, 2012
1 parent 1870df0 commit e9a32c1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
11 changes: 1 addition & 10 deletions src/mongo/s/d_logic.cpp
Expand Up @@ -104,9 +104,6 @@ namespace mongo {
uassert(9517, "cannot queue a writeback operation to the writeback queue",
(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() );

Expand All @@ -122,7 +119,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 );
Expand All @@ -131,15 +127,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;
}

Expand Down
27 changes: 12 additions & 15 deletions src/mongo/s/d_writeback.cpp
Expand Up @@ -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 ) {
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/s/d_writeback.h
Expand Up @@ -58,8 +58,10 @@ namespace mongo {
*
* 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
Expand Down

0 comments on commit e9a32c1

Please sign in to comment.