本文整理汇总了C++中boost::optional::appendToBuilder方法的典型用法代码示例。如果您正苦于以下问题:C++ optional::appendToBuilder方法的具体用法?C++ optional::appendToBuilder怎么用?C++ optional::appendToBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::optional
的用法示例。
在下文中一共展示了optional::appendToBuilder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shardCollection
void ShardingCatalogManager::shardCollection(OperationContext* opCtx,
const NamespaceString& nss,
const boost::optional<UUID> uuid,
const ShardKeyPattern& fieldsAndOrder,
const BSONObj& defaultCollation,
bool unique,
const vector<BSONObj>& splitPoints,
bool isFromMapReduce,
const ShardId& dbPrimaryShardId) {
const auto shardRegistry = Grid::get(opCtx)->shardRegistry();
const auto primaryShard = uassertStatusOK(shardRegistry->getShard(opCtx, dbPrimaryShardId));
// Fail if there are partially written chunks from a previous failed shardCollection.
checkForExistingChunks(opCtx, nss);
// Prior to 4.0.5, zones cannot be taken into account at collection sharding time, so ignore
// them and let the balancer apply them later
const std::vector<TagsType> treatAsNoZonesDefined;
// Map/reduce with output to sharded collection ignores consistency checks and requires the
// initial chunks to be spread across shards unconditionally
const bool treatAsEmpty = isFromMapReduce;
// Record start in changelog
{
BSONObjBuilder collectionDetail;
collectionDetail.append("shardKey", fieldsAndOrder.toBSON());
collectionDetail.append("collection", nss.ns());
if (uuid)
uuid->appendToBuilder(&collectionDetail, "uuid");
collectionDetail.append("empty", treatAsEmpty);
collectionDetail.append("fromMapReduce", isFromMapReduce);
collectionDetail.append("primary", primaryShard->toString());
collectionDetail.append("numChunks", static_cast<int>(splitPoints.size() + 1));
uassertStatusOK(ShardingLogging::get(opCtx)->logChangeChecked(
opCtx,
"shardCollection.start",
nss.ns(),
collectionDetail.obj(),
ShardingCatalogClient::kMajorityWriteConcern));
}
// Construct the collection default collator.
std::unique_ptr<CollatorInterface> defaultCollator;
if (!defaultCollation.isEmpty()) {
defaultCollator = uassertStatusOK(CollatorFactoryInterface::get(opCtx->getServiceContext())
->makeFromBSON(defaultCollation));
}
const auto initialChunks = InitialSplitPolicy::createFirstChunks(opCtx,
nss,
fieldsAndOrder,
dbPrimaryShardId,
splitPoints,
treatAsNoZonesDefined,
treatAsEmpty);
InitialSplitPolicy::writeFirstChunksToConfig(opCtx, initialChunks);
{
CollectionType coll;
coll.setNs(nss);
if (uuid)
coll.setUUID(*uuid);
coll.setEpoch(initialChunks.collVersion().epoch());
coll.setUpdatedAt(Date_t::fromMillisSinceEpoch(initialChunks.collVersion().toLong()));
coll.setKeyPattern(fieldsAndOrder.toBSON());
coll.setDefaultCollation(defaultCollator ? defaultCollator->getSpec().toBSON() : BSONObj());
coll.setUnique(unique);
uassertStatusOK(ShardingCatalogClientImpl::updateShardingCatalogEntryForCollection(
opCtx, nss, coll, true /*upsert*/));
}
auto shard = uassertStatusOK(shardRegistry->getShard(opCtx, dbPrimaryShardId));
invariant(!shard->isConfig());
// Tell the primary mongod to refresh its data
SetShardVersionRequest ssv = SetShardVersionRequest::makeForVersioningNoPersist(
shardRegistry->getConfigServerConnectionString(),
dbPrimaryShardId,
primaryShard->getConnString(),
nss,
initialChunks.collVersion(),
true /* isAuthoritative */,
true /* forceRefresh */);
auto ssvResponse =
shard->runCommandWithFixedRetryAttempts(opCtx,
ReadPreferenceSetting{ReadPreference::PrimaryOnly},
"admin",
ssv.toBSON(),
Shard::RetryPolicy::kIdempotent);
auto status = ssvResponse.isOK() ? std::move(ssvResponse.getValue().commandStatus)
: std::move(ssvResponse.getStatus());
if (!status.isOK()) {
warning() << "could not update initial version of " << nss.ns() << " on shard primary "
<< dbPrimaryShardId << causedBy(redact(status));
}
//.........这里部分代码省略.........