bool Sync::shouldRetry(const BSONObj& o) { // should already have write lock const char *ns = o.getStringField("ns"); Client::Context ctx(ns); // we don't have the object yet, which is possible on initial sync. get it. log() << "replication info adding missing object" << endl; // rare enough we can log BSONObj missingObj = getMissingDoc(o); if( missingObj.isEmpty() ) { log() << "replication missing object not found on source. presumably deleted later in oplog" << endl; log() << "replication o2: " << o.getObjectField("o2").toString() << endl; log() << "replication o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl; return false; } else { DiskLoc d = theDataFileMgr.insert(ns, (void*) missingObj.objdata(), missingObj.objsize()); uassert(15917, "Got bad disk location when attempting to insert", !d.isNull()); LOG(1) << "replication inserted missing doc: " << missingObj.toString() << endl; return true; } }
bool Sync::shouldRetry(const BSONObj& o) { // should already have write lock const char *ns = o.getStringField("ns"); Client::Context ctx(ns); OperationContextImpl txn; // we don't have the object yet, which is possible on initial sync. get it. log() << "replication info adding missing object" << endl; // rare enough we can log BSONObj missingObj = getMissingDoc(ctx.db(), o); if( missingObj.isEmpty() ) { log() << "replication missing object not found on source. presumably deleted later in oplog" << endl; log() << "replication o2: " << o.getObjectField("o2").toString() << endl; log() << "replication o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl; return false; } else { Collection* collection = ctx.db()->getOrCreateCollection( ns ); verify( collection ); // should never happen StatusWith<DiskLoc> result = collection->insertDocument( &txn, missingObj, true ); uassert(15917, str::stream() << "failed to insert missing doc: " << result.toString(), result.isOK() ); LOG(1) << "replication inserted missing doc: " << missingObj.toString() << endl; return true; } }
bool SyncTail::shouldRetry(OperationContext* txn, const BSONObj& o) { const NamespaceString nss(o.getStringField("ns")); MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { // Take an X lock on the database in order to preclude other modifications. // Also, the database might not exist yet, so create it. AutoGetOrCreateDb autoDb(txn, nss.db(), MODE_X); Database* const db = autoDb.getDb(); // we don't have the object yet, which is possible on initial sync. get it. log() << "adding missing object" << endl; // rare enough we can log BSONObj missingObj = getMissingDoc(txn, db, o); if (missingObj.isEmpty()) { log() << "missing object not found on source." " presumably deleted later in oplog"; log() << "o2: " << o.getObjectField("o2").toString(); log() << "o firstfield: " << o.getObjectField("o").firstElementFieldName(); return false; } else { WriteUnitOfWork wunit(txn); Collection* const coll = db->getOrCreateCollection(txn, nss.toString()); invariant(coll); Status status = coll->insertDocument(txn, missingObj, true); uassert(15917, str::stream() << "failed to insert missing doc: " << status.toString(), status.isOK()); LOG(1) << "inserted missing doc: " << missingObj.toString() << endl; wunit.commit(); return true; } } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "InsertRetry", nss.ns()); // fixes compile errors on GCC - see SERVER-18219 for details MONGO_UNREACHABLE; }
bool Sync::shouldRetry(OperationContext* txn, const BSONObj& o) { const NamespaceString nss(o.getStringField("ns")); // Take an X lock on the database in order to preclude other modifications. Also, the // database might not exist yet, so create it. AutoGetOrCreateDb autoDb(txn, nss.db(), MODE_X); Database* const db = autoDb.getDb(); // we don't have the object yet, which is possible on initial sync. get it. log() << "adding missing object" << endl; // rare enough we can log BSONObj missingObj = getMissingDoc(txn, db, o); if( missingObj.isEmpty() ) { log() << "missing object not found on source. presumably deleted later in oplog" << endl; log() << "o2: " << o.getObjectField("o2").toString() << endl; log() << "o firstfield: " << o.getObjectField("o").firstElementFieldName() << endl; return false; } else { WriteUnitOfWork wunit(txn); Collection* const collection = db->getOrCreateCollection(txn, nss.toString()); invariant(collection); StatusWith<RecordId> result = collection->insertDocument(txn, missingObj, true); uassert(15917, str::stream() << "failed to insert missing doc: " << result.getStatus().toString(), result.isOK() ); LOG(1) << "inserted missing doc: " << missingObj.toString() << endl; wunit.commit(); return true; } }