本文整理汇总了C++中DatabaseType::getPrimary方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseType::getPrimary方法的具体用法?C++ DatabaseType::getPrimary怎么用?C++ DatabaseType::getPrimary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseType
的用法示例。
在下文中一共展示了DatabaseType::getPrimary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shardCollection
Status CatalogManagerReplicaSet::shardCollection(OperationContext* txn,
const string& ns,
const ShardKeyPattern& fieldsAndOrder,
bool unique,
const vector<BSONObj>& initPoints,
const set<ShardId>& initShardIds) {
// Lock the collection globally so that no other mongos can try to shard or drop the collection
// at the same time.
auto scopedDistLock = getDistLockManager()->lock(ns, "shardCollection");
if (!scopedDistLock.isOK()) {
return scopedDistLock.getStatus();
}
StatusWith<DatabaseType> status = getDatabase(nsToDatabase(ns));
if (!status.isOK()) {
return status.getStatus();
}
DatabaseType dbt = status.getValue();
ShardId dbPrimaryShardId = dbt.getPrimary();
const auto primaryShard = grid.shardRegistry()->getShard(dbPrimaryShardId);
{
// In 3.0 and prior we include this extra safety check that the collection is not getting
// sharded concurrently by two different mongos instances. It is not 100%-proof, but it
// reduces the chance that two invocations of shard collection will step on each other's
// toes. Now we take the distributed lock so going forward this check won't be necessary
// but we leave it around for compatibility with other mongoses from 3.0.
// TODO(spencer): Remove this after 3.2 ships.
const auto configShard = grid.shardRegistry()->getShard("config");
const auto readHost = configShard->getTargeter()->findHost(kConfigReadSelector);
if (!readHost.isOK()) {
return readHost.getStatus();
}
auto countStatus = _runCountCommand(
readHost.getValue(), NamespaceString(ChunkType::ConfigNS), BSON(ChunkType::ns(ns)));
if (!countStatus.isOK()) {
return countStatus.getStatus();
}
if (countStatus.getValue() > 0) {
return Status(ErrorCodes::AlreadyInitialized,
str::stream() << "collection " << ns << " already sharded with "
<< countStatus.getValue() << " chunks.");
}
}
// Record start in changelog
{
BSONObjBuilder collectionDetail;
collectionDetail.append("shardKey", fieldsAndOrder.toBSON());
collectionDetail.append("collection", ns);
collectionDetail.append("primary", primaryShard->toString());
{
BSONArrayBuilder initialShards(collectionDetail.subarrayStart("initShards"));
for (const ShardId& shardId : initShardIds) {
initialShards.append(shardId);
}
}
collectionDetail.append("numChunks", static_cast<int>(initPoints.size() + 1));
logChange(txn->getClient()->clientAddress(true),
"shardCollection.start",
ns,
collectionDetail.obj());
}
ChunkManagerPtr manager(new ChunkManager(ns, fieldsAndOrder, unique));
manager->createFirstChunks(dbPrimaryShardId, &initPoints, &initShardIds);
manager->loadExistingRanges(nullptr);
CollectionInfo collInfo;
collInfo.useChunkManager(manager);
collInfo.save(ns);
manager->reload(true);
// TODO(spencer) SERVER-19319: Send setShardVersion to primary shard so it knows to start
// rejecting unversioned writes.
BSONObj finishDetail = BSON("version"
<< ""); // TODO(spencer) SERVER-19319 Report actual version used
logChange(txn->getClient()->clientAddress(true), "shardCollection", ns, finishDetail);
return Status::OK();
}
示例2: invariant
DBConfig::DBConfig(std::string name, const DatabaseType& dbt, repl::OpTime configOpTime)
: _name(name), _configOpTime(std::move(configOpTime)) {
invariant(_name == dbt.getName());
_primaryId = dbt.getPrimary();
_shardingEnabled = dbt.getSharded();
}