本文整理汇总了C++中NamespaceString::isSystem方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceString::isSystem方法的具体用法?C++ NamespaceString::isSystem怎么用?C++ NamespaceString::isSystem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceString
的用法示例。
在下文中一共展示了NamespaceString::isSystem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkAuthForRenameCollectionCommand
Status checkAuthForRenameCollectionCommand(ClientBasic* client,
const std::string& dbname,
const BSONObj& cmdObj) {
NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection"));
NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to"));
bool dropTarget = cmdObj["dropTarget"].trueValue();
if (sourceNS.db() == targetNS.db() && !sourceNS.isSystem() && !targetNS.isSystem()) {
// If renaming within the same database, then if you have renameCollectionSameDB and
// either can read both of source and dest collections or *can't* read either of source
// or dest collection, then you get can do the rename, even without insert on the
// destination collection.
bool canRename = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forDatabaseName(sourceNS.db()),
ActionType::renameCollectionSameDB);
bool canDropTargetIfNeeded = true;
if (dropTarget) {
canDropTargetIfNeeded =
AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS),
ActionType::dropCollection);
}
bool canReadSrc = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(sourceNS), ActionType::find);
bool canReadDest = AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS), ActionType::find);
if (canRename && canDropTargetIfNeeded && (canReadSrc || !canReadDest)) {
return Status::OK();
}
}
// Check privileges on source collection
ActionSet actions;
actions.addAction(ActionType::find);
actions.addAction(ActionType::dropCollection);
if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(sourceNS), actions)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
// Check privileges on dest collection
actions.removeAllActions();
actions.addAction(ActionType::insert);
actions.addAction(ActionType::createIndex);
if (dropTarget) {
actions.addAction(ActionType::dropCollection);
}
if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS), actions)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
return Status::OK();
}
示例2: createView
Status ViewCatalog::createView(OperationContext* opCtx,
const NamespaceString& viewName,
const NamespaceString& viewOn,
const BSONArray& pipeline,
const BSONObj& collation) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
if (viewName.db() != viewOn.db())
return Status(ErrorCodes::BadValue,
"View must be created on a view or collection in the same database");
if (_lookup(lk, opCtx, StringData(viewName.ns())))
return Status(ErrorCodes::NamespaceExists, "Namespace already exists");
if (!NamespaceString::validCollectionName(viewOn.coll()))
return Status(ErrorCodes::InvalidNamespace,
str::stream() << "invalid name for 'viewOn': " << viewOn.coll());
if (viewName.isSystem())
return Status(
ErrorCodes::InvalidNamespace,
"View name cannot start with 'system.', which is reserved for system namespaces");
auto collator = parseCollator(opCtx, collation);
if (!collator.isOK())
return collator.getStatus();
return _createOrUpdateView(
lk, opCtx, viewName, viewOn, pipeline, std::move(collator.getValue()));
}
示例3: checkAuthForRenameCollectionCommand
Status checkAuthForRenameCollectionCommand(ClientBasic* client,
const std::string& dbname,
const BSONObj& cmdObj) {
NamespaceString sourceNS = NamespaceString(cmdObj.getStringField("renameCollection"));
NamespaceString targetNS = NamespaceString(cmdObj.getStringField("to"));
bool dropTarget = cmdObj["dropTarget"].trueValue();
if (sourceNS.db() == targetNS.db() && !sourceNS.isSystem() && !targetNS.isSystem()) {
bool authed1 = client->getAuthorizationSession()->isAuthorizedForActionsOnResource(
ResourcePattern::forDatabaseName(sourceNS.db()),
ActionType::renameCollectionSameDB);
bool authed2 = true;
if (dropTarget) {
authed2 = client->getAuthorizationSession()->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS), ActionType::dropCollection);
}
if (authed1 && authed2) {
return Status::OK();
}
}
// Check privileges on source collection
ActionSet actions;
actions.addAction(ActionType::find);
actions.addAction(ActionType::dropCollection);
if (!client->getAuthorizationSession()->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(sourceNS), actions)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
// Check privileges on dest collection
actions.removeAllActions();
actions.addAction(ActionType::insert);
actions.addAction(ActionType::createIndex);
if (dropTarget) {
actions.addAction(ActionType::dropCollection);
}
if (!client->getAuthorizationSession()->isAuthorizedForActionsOnResource(
ResourcePattern::forExactNamespace(targetNS), actions)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized");
}
return Status::OK();
}
示例4: errmsgRun
virtual bool errmsgRun(OperationContext* opCtx,
const string& db,
const BSONObj& cmdObj,
string& errmsg,
BSONObjBuilder& result) {
NamespaceString nss = CommandHelpers::parseNsCollectionRequired(db, cmdObj);
repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx);
if (replCoord->getMemberState().primary() && !cmdObj["force"].trueValue()) {
errmsg =
"will not run compact on an active replica set primary as this is a slow blocking "
"operation. use force:true to force";
return false;
}
if (!nss.isNormal()) {
errmsg = "bad namespace name";
return false;
}
if (nss.isSystem()) {
// Items in system.* cannot be moved as there might be pointers to them.
errmsg = "can't compact a system namespace";
return false;
}
CompactOptions compactOptions;
if (cmdObj.hasElement("validate"))
compactOptions.validateDocuments = cmdObj["validate"].trueValue();
AutoGetDb autoDb(opCtx, db, MODE_X);
Database* const collDB = autoDb.getDb();
Collection* collection = collDB ? collDB->getCollection(opCtx, nss) : nullptr;
auto view =
collDB && !collection ? ViewCatalog::get(collDB)->lookup(opCtx, nss.ns()) : nullptr;
// If db/collection does not exist, short circuit and return.
if (!collDB || !collection) {
if (view)
uasserted(ErrorCodes::CommandNotSupportedOnView, "can't compact a view");
else
uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist");
}
OldClientContext ctx(opCtx, nss.ns());
BackgroundOperation::assertNoBgOpInProgForNs(nss.ns());
log() << "compact " << nss.ns() << " begin, options: " << compactOptions;
StatusWith<CompactStats> status = compactCollection(opCtx, collection, &compactOptions);
uassertStatusOK(status.getStatus());
log() << "compact " << nss.ns() << " end";
return true;
}
示例5: emptyCapped
mongo::Status mongo::emptyCapped(OperationContext* opCtx, const NamespaceString& collectionName) {
AutoGetDb autoDb(opCtx, collectionName.db(), MODE_X);
bool userInitiatedWritesAndNotPrimary = opCtx->writesAreReplicated() &&
!repl::ReplicationCoordinator::get(opCtx)->canAcceptWritesFor(opCtx, collectionName);
if (userInitiatedWritesAndNotPrimary) {
return Status(ErrorCodes::NotMaster,
str::stream() << "Not primary while truncating collection: "
<< collectionName.ns());
}
Database* db = autoDb.getDb();
uassert(ErrorCodes::NamespaceNotFound, "no such database", db);
Collection* collection = db->getCollection(opCtx, collectionName);
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "emptycapped not supported on view: " << collectionName.ns(),
collection || !db->getViewCatalog()->lookup(opCtx, collectionName.ns()));
uassert(ErrorCodes::NamespaceNotFound, "no such collection", collection);
if (collectionName.isSystem() && !collectionName.isSystemDotProfile()) {
return Status(ErrorCodes::IllegalOperation,
str::stream() << "Cannot truncate a system collection: "
<< collectionName.ns());
}
if (collectionName.isVirtualized()) {
return Status(ErrorCodes::IllegalOperation,
str::stream() << "Cannot truncate a virtual collection: "
<< collectionName.ns());
}
if ((repl::ReplicationCoordinator::get(opCtx)->getReplicationMode() !=
repl::ReplicationCoordinator::modeNone) &&
collectionName.isOplog()) {
return Status(ErrorCodes::OplogOperationUnsupported,
str::stream() << "Cannot truncate a live oplog while replicating: "
<< collectionName.ns());
}
BackgroundOperation::assertNoBgOpInProgForNs(collectionName.ns());
WriteUnitOfWork wuow(opCtx);
Status status = collection->truncate(opCtx);
if (!status.isOK()) {
return status;
}
getGlobalServiceContext()->getOpObserver()->onEmptyCapped(
opCtx, collection->ns(), collection->uuid());
wuow.commit();
return Status::OK();
}
示例6: errmsgRun
virtual bool errmsgRun(OperationContext* opCtx,
const string& db,
const BSONObj& cmdObj,
string& errmsg,
BSONObjBuilder& result) {
NamespaceString nss = CommandHelpers::parseNsCollectionRequired(db, cmdObj);
repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx);
if (replCoord->getMemberState().primary() && !cmdObj["force"].trueValue()) {
errmsg =
"will not run compact on an active replica set primary as this is a slow blocking "
"operation. use force:true to force";
return false;
}
if (!nss.isNormal()) {
errmsg = "bad namespace name";
return false;
}
if (nss.isSystem()) {
// items in system.* cannot be moved as there might be pointers to them
// i.e. system.indexes entries are pointed to from NamespaceDetails
errmsg = "can't compact a system namespace";
return false;
}
CompactOptions compactOptions;
if (cmdObj["preservePadding"].trueValue()) {
compactOptions.paddingMode = CompactOptions::PRESERVE;
if (cmdObj.hasElement("paddingFactor") || cmdObj.hasElement("paddingBytes")) {
errmsg = "cannot mix preservePadding and paddingFactor|paddingBytes";
return false;
}
} else if (cmdObj.hasElement("paddingFactor") || cmdObj.hasElement("paddingBytes")) {
compactOptions.paddingMode = CompactOptions::MANUAL;
if (cmdObj.hasElement("paddingFactor")) {
compactOptions.paddingFactor = cmdObj["paddingFactor"].Number();
if (compactOptions.paddingFactor < 1 || compactOptions.paddingFactor > 4) {
errmsg = "invalid padding factor";
return false;
}
}
if (cmdObj.hasElement("paddingBytes")) {
compactOptions.paddingBytes = cmdObj["paddingBytes"].numberInt();
if (compactOptions.paddingBytes < 0 ||
compactOptions.paddingBytes > (1024 * 1024)) {
errmsg = "invalid padding bytes";
return false;
}
}
}
if (cmdObj.hasElement("validate"))
compactOptions.validateDocuments = cmdObj["validate"].trueValue();
AutoGetDb autoDb(opCtx, db, MODE_X);
Database* const collDB = autoDb.getDb();
Collection* collection = collDB ? collDB->getCollection(opCtx, nss) : nullptr;
auto view =
collDB && !collection ? collDB->getViewCatalog()->lookup(opCtx, nss.ns()) : nullptr;
// If db/collection does not exist, short circuit and return.
if (!collDB || !collection) {
if (view)
uasserted(ErrorCodes::CommandNotSupportedOnView, "can't compact a view");
else
uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist");
}
OldClientContext ctx(opCtx, nss.ns());
BackgroundOperation::assertNoBgOpInProgForNs(nss.ns());
log() << "compact " << nss.ns() << " begin, options: " << compactOptions;
StatusWith<CompactStats> status = collection->compact(opCtx, &compactOptions);
uassertStatusOK(status.getStatus());
if (status.getValue().corruptDocuments > 0)
result.append("invalidObjects", status.getValue().corruptDocuments);
log() << "compact " << nss.ns() << " end";
return true;
}