virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result) { boost::optional<DisableDocumentValidation> maybeDisableValidation; if (shouldBypassDocumentValidationForCommand(cmdObj)) maybeDisableValidation.emplace(txn); string fromhost = cmdObj.getStringField("from"); if (fromhost.empty()) { errmsg = "missing 'from' parameter"; return false; } { HostAndPort h(fromhost); if (repl::isSelf(h)) { errmsg = "can't cloneCollection from self"; return false; } } string collection = parseNs(dbname, cmdObj); Status allowedWriteStatus = userAllowedWriteNS(dbname, collection); if (!allowedWriteStatus.isOK()) { return appendCommandStatus(result, allowedWriteStatus); } BSONObj query = cmdObj.getObjectField("query"); if (query.isEmpty()) query = BSONObj(); BSONElement copyIndexesSpec = cmdObj.getField("copyindexes"); bool copyIndexes = copyIndexesSpec.isBoolean() ? copyIndexesSpec.boolean() : true; log() << "cloneCollection. db:" << dbname << " collection:" << collection << " from: " << fromhost << " query: " << query << " " << (copyIndexes ? "" : ", not copying indexes") << endl; Cloner cloner; unique_ptr<DBClientConnection> myconn; myconn.reset(new DBClientConnection()); if (!myconn->connect(HostAndPort(fromhost), errmsg)) return false; cloner.setConnection(myconn.release()); return cloner.copyCollection( txn, collection, query, errmsg, true, true /* interruptable */, copyIndexes); }
void RollbackSourceImpl::copyCollectionFromRemote(OperationContext* opCtx, const NamespaceString& nss) const { std::string errmsg; std::unique_ptr<DBClientConnection> tmpConn(new DBClientConnection()); uassert(15908, errmsg, tmpConn->connect(_source, StringData(), errmsg) && replAuthenticate(tmpConn.get())); // cloner owns _conn in unique_ptr Cloner cloner; cloner.setConnection(tmpConn.release()); uassert(15909, str::stream() << "replSet rollback error resyncing collection " << nss.ns() << ' ' << errmsg, cloner.copyCollection(opCtx, nss.ns(), BSONObj(), errmsg, true)); }
virtual bool run(OperationContext* txn, const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) { string fromhost = cmdObj.getStringField("from"); if ( fromhost.empty() ) { errmsg = "missing 'from' parameter"; return false; } { HostAndPort h(fromhost); if (repl::isSelf(h)) { errmsg = "can't cloneCollection from self"; return false; } } string collection = parseNs(dbname, cmdObj); if ( collection.empty() ) { errmsg = "bad 'cloneCollection' value"; return false; } BSONObj query = cmdObj.getObjectField("query"); if ( query.isEmpty() ) query = BSONObj(); BSONElement copyIndexesSpec = cmdObj.getField("copyindexes"); bool copyIndexes = copyIndexesSpec.isBoolean() ? copyIndexesSpec.boolean() : true; log() << "cloneCollection. db:" << dbname << " collection:" << collection << " from: " << fromhost << " query: " << query << " " << ( copyIndexes ? "" : ", not copying indexes" ) << endl; Cloner cloner; auto_ptr<DBClientConnection> myconn; myconn.reset( new DBClientConnection() ); if ( ! myconn->connect( fromhost , errmsg ) ) return false; cloner.setConnection( myconn.release() ); return cloner.copyCollection(txn, collection, query, errmsg, true, false, copyIndexes); }
void RollbackSourceImpl::copyCollectionFromRemote(OperationContext* opCtx, const NamespaceString& nss) const { std::string errmsg; auto tmpConn = stdx::make_unique<DBClientConnection>(); uassert(15908, errmsg, tmpConn->connect(_source, StringData(), errmsg) && replAuthenticate(tmpConn.get())); // cloner owns _conn in unique_ptr Cloner cloner; cloner.setConnection(std::move(tmpConn)); uassert(15909, str::stream() << "replSet rollback error resyncing collection " << nss.ns() << ' ' << errmsg, cloner.copyCollection( opCtx, nss.ns(), BSONObj(), errmsg, true, CollectionOptions::parseForStorage)); }