本文整理汇总了C++中NamespaceString::ns方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceString::ns方法的具体用法?C++ NamespaceString::ns怎么用?C++ NamespaceString::ns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceString
的用法示例。
在下文中一共展示了NamespaceString::ns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseNsCollectionRequired
NamespaceString Command::parseNsCollectionRequired(const string& dbname, const BSONObj& cmdObj) {
// Accepts both BSON String and Symbol for collection name per SERVER-16260
// TODO(kangas) remove Symbol support in MongoDB 3.0 after Ruby driver audit
BSONElement first = cmdObj.firstElement();
uassert(ErrorCodes::BadValue,
str::stream() << "collection name has invalid type " << typeName(first.type()),
first.canonicalType() == canonicalizeBSONType(mongo::String));
const NamespaceString nss(dbname, first.valueStringData());
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid namespace specified '" << nss.ns() << "'",
nss.isValid());
return nss;
}
示例2: _createOrUpdateView_inlock
Status ViewCatalog::_createOrUpdateView_inlock(OperationContext* opCtx,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline,
std::unique_ptr<CollatorInterface> collator) {
_requireValidCatalog_inlock(opCtx);
// Build the BSON definition for this view to be saved in the durable view catalog. If the
// collation is empty, omit it from the definition altogether.
BSONObjBuilder viewDefBuilder;
viewDefBuilder.append("_id", viewName.ns());
viewDefBuilder.append("viewOn", viewOn.coll());
viewDefBuilder.append("pipeline", pipeline);
if (collator) {
viewDefBuilder.append("collation", collator->getSpec().toBSON());
}
BSONObj ownedPipeline = pipeline.getOwned();
auto view = std::make_shared<ViewDefinition>(
viewName.db(), viewName.coll(), viewOn.coll(), ownedPipeline, std::move(collator));
// Check that the resulting dependency graph is acyclic and within the maximum depth.
Status graphStatus = _upsertIntoGraph(opCtx, *(view.get()));
if (!graphStatus.isOK()) {
return graphStatus;
}
_durable->upsert(opCtx, viewName, viewDefBuilder.obj());
_viewMap[viewName.ns()] = view;
opCtx->recoveryUnit()->onRollback([this, viewName]() {
this->_viewMap.erase(viewName.ns());
this->_viewGraphNeedsRefresh = true;
});
// We may get invalidated, but we're exclusively locked, so the change must be ours.
opCtx->recoveryUnit()->onCommit(
[this](boost::optional<Timestamp>) { this->_valid.store(true); });
return Status::OK();
}
示例3: query
Status AuthzManagerExternalStateMongod::query(
const NamespaceString& collectionName,
const BSONObj& query,
const boost::function<void(const BSONObj&)>& resultProcessor) {
try {
DBDirectClient client;
Client::GodScope gs;
client.query(resultProcessor, collectionName.ns(), query);
return Status::OK();
} catch (const DBException& e) {
return e.toStatus();
}
}
示例4: uasserted
AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
const NamespaceString& nss,
LockMode modeDB,
LockMode modeColl,
ViewMode viewMode)
: _viewMode(viewMode),
_autoDb(opCtx, nss.db(), modeDB),
_collLock(opCtx->lockState(), nss.ns(), modeColl),
_coll(_autoDb.getDb() ? _autoDb.getDb()->getCollection(opCtx, nss) : nullptr) {
Database* db = _autoDb.getDb();
// If the database exists, but not the collection, check for views.
if (_viewMode == ViewMode::kViewsForbidden && db && !_coll &&
db->getViewCatalog()->lookup(opCtx, nss.ns()))
uasserted(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "Namespace " << nss.ns() << " is a view, not a collection");
// Wait for a configured amount of time after acquiring locks if the failpoint is enabled.
MONGO_FAIL_POINT_BLOCK(setAutoGetCollectionWait, customWait) {
const BSONObj& data = customWait.getData();
sleepFor(Milliseconds(data["waitForMillis"].numberInt()));
}
}
示例5: storeCollectionRanges
/**
* Stores ranges for a particular collection and shard starting from some version
*/
void storeCollectionRanges( const NamespaceString& nss,
const string& shardName,
const vector<KeyRange>& ranges,
const ChunkVersion& startVersion ) {
// Get key pattern from first range
ASSERT_GREATER_THAN( ranges.size(), 0u );
CollectionType coll;
coll.setNS( nss.ns() );
coll.setKeyPattern( ranges.begin()->keyPattern );
coll.setEpoch( startVersion.epoch() );
coll.setUpdatedAt( 1ULL );
string errMsg;
ASSERT( coll.isValid( &errMsg ) );
DBDirectClient client(&_txn);
client.update( CollectionType::ConfigNS,
BSON( CollectionType::ns( coll.getNS() ) ),
coll.toBSON(), true, false );
ChunkVersion nextVersion = startVersion;
for ( vector<KeyRange>::const_iterator it = ranges.begin(); it != ranges.end(); ++it ) {
ChunkType chunk;
// TODO: We should not rely on the serialized ns, minkey being unique in the future,
// causes problems since it links string serialization to correctness.
chunk.setName( Chunk::genID( nss, it->minKey ) );
chunk.setShard( shardName );
chunk.setNS( nss.ns() );
chunk.setVersion( nextVersion );
chunk.setMin( it->minKey );
chunk.setMax( it->maxKey );
nextVersion.incMajor();
client.insert( ChunkType::ConfigNS, chunk.toBSON() );
}
}
示例6: _markStaleNS
void ParallelSortClusteredCursor::_markStaleNS(OperationContext* txn,
const NamespaceString& staleNS,
const StaleConfigException& e,
bool& forceReload) {
if (e.requiresFullReload()) {
Grid::get(txn)->catalogCache()->invalidate(staleNS.db());
}
if (_staleNSMap.find(staleNS.ns()) == _staleNSMap.end())
_staleNSMap[staleNS.ns()] = 1;
int tries = ++_staleNSMap[staleNS.ns()];
if (tries >= 5) {
throw SendStaleConfigException(staleNS.ns(),
str::stream() << "too many retries of stale version info",
e.getVersionReceived(),
e.getVersionWanted());
}
forceReload = tries > 2;
}
示例7: makeUpdateDocumentOplogEntry
/**
* Creates an update oplog entry with given optime and namespace.
*/
OplogEntry makeUpdateDocumentOplogEntry(OpTime opTime,
const NamespaceString& nss,
const BSONObj& documentToUpdate,
const BSONObj& updatedDocument) {
BSONObjBuilder bob;
bob.appendElements(opTime.toBSON());
bob.append("h", 1LL);
bob.append("op", "u");
bob.append("ns", nss.ns());
bob.append("o2", documentToUpdate);
bob.append("o", updatedDocument);
return OplogEntry(bob.obj());
}
示例8: nss
TEST_F(MergeChunkTests, CompoundMerge) {
const NamespaceString nss("foo.bar");
const BSONObj kp = BSON("x" << 1 << "y" << 1);
const OID epoch = OID::gen();
vector<KeyRange> ranges;
// Setup chunk metadata
ranges.push_back(
KeyRange(nss.ns(), BSON("x" << 0 << "y" << 1), BSON("x" << 1 << "y" << 0), kp));
ranges.push_back(
KeyRange(nss.ns(), BSON("x" << 1 << "y" << 0), BSON("x" << 2 << "y" << 1), kp));
storeCollectionRanges(nss, shardName(), ranges, ChunkVersion(1, 0, epoch));
// Get latest version
ChunkVersion latestVersion;
shardingState.refreshMetadataNow(&_txn, nss.ns(), &latestVersion);
shardingState.resetMetadata(nss.ns());
// Do merge
string errMsg;
bool result = mergeChunks(
&_txn, nss, BSON("x" << 0 << "y" << 1), BSON("x" << 2 << "y" << 1), epoch, &errMsg);
ASSERT_EQUALS(errMsg, "");
ASSERT(result);
// Verify result
CollectionMetadataPtr metadata = shardingState.getCollectionMetadata(nss.ns());
ChunkType chunk;
ASSERT(metadata->getNextChunk(BSON("x" << 0 << "y" << 1), &chunk));
ASSERT(chunk.getMin().woCompare(BSON("x" << 0 << "y" << 1)) == 0);
ASSERT(chunk.getMax().woCompare(BSON("x" << 2 << "y" << 1)) == 0);
ASSERT_EQUALS(metadata->getNumChunks(), 1u);
ASSERT_EQUALS(metadata->getShardVersion().majorVersion(), latestVersion.majorVersion());
ASSERT_GREATER_THAN(metadata->getShardVersion().minorVersion(), latestVersion.minorVersion());
assertWrittenAsMerged(ranges);
}
示例9: beginQueryOp
void beginQueryOp(OperationContext* txn,
const NamespaceString& nss,
const BSONObj& queryObj,
long long ntoreturn,
long long ntoskip) {
auto curop = CurOp::get(txn);
curop->debug().query = queryObj;
curop->debug().ntoreturn = ntoreturn;
curop->debug().ntoskip = ntoskip;
stdx::lock_guard<Client> lk(*txn->getClient());
curop->setQuery_inlock(queryObj);
curop->setNS_inlock(nss.ns());
}
示例10: run
void run() {
const ServiceContext::UniqueOperationContext opCtxPtr = cc().makeOperationContext();
OperationContext& opCtx = *opCtxPtr;
dbtests::WriteContextForTests ctx(&opCtx, _nss.ns());
const std::string indexName = "x_1";
ASSERT_OK(dbtests::createIndexFromSpec(
&opCtx,
_nss.ns(),
BSON("name" << indexName << "ns" << _nss.ns() << "key" << BSON("x" << 1) << "v"
<< static_cast<int>(kIndexVersion)
<< "expireAfterSeconds"
<< 5)));
const IndexDescriptor* desc = _catalog->findIndexByName(&opCtx, indexName);
ASSERT(desc);
ASSERT_EQUALS(5, desc->infoObj()["expireAfterSeconds"].numberLong());
// Change value of "expireAfterSeconds" on disk.
{
WriteUnitOfWork wuow(&opCtx);
_coll->getCatalogEntry()->updateTTLSetting(&opCtx, "x_1", 10);
wuow.commit();
}
// Verify that the catalog does not yet know of the change.
desc = _catalog->findIndexByName(&opCtx, indexName);
ASSERT_EQUALS(5, desc->infoObj()["expireAfterSeconds"].numberLong());
{
// Notify the catalog of the change.
WriteUnitOfWork wuow(&opCtx);
desc = _catalog->refreshEntry(&opCtx, desc);
wuow.commit();
}
// Test that the catalog reflects the change.
ASSERT_EQUALS(10, desc->infoObj()["expireAfterSeconds"].numberLong());
}
示例11: checkAuthForFind
Status AuthorizationSession::checkAuthForFind(const NamespaceString& ns, bool hasTerm) {
if (MONGO_unlikely(ns.isCommand())) {
return Status(ErrorCodes::InternalError,
str::stream() << "Checking query auth on command namespace " << ns.ns());
}
if (!isAuthorizedForActionsOnNamespace(ns, ActionType::find)) {
return Status(ErrorCodes::Unauthorized,
str::stream() << "not authorized for query on " << ns.ns());
}
// Only internal clients (such as other nodes in a replica set) are allowed to use
// the 'term' field in a find operation. Use of this field could trigger changes
// in the receiving server's replication state and should be protected.
if (hasTerm &&
!isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
ActionType::internal)) {
return Status(ErrorCodes::Unauthorized,
str::stream() << "not authorized for query with term on " << ns.ns());
}
return Status::OK();
}
示例12: run
void run() {
OldClientWriteContext ctx(&_txn, nss.ns());
addIndex(BSON("a" << 1));
addIndex(BSON("a" << 1 << "b" << 1));
addIndex(BSON("c" << 1));
for (int i = 0; i < 10; i++) {
insert(BSON("a" << 1 << "b" << i << "c" << i));
}
// This query should result in a plan cache entry for the first $or branch, because
// there are two competing indices. The second branch has only one relevant index, so
// its winning plan should not be cached.
BSONObj query = fromjson("{$or: [{a: 1, b: 3}, {c: 1}]}");
Collection* collection = ctx.getCollection();
auto qr = stdx::make_unique<QueryRequest>(nss);
qr->setFilter(query);
auto statusWithCQ = CanonicalQuery::canonicalize(
txn(), std::move(qr), ExtensionsCallbackDisallowExtensions());
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
// Get planner params.
QueryPlannerParams plannerParams;
fillOutPlannerParams(&_txn, collection, cq.get(), &plannerParams);
WorkingSet ws;
std::unique_ptr<SubplanStage> subplan(
new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get()));
PlanYieldPolicy yieldPolicy(PlanExecutor::YIELD_MANUAL, _clock);
ASSERT_OK(subplan->pickBestPlan(&yieldPolicy));
// Nothing is in the cache yet, so neither branch should have been planned from
// the plan cache.
ASSERT_FALSE(subplan->branchPlannedFromCache(0));
ASSERT_FALSE(subplan->branchPlannedFromCache(1));
// If we repeat the same query, the plan for the first branch should have come from
// the cache.
ws.clear();
subplan.reset(new SubplanStage(&_txn, collection, &ws, plannerParams, cq.get()));
ASSERT_OK(subplan->pickBestPlan(&yieldPolicy));
ASSERT_TRUE(subplan->branchPlannedFromCache(0));
ASSERT_FALSE(subplan->branchPlannedFromCache(1));
}
示例13: aboutToDelete
OpObserver::DeleteState OpObserver::aboutToDelete(OperationContext* txn,
const NamespaceString& ns,
const BSONObj& doc) {
OpObserver::DeleteState deleteState;
BSONElement idElement = doc["_id"];
if (!idElement.eoo()) {
deleteState.idDoc = idElement.wrap();
}
auto css = CollectionShardingState::get(txn, ns.ns());
deleteState.isMigrating = css->isDocumentInMigratingChunk(txn, doc);
return deleteState;
}
示例14: checkAuthForUpdate
Status AuthorizationSession::checkAuthForUpdate(const NamespaceString& ns,
const BSONObj& query,
const BSONObj& update,
bool upsert) {
if (!upsert) {
if (!isAuthorizedForActionsOnNamespace(ns, ActionType::update)) {
return Status(ErrorCodes::Unauthorized,
mongoutils::str::stream() << "not authorized for update on " <<
ns.ns());
}
}
else {
ActionSet required;
required.addAction(ActionType::update);
required.addAction(ActionType::insert);
if (!isAuthorizedForActionsOnNamespace(ns, required)) {
return Status(ErrorCodes::Unauthorized,
mongoutils::str::stream() << "not authorized for upsert on " <<
ns.ns());
}
}
return Status::OK();
}
示例15: addPrivilegesRequiredForRenameCollection
void addPrivilegesRequiredForRenameCollection(const BSONObj& cmdObj,
std::vector<Privilege>* out) {
NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection"));
NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to"));
uassert(17140, "Invalid source namespace " + sourceNS.ns(), sourceNS.isValid());
uassert(17141, "Invalid target namespace " + targetNS.ns(), targetNS.isValid());
ActionSet sourceActions;
ActionSet targetActions;
if (sourceNS.db() == targetNS.db()) {
sourceActions.addAction(ActionType::renameCollectionSameDB);
targetActions.addAction(ActionType::renameCollectionSameDB);
} else {
sourceActions.addAction(ActionType::cloneCollectionLocalSource);
sourceActions.addAction(ActionType::dropCollection);
targetActions.addAction(ActionType::createCollection);
targetActions.addAction(ActionType::cloneCollectionTarget);
targetActions.addAction(ActionType::createIndex);
}
out->push_back(Privilege(ResourcePattern::forExactNamespace(sourceNS), sourceActions));
out->push_back(Privilege(ResourcePattern::forExactNamespace(targetNS), targetActions));
}