本文整理汇总了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();
});
}
示例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();
}
示例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();
}
示例4: noteBatchError
void BatchWriteOp::noteBatchError( const TargetedWriteBatch& targetedBatch,
const BatchedErrorDetail& error ) {
BatchedCommandResponse response;
response.setOk( false );
cloneBatchErrorFrom( error, &response );
noteBatchResponse( targetedBatch, response, NULL );
}
示例5: retry
void ForwardingCatalogManager::writeConfigServerDirect(const BatchedCommandRequest& request,
BatchedCommandResponse* response) {
retry([&] {
BatchedCommandResponse theResponse;
_actual->writeConfigServerDirect(request, &theResponse);
theResponse.cloneTo(response);
});
}
示例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;
});
}
示例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;
}
示例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();
}
示例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;
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}