当前位置: 首页>>代码示例>>C++>>正文


C++ BatchedCommandResponse类代码示例

本文整理汇总了C++中BatchedCommandResponse的典型用法代码示例。如果您正苦于以下问题:C++ BatchedCommandResponse类的具体用法?C++ BatchedCommandResponse怎么用?C++ BatchedCommandResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BatchedCommandResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onCommand

void ShardingTestFixture::expectInserts(const NamespaceString& nss,
                                        const std::vector<BSONObj>& expected) {
    onCommand([&nss, &expected](const RemoteCommandRequest& request) {
        ASSERT_EQUALS(nss.db(), request.dbname);

        BatchedInsertRequest actualBatchedInsert;
        std::string errmsg;
        ASSERT_TRUE(actualBatchedInsert.parseBSON(request.dbname, request.cmdObj, &errmsg));

        ASSERT_EQUALS(nss.toString(), actualBatchedInsert.getNS().toString());

        auto inserted = actualBatchedInsert.getDocuments();
        ASSERT_EQUALS(expected.size(), inserted.size());

        auto itInserted = inserted.begin();
        auto itExpected = expected.begin();

        for (; itInserted != inserted.end(); itInserted++, itExpected++) {
            ASSERT_EQ(*itExpected, *itInserted);
        }

        BatchedCommandResponse response;
        response.setOk(true);

        return response.toBSON();
    });
}
开发者ID:GodotGo,项目名称:mongo,代码行数:27,代码来源:sharding_test_fixture.cpp

示例2: dassert

bool WriteCmd::run(OperationContext* txn,
                   const string& dbName,
                   BSONObj& cmdObj,
                   int options,
                   string& errMsg,
                   BSONObjBuilder& result,
                   bool fromRepl) {
    // Can't be run on secondaries (logTheOp() == false, slaveOk() == false).
    dassert(!fromRepl);
    BatchedCommandRequest request(_writeType);
    BatchedCommandResponse response;

    if (!request.parseBSON(cmdObj, &errMsg) || !request.isValid(&errMsg)) {
        return appendCommandStatus(result, Status(ErrorCodes::FailedToParse, errMsg));
    }

    // Note that this is a runCommmand, and therefore, the database and the collection name
    // are in different parts of the grammar for the command. But it's more convenient to
    // work with a NamespaceString. We built it here and replace it in the parsed command.
    // Internally, everything work with the namespace string as opposed to just the
    // collection name.
    NamespaceString nss(dbName, request.getNS());
    request.setNSS(nss);

    WriteConcernOptions defaultWriteConcern =
        repl::getGlobalReplicationCoordinator()->getGetLastErrorDefault();

    WriteBatchExecutor writeBatchExecutor(
        txn, defaultWriteConcern, &globalOpCounters, lastError.get());

    writeBatchExecutor.executeBatch(request, &response);

    result.appendElements(response.toBSON());
    return response.getOk();
}
开发者ID:DavidAlphaFox,项目名称:mongodb,代码行数:35,代码来源:write_commands.cpp

示例3: dassert

bool WriteCmd::run(OperationContext* txn,
                   const string& dbName,
                   BSONObj& cmdObj,
                   int options,
                   string& errMsg,
                   BSONObjBuilder& result) {
    // Can't be run on secondaries.
    dassert(txn->writesAreReplicated());
    BatchedCommandRequest request(_writeType);
    BatchedCommandResponse response;

    if (!request.parseBSON(dbName, cmdObj, &errMsg) || !request.isValid(&errMsg)) {
        return appendCommandStatus(result, Status(ErrorCodes::FailedToParse, errMsg));
    }

    StatusWith<WriteConcernOptions> wcStatus = extractWriteConcern(cmdObj, dbName);

    if (!wcStatus.isOK()) {
        return appendCommandStatus(result, wcStatus.getStatus());
    }
    txn->setWriteConcern(wcStatus.getValue());

    WriteBatchExecutor writeBatchExecutor(
        txn, &globalOpCounters, &LastError::get(txn->getClient()));

    writeBatchExecutor.executeBatch(request, &response);

    result.appendElements(response.toBSON());
    return response.getOk();
}
开发者ID:gastongouron,项目名称:mongo,代码行数:30,代码来源:write_commands.cpp

示例4: noteBatchError

 void BatchWriteOp::noteBatchError( const TargetedWriteBatch& targetedBatch,
                                    const BatchedErrorDetail& error ) {
     BatchedCommandResponse response;
     response.setOk( false );
     cloneBatchErrorFrom( error, &response );
     noteBatchResponse( targetedBatch, response, NULL );
 }
开发者ID:hipsterbd,项目名称:mongo,代码行数:7,代码来源:batch_write_op.cpp

示例5: retry

void ForwardingCatalogManager::writeConfigServerDirect(const BatchedCommandRequest& request,
                                                       BatchedCommandResponse* response) {
    retry([&] {
        BatchedCommandResponse theResponse;
        _actual->writeConfigServerDirect(request, &theResponse);
        theResponse.cloneTo(response);
    });
}
开发者ID:pmq20,项目名称:mongo,代码行数:8,代码来源:forwarding_catalog_manager.cpp

示例6: retry

void ForwardingCatalogManager::writeConfigServerDirect(OperationContext* txn,
                                                       const BatchedCommandRequest& request,
                                                       BatchedCommandResponse* response) {
    retry([&] {
        BatchedCommandResponse theResponse;
        _actual->writeConfigServerDirect(txn, request, &theResponse);
        theResponse.cloneTo(response);
        return 1;
    });
}
开发者ID:jiangjian-zh,项目名称:mongo,代码行数:10,代码来源:forwarding_catalog_manager.cpp

示例7: remove

    Status AuthzManagerExternalStateMongos::remove(
            const NamespaceString& collectionName,
            const BSONObj& query,
            const BSONObj& writeConcern,
            int* numRemoved) {
        BatchedCommandResponse response;
        Status res = clusterDelete(collectionName, query, 0 /* limit */, writeConcern, &response);

        if (res.isOK()) {
            *numRemoved = response.getN();
        }

        return res;
    }
开发者ID:AndrewCEmil,项目名称:mongo,代码行数:14,代码来源:authz_manager_external_state_s.cpp

示例8: dassert

    bool WriteCmd::run(const string& dbName,
                       BSONObj& cmdObj,
                       int options,
                       string& errMsg,
                       BSONObjBuilder& result,
                       bool fromRepl) {

        // Can't be run on secondaries (logTheOp() == false, slaveOk() == false).
        dassert( !fromRepl );
        BatchedCommandRequest request( _writeType );
        BatchedCommandResponse response;

        if ( !request.parseBSON( cmdObj, &errMsg ) || !request.isValid( &errMsg ) ) {
            return appendCommandStatus( result, Status( ErrorCodes::FailedToParse, errMsg ) );
        }

        // Note that this is a runCommmand, and therefore, the database and the collection name
        // are in different parts of the grammar for the command. But it's more convenient to
        // work with a NamespaceString. We built it here and replace it in the parsed command.
        // Internally, everything work with the namespace string as opposed to just the
        // collection name.
        NamespaceString nss(dbName, request.getNS());
        request.setNS(nss.ns());

        Status status = userAllowedWriteNS( nss );
        if ( !status.isOK() )
            return appendCommandStatus( result, status );

        BSONObj defaultWriteConcern;
        // This is really bad - it's only safe because we leak the defaults by overriding them with
        // new defaults and because we never reset to an empty default.
        // TODO: fix this for sane behavior where we query repl set object
        if ( getLastErrorDefault ) defaultWriteConcern = *getLastErrorDefault;
        if ( defaultWriteConcern.isEmpty() ) {
            BSONObjBuilder b;
            b.append( "w", 1 );
            defaultWriteConcern = b.obj();
        }

        WriteBatchExecutor writeBatchExecutor(defaultWriteConcern,
                                              &cc(),
                                              &globalOpCounters,
                                              lastError.get());

        writeBatchExecutor.executeBatch( request, &response );

        result.appendElements( response.toBSON() );
        return response.getOk();
    }
开发者ID:Attnaorg,项目名称:mongo,代码行数:49,代码来源:write_commands.cpp

示例9: dassert

void Strategy::writeOp(OperationContext* txn, int op, Request& request) {
    // make sure we have a last error
    dassert(&LastError::get(cc()));

    OwnedPointerVector<BatchedCommandRequest> commandRequestsOwned;
    vector<BatchedCommandRequest*>& commandRequests = commandRequestsOwned.mutableVector();

    msgToBatchRequests(request.m(), &commandRequests);

    for (vector<BatchedCommandRequest*>::iterator it = commandRequests.begin();
         it != commandRequests.end();
         ++it) {
        // Multiple commands registered to last error as multiple requests
        if (it != commandRequests.begin())
            LastError::get(cc()).startRequest();

        BatchedCommandRequest* commandRequest = *it;

        // Adjust namespaces for command
        NamespaceString fullNS(commandRequest->getNS());
        string cmdNS = fullNS.getCommandNS();
        // We only pass in collection name to command
        commandRequest->setNS(fullNS);

        BSONObjBuilder builder;
        BSONObj requestBSON = commandRequest->toBSON();

        {
            // Disable the last error object for the duration of the write cmd
            LastError::Disabled disableLastError(&LastError::get(cc()));
            Command::runAgainstRegistered(txn, cmdNS.c_str(), requestBSON, builder, 0);
        }

        BatchedCommandResponse commandResponse;
        bool parsed = commandResponse.parseBSON(builder.done(), NULL);
        (void)parsed;  // for compile
        dassert(parsed && commandResponse.isValid(NULL));

        // Populate the lastError object based on the write response
        LastError::get(cc()).reset();
        bool hadError =
            batchErrorToLastError(*commandRequest, commandResponse, &LastError::get(cc()));

        // Check if this is an ordered batch and we had an error which should stop processing
        if (commandRequest->getOrdered() && hadError)
            break;
    }
}
开发者ID:CeperaCPP,项目名称:mongo,代码行数:48,代码来源:strategy.cpp

示例10: refreshSessions

Status SessionsCollectionSharded::refreshSessions(OperationContext* opCtx,
                                                  const LogicalSessionRecordSet& sessions) {
    auto send = [&](BSONObj toSend) {
        auto opMsg =
            OpMsgRequest::fromDBAndBody(NamespaceString::kLogicalSessionsNamespace.db(), toSend);
        auto request = BatchedCommandRequest::parseUpdate(opMsg);

        BatchedCommandResponse response;
        BatchWriteExecStats stats;

        ClusterWriter::write(opCtx, request, &stats, &response);
        return response.toStatus();
    };

    return doRefresh(NamespaceString::kLogicalSessionsNamespace, sessions, send);
}
开发者ID:EvgeniyPatlan,项目名称:percona-server-mongodb,代码行数:16,代码来源:sessions_collection_sharded.cpp

示例11: request

Status DistLockCatalogImpl::unlockAll(OperationContext* opCtx, const std::string& processID) {
    BatchedCommandRequest request([&] {
        write_ops::Update updateOp(_locksNS);
        updateOp.setUpdates({[&] {
            write_ops::UpdateOpEntry entry;
            entry.setQ(BSON(LocksType::process(processID)));
            entry.setU(BSON("$set" << BSON(LocksType::state(LocksType::UNLOCKED))));
            entry.setUpsert(false);
            entry.setMulti(true);
            return entry;
        }()});
        return updateOp;
    }());
    request.setWriteConcern(kLocalWriteConcern.toBSON());

    BSONObj cmdObj = request.toBSON();

    auto const shardRegistry = Grid::get(opCtx)->shardRegistry();
    auto response = shardRegistry->getConfigShard()->runCommandWithFixedRetryAttempts(
        opCtx,
        ReadPreferenceSetting{ReadPreference::PrimaryOnly},
        _locksNS.db().toString(),
        cmdObj,
        Shard::kDefaultConfigCommandTimeout,
        Shard::RetryPolicy::kIdempotent);

    if (!response.isOK()) {
        return response.getStatus();
    }
    if (!response.getValue().commandStatus.isOK()) {
        return response.getValue().commandStatus;
    }
    if (!response.getValue().writeConcernStatus.isOK()) {
        return response.getValue().writeConcernStatus;
    }

    BatchedCommandResponse batchResponse;
    std::string errmsg;
    if (!batchResponse.parseBSON(response.getValue().response, &errmsg)) {
        return Status(ErrorCodes::FailedToParse,
                      str::stream()
                          << "Failed to parse config server response to batch request for "
                             "unlocking existing distributed locks"
                          << causedBy(errmsg));
    }
    return batchResponse.toStatus();
}
开发者ID:DINKIN,项目名称:mongo,代码行数:47,代码来源:dist_lock_catalog_impl.cpp

示例12: updateDoc

Status DistLockCatalogImpl::unlockAll(OperationContext* txn, const std::string& processID) {
    std::unique_ptr<BatchedUpdateDocument> updateDoc(new BatchedUpdateDocument());
    updateDoc->setQuery(BSON(LocksType::process(processID)));
    updateDoc->setUpdateExpr(BSON("$set" << BSON(LocksType::state(LocksType::UNLOCKED))));
    updateDoc->setUpsert(false);
    updateDoc->setMulti(true);

    std::unique_ptr<BatchedUpdateRequest> updateRequest(new BatchedUpdateRequest());
    updateRequest->addToUpdates(updateDoc.release());

    BatchedCommandRequest request(updateRequest.release());
    request.setNS(_locksNS);
    request.setWriteConcern(kLocalWriteConcern.toBSON());

    BSONObj cmdObj = request.toBSON();

    auto response = _client->getConfigShard()->runCommandWithFixedRetryAttempts(
        txn,
        ReadPreferenceSetting{ReadPreference::PrimaryOnly},
        _locksNS.db().toString(),
        cmdObj,
        Shard::kDefaultConfigCommandTimeout,
        Shard::RetryPolicy::kIdempotent);

    if (!response.isOK()) {
        return response.getStatus();
    }
    if (!response.getValue().commandStatus.isOK()) {
        return response.getValue().commandStatus;
    }
    if (!response.getValue().writeConcernStatus.isOK()) {
        return response.getValue().writeConcernStatus;
    }

    BatchedCommandResponse batchResponse;
    std::string errmsg;
    if (!batchResponse.parseBSON(response.getValue().response, &errmsg)) {
        return Status(ErrorCodes::FailedToParse,
                      str::stream()
                          << "Failed to parse config server response to batch request for "
                             "unlocking existing distributed locks"
                          << causedBy(errmsg));
    }
    return batchResponse.toStatus();
}
开发者ID:Machyne,项目名称:mongo,代码行数:45,代码来源:dist_lock_catalog_impl.cpp

示例13: fassert

Status CatalogManager::updateDatabase(const std::string& dbName, const DatabaseType& db) {
    fassert(28616, db.validate());

    BatchedCommandResponse response;
    Status status = update(DatabaseType::ConfigNS,
                           BSON(DatabaseType::name(dbName)),
                           db.toBSON(),
                           true,   // upsert
                           false,  // multi
                           &response);
    if (!status.isOK()) {
        return Status(status.code(),
                      str::stream() << "database metadata write failed: " << response.toBSON()
                      << "; status: " << status.toString());
    }

    return Status::OK();
}
开发者ID:yongseoklee,项目名称:mongo,代码行数:18,代码来源:catalog_manager.cpp

示例14: getStatusFromCommandResult

SessionsCollection::SendBatchFn SessionsCollection::makeSendFnForBatchWrite(
    const NamespaceString& ns, DBClientBase* client) {
    auto send = [client, ns](BSONObj batch) -> Status {
        BSONObj res;
        if (!client->runCommand(ns.db().toString(), batch, res)) {
            return getStatusFromCommandResult(res);
        }

        BatchedCommandResponse response;
        std::string errmsg;
        if (!response.parseBSON(res, &errmsg)) {
            return {ErrorCodes::FailedToParse, errmsg};
        }

        return response.toStatus();
    };

    return send;
}
开发者ID:zhihuiFan,项目名称:mongo,代码行数:19,代码来源:sessions_collection.cpp

示例15: clusterCreateIndex

Status clusterCreateIndex(OperationContext* txn, const string& ns, BSONObj keys, bool unique) {
    const NamespaceString nss(ns);
    const std::string dbName = nss.db().toString();

    BSONObj indexDoc = createIndexDoc(ns, keys, unique);

    // Go through the shard insert path
    std::unique_ptr<BatchedInsertRequest> insert(new BatchedInsertRequest());
    insert->addToDocuments(indexDoc);

    BatchedCommandRequest request(insert.release());
    request.setNS(NamespaceString(nss.getSystemIndexesCollection()));
    request.setWriteConcern(WriteConcernOptions::Acknowledged);

    BatchedCommandResponse response;

    ClusterWriter writer(false, 0);
    writer.write(txn, request, &response);

    return response.toStatus();
}
开发者ID:benjaminmurphy,项目名称:mongo,代码行数:21,代码来源:cluster_write.cpp


注:本文中的BatchedCommandResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。