本文整理汇总了C++中BatchedCommandResponse::toStatus方法的典型用法代码示例。如果您正苦于以下问题:C++ BatchedCommandResponse::toStatus方法的具体用法?C++ BatchedCommandResponse::toStatus怎么用?C++ BatchedCommandResponse::toStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BatchedCommandResponse
的用法示例。
在下文中一共展示了BatchedCommandResponse::toStatus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: unlockAll
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();
}
示例3: unlockAll
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();
}
示例4: makeSendFnForBatchWrite
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;
}
示例5: 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();
}