本文整理汇总了C++中ChunkManagerPtr::getShardKeyPattern方法的典型用法代码示例。如果您正苦于以下问题:C++ ChunkManagerPtr::getShardKeyPattern方法的具体用法?C++ ChunkManagerPtr::getShardKeyPattern怎么用?C++ ChunkManagerPtr::getShardKeyPattern使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChunkManagerPtr
的用法示例。
在下文中一共展示了ChunkManagerPtr::getShardKeyPattern方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _doBalanceRound
//.........这里部分代码省略.........
return;
}
allChunkMinimums.insert(chunk->getMin().getOwned());
OwnedPointerVector<ChunkType>*& chunkList =
shardToChunksMap.mutableMap()[chunk->getShard()];
if (chunkList == NULL) {
chunkList = new OwnedPointerVector<ChunkType>();
}
chunkList->mutableVector().push_back(chunk.release());
}
cursor.reset();
if (shardToChunksMap.map().empty()) {
LOG(1) << "skipping empty collection (" << ns << ")";
continue;
}
for (ShardInfoMap::const_iterator i = shardInfo.begin(); i != shardInfo.end(); ++i) {
// this just makes sure there is an entry in shardToChunksMap for every shard
OwnedPointerVector<ChunkType>*& chunkList = shardToChunksMap.mutableMap()[i->first];
if (chunkList == NULL) {
chunkList = new OwnedPointerVector<ChunkType>();
}
}
DistributionStatus status(shardInfo, shardToChunksMap.map());
// load tags
cursor = conn.query(TagsType::ConfigNS, QUERY(TagsType::ns(ns)).sort(TagsType::min()));
vector<TagRange> ranges;
while (cursor->more()) {
BSONObj tag = cursor->nextSafe();
TagRange tr(tag[TagsType::min()].Obj().getOwned(),
tag[TagsType::max()].Obj().getOwned(),
tag[TagsType::tag()].String());
ranges.push_back(tr);
uassert(
16356, str::stream() << "tag ranges not valid for: " << ns, status.addTagRange(tr));
}
cursor.reset();
DBConfigPtr cfg = grid.getDBConfig(ns);
if (!cfg) {
warning() << "could not load db config to balance " << ns << " collection" << endl;
continue;
}
// This line reloads the chunk manager once if this process doesn't know the collection
// is sharded yet.
ChunkManagerPtr cm = cfg->getChunkManagerIfExists(ns, true);
if (!cm) {
warning() << "could not load chunks to balance " << ns << " collection" << endl;
continue;
}
// loop through tags to make sure no chunk spans tags; splits on tag min. for all chunks
bool didAnySplits = false;
for (unsigned i = 0; i < ranges.size(); i++) {
BSONObj min = ranges[i].min;
min = cm->getShardKeyPattern().getKeyPattern().extendRangeBound(min, false);
if (allChunkMinimums.count(min) > 0)
continue;
didAnySplits = true;
log() << "ns: " << ns << " need to split on " << min
<< " because there is a range there" << endl;
ChunkPtr c = cm->findIntersectingChunk(min);
vector<BSONObj> splitPoints;
splitPoints.push_back(min);
Status status = c->multiSplit(splitPoints, NULL);
if (!status.isOK()) {
error() << "split failed: " << status << endl;
} else {
LOG(1) << "split worked" << endl;
}
break;
}
if (didAnySplits) {
// state change, just wait till next round
continue;
}
CandidateChunk* p = _policy->balance(ns, status, _balancedLastTime);
if (p)
candidateChunks->push_back(CandidateChunkPtr(p));
}
}
示例2: runAggregate
Status ClusterAggregate::runAggregate(OperationContext* txn,
const Namespaces& namespaces,
BSONObj cmdObj,
int options,
BSONObjBuilder* result) {
auto dbname = namespaces.executionNss.db().toString();
auto status = grid.catalogCache()->getDatabase(txn, dbname);
if (!status.isOK()) {
appendEmptyResultSet(*result, status.getStatus(), namespaces.requestedNss.ns());
return Status::OK();
}
std::shared_ptr<DBConfig> conf = status.getValue();
if (!conf->isShardingEnabled()) {
return aggPassthrough(txn, namespaces, conf, cmdObj, result, options);
}
auto request = AggregationRequest::parseFromBSON(namespaces.executionNss, cmdObj);
if (!request.isOK()) {
return request.getStatus();
}
boost::intrusive_ptr<ExpressionContext> mergeCtx =
new ExpressionContext(txn, request.getValue());
mergeCtx->inRouter = true;
// explicitly *not* setting mergeCtx->tempDir
// Parse and optimize the pipeline specification.
auto pipeline = Pipeline::parse(request.getValue().getPipeline(), mergeCtx);
if (!pipeline.isOK()) {
return pipeline.getStatus();
}
for (auto&& ns : pipeline.getValue()->getInvolvedCollections()) {
uassert(28769, str::stream() << ns.ns() << " cannot be sharded", !conf->isSharded(ns.ns()));
// We won't try to execute anything on a mongos, but we still have to populate this map
// so that any $lookups etc will be able to have a resolved view definition. It's okay
// that this is incorrect, we will repopulate the real resolved namespace map on the
// mongod.
// TODO SERVER-25038 This should become unnecessary once we can get the involved
// namespaces before parsing.
mergeCtx->resolvedNamespaces[ns.coll()] = {ns, std::vector<BSONObj>{}};
}
if (!conf->isSharded(namespaces.executionNss.ns())) {
return aggPassthrough(txn, namespaces, conf, cmdObj, result, options);
}
ChunkManagerPtr chunkMgr = conf->getChunkManager(txn, namespaces.executionNss.ns());
// If there was no collation specified, but there is a default collation for the collation,
// use that.
if (request.getValue().getCollation().isEmpty() && chunkMgr->getDefaultCollator()) {
mergeCtx->setCollator(chunkMgr->getDefaultCollator()->clone());
}
// Now that we know the collation we'll be using, inject the ExpressionContext and optimize.
// TODO SERVER-25038: this must happen before we parse the pipeline, since we can make
// string comparisons during parse time.
pipeline.getValue()->injectExpressionContext(mergeCtx);
pipeline.getValue()->optimizePipeline();
// If the first $match stage is an exact match on the shard key (with a simple collation or
// no string matching), we only have to send it to one shard, so send the command to that
// shard.
BSONObj firstMatchQuery = pipeline.getValue()->getInitialQuery();
BSONObj shardKeyMatches;
shardKeyMatches = uassertStatusOK(
chunkMgr->getShardKeyPattern().extractShardKeyFromQuery(txn, firstMatchQuery));
bool singleShard = false;
if (!shardKeyMatches.isEmpty()) {
auto chunk = chunkMgr->findIntersectingChunk(
txn, shardKeyMatches, request.getValue().getCollation());
if (chunk.isOK()) {
singleShard = true;
}
}
// Don't need to split pipeline if the first $match is an exact match on shard key, unless
// there is a stage that needs to be run on the primary shard.
const bool needPrimaryShardMerger = pipeline.getValue()->needsPrimaryShardMerger();
const bool needSplit = !singleShard || needPrimaryShardMerger;
// Split the pipeline into pieces for mongod(s) and this mongos. If needSplit is true,
// 'pipeline' will become the merger side.
boost::intrusive_ptr<Pipeline> shardPipeline(needSplit ? pipeline.getValue()->splitForSharded()
: pipeline.getValue());
// Create the command for the shards. The 'fromRouter' field means produce output to be
// merged.
MutableDocument commandBuilder(request.getValue().serializeToCommandObj());
commandBuilder[AggregationRequest::kPipelineName] = Value(shardPipeline->serialize());
if (needSplit) {
commandBuilder[AggregationRequest::kFromRouterName] = Value(true);
commandBuilder[AggregationRequest::kCursorName] =
Value(DOC(AggregationRequest::kBatchSizeName << 0));
}
// These fields are not part of the AggregationRequest since they are not handled by the
//.........这里部分代码省略.........