本文整理汇总了C++中NamespaceString::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceString::isValid方法的具体用法?C++ NamespaceString::isValid怎么用?C++ NamespaceString::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceString
的用法示例。
在下文中一共展示了NamespaceString::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseNs
NamespaceString AggregationRequest::parseNs(const std::string& dbname, const BSONObj& cmdObj) {
auto firstElement = cmdObj.firstElement();
if (firstElement.isNumber()) {
uassert(ErrorCodes::FailedToParse,
str::stream() << "Invalid command format: the '"
<< firstElement.fieldNameStringData()
<< "' field must specify a collection name or 1",
firstElement.number() == 1);
return NamespaceString::makeCollectionlessAggregateNSS(dbname);
} else {
uassert(ErrorCodes::TypeMismatch,
str::stream() << "collection name has invalid type: "
<< typeName(firstElement.type()),
firstElement.type() == BSONType::String);
const NamespaceString nss(dbname, firstElement.valueStringData());
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid namespace specified '" << nss.ns() << "'",
nss.isValid() && !nss.isCollectionlessAggregateNS());
return nss;
}
}
示例2: appendAsCommand
void MoveChunkRequest::appendAsCommand(BSONObjBuilder* builder,
const NamespaceString& nss,
ChunkVersion chunkVersion,
const ConnectionString& configServerConnectionString,
const ShardId& fromShardId,
const ShardId& toShardId,
const ChunkRange& range,
int64_t maxChunkSizeBytes,
const MigrationSecondaryThrottleOptions& secondaryThrottle,
bool waitForDelete) {
invariant(builder->asTempObj().isEmpty());
invariant(nss.isValid());
builder->append(kMoveChunk, nss.ns());
chunkVersion.appendToCommand(builder); // 3.4 shard compatibility
builder->append(kEpoch, chunkVersion.epoch());
// config connection string is included for 3.4 shard compatibility
builder->append(kConfigServerConnectionString, configServerConnectionString.toString());
builder->append(kFromShardId, fromShardId.toString());
builder->append(kToShardId, toShardId.toString());
range.append(builder);
builder->append(kMaxChunkSizeBytes, static_cast<long long>(maxChunkSizeBytes));
secondaryThrottle.append(builder);
builder->append(kWaitForDelete, waitForDelete);
builder->append(kTakeDistLock, false);
}
示例3: appendAsCommand
void StartChunkCloneRequest::appendAsCommand(
BSONObjBuilder* builder,
const NamespaceString& nss,
const MigrationSessionId& sessionId,
const ConnectionString& configServerConnectionString,
const ConnectionString& fromShardConnectionString,
const ShardId& fromShardId,
const ShardId& toShardId,
const BSONObj& chunkMinKey,
const BSONObj& chunkMaxKey,
const BSONObj& shardKeyPattern,
const MigrationSecondaryThrottleOptions& secondaryThrottle) {
invariant(builder->asTempObj().isEmpty());
invariant(nss.isValid());
invariant(fromShardConnectionString.isValid());
builder->append(kRecvChunkStart, nss.ns());
sessionId.append(builder);
builder->append(kConfigServerConnectionString, configServerConnectionString.toString());
builder->append(kFromShardConnectionString, fromShardConnectionString.toString());
builder->append(kFromShardId, fromShardId.toString());
builder->append(kToShardId, toShardId.toString());
builder->append(kChunkMinKey, chunkMinKey);
builder->append(kChunkMaxKey, chunkMaxKey);
builder->append(kShardKeyPattern, shardKeyPattern);
secondaryThrottle.append(builder);
}
示例4: appendAsCommand
void MoveChunkRequest::appendAsCommand(BSONObjBuilder* builder,
const NamespaceString& nss,
const ChunkVersion& shardVersion,
const ConnectionString& configServerConnectionString,
const ShardId& fromShardId,
const ShardId& toShardId,
const ChunkRange& range,
int64_t maxChunkSizeBytes,
const MigrationSecondaryThrottleOptions& secondaryThrottle,
bool waitForDelete,
bool takeDistLock) {
invariant(builder->asTempObj().isEmpty());
invariant(nss.isValid());
builder->append(kMoveChunk, nss.ns());
shardVersion.appendForCommands(builder);
builder->append(kConfigServerConnectionString, configServerConnectionString.toString());
builder->append(kFromShardId, fromShardId.toString());
builder->append(kToShardId, toShardId.toString());
range.append(builder);
builder->append(kMaxChunkSizeBytes, static_cast<long long>(maxChunkSizeBytes));
secondaryThrottle.append(builder);
builder->append(kWaitForDelete, waitForDelete);
builder->append(kTakeDistLock, takeDistLock);
}
示例5: uassert
std::unique_ptr<DocumentSourceOut::LiteParsed> DocumentSourceOut::LiteParsed::parse(
const AggregationRequest& request, const BSONElement& spec) {
uassert(ErrorCodes::TypeMismatch,
str::stream() << "$out stage requires a string or object argument, but found "
<< typeName(spec.type()),
spec.type() == BSONType::String || spec.type() == BSONType::Object);
NamespaceString targetNss;
bool allowSharded;
WriteModeEnum mode;
if (spec.type() == BSONType::String) {
targetNss = NamespaceString(request.getNamespaceString().db(), spec.valueStringData());
allowSharded = false;
mode = WriteModeEnum::kModeReplaceCollection;
} else if (spec.type() == BSONType::Object) {
auto outSpec =
DocumentSourceOutSpec::parse(IDLParserErrorContext("$out"), spec.embeddedObject());
if (auto targetDb = outSpec.getTargetDb()) {
targetNss = NamespaceString(*targetDb, outSpec.getTargetCollection());
} else {
targetNss =
NamespaceString(request.getNamespaceString().db(), outSpec.getTargetCollection());
}
mode = outSpec.getMode();
// Sharded output collections are not allowed with mode "replaceCollection".
allowSharded = mode != WriteModeEnum::kModeReplaceCollection;
}
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid $out target namespace, " << targetNss.ns(),
targetNss.isValid());
// All modes require the "insert" action.
ActionSet actions{ActionType::insert};
switch (mode) {
case WriteModeEnum::kModeReplaceCollection:
actions.addAction(ActionType::remove);
break;
case WriteModeEnum::kModeReplaceDocuments:
actions.addAction(ActionType::update);
break;
case WriteModeEnum::kModeInsertDocuments:
// "insertDocuments" mode only requires the "insert" action.
break;
}
if (request.shouldBypassDocumentValidation()) {
actions.addAction(ActionType::bypassDocumentValidation);
}
PrivilegeVector privileges{Privilege(ResourcePattern::forExactNamespace(targetNss), actions)};
return stdx::make_unique<DocumentSourceOut::LiteParsed>(
std::move(targetNss), std::move(privileges), allowSharded);
}
示例6: run
virtual bool run(OperationContext* opCtx,
const string& dbname,
const BSONObj& cmdObj,
BSONObjBuilder& result) {
const NamespaceString fullNs = CommandHelpers::parseNsCollectionRequired(dbname, cmdObj);
if (!fullNs.isValid()) {
return CommandHelpers::appendCommandStatus(
result,
{ErrorCodes::InvalidNamespace,
str::stream() << "collection name " << fullNs.ns() << " is not valid"});
}
int n = cmdObj.getIntField("n");
bool inc = cmdObj.getBoolField("inc"); // inclusive range?
if (n <= 0) {
return CommandHelpers::appendCommandStatus(
result, {ErrorCodes::BadValue, "n must be a positive integer"});
}
// Lock the database in mode IX and lock the collection exclusively.
AutoGetCollection autoColl(opCtx, fullNs, MODE_IX, MODE_X);
Collection* collection = autoColl.getCollection();
if (!collection) {
return CommandHelpers::appendCommandStatus(
result,
{ErrorCodes::NamespaceNotFound,
str::stream() << "collection " << fullNs.ns() << " does not exist"});
}
if (!collection->isCapped()) {
return CommandHelpers::appendCommandStatus(
result, {ErrorCodes::IllegalOperation, "collection must be capped"});
}
RecordId end;
{
// Scan backwards through the collection to find the document to start truncating from.
// We will remove 'n' documents, so start truncating from the (n + 1)th document to the
// end.
auto exec = InternalPlanner::collectionScan(
opCtx, fullNs.ns(), collection, PlanExecutor::NO_YIELD, InternalPlanner::BACKWARD);
for (int i = 0; i < n + 1; ++i) {
PlanExecutor::ExecState state = exec->getNext(nullptr, &end);
if (PlanExecutor::ADVANCED != state) {
return CommandHelpers::appendCommandStatus(
result,
{ErrorCodes::IllegalOperation,
str::stream() << "invalid n, collection contains fewer than " << n
<< " documents"});
}
}
}
collection->cappedTruncateAfter(opCtx, end, inc);
return true;
}
示例7: parseNsFullyQualified
string Command::parseNsFullyQualified(const string& dbname, const BSONObj& cmdObj) {
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(first.valueStringData());
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid namespace specified '" << nss.ns() << "'",
nss.isValid());
return nss.ns();
}
示例8: makeForVersioning
SetShardVersionRequest SetShardVersionRequest::makeForVersioning(
const ConnectionString& configServer,
const ShardId& shardName,
const ConnectionString& shardConnectionString,
const NamespaceString& nss,
const ChunkVersion& nssVersion,
bool isAuthoritative) {
invariant(nss.isValid());
return SetShardVersionRequest(
configServer, shardName, shardConnectionString, nss, nssVersion, isAuthoritative);
}
示例9: 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;
}
示例10: 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));
}
示例11: BSON
CollectionCloner::CollectionCloner(ReplicationExecutor* executor,
const HostAndPort& source,
const NamespaceString& sourceNss,
const CollectionOptions& options,
const CallbackFn& work,
StorageInterface* storageInterface)
: _executor(executor),
_source(source),
_sourceNss(sourceNss),
_destNss(_sourceNss),
_options(options),
_work(work),
_storageInterface(storageInterface),
_active(false),
_listIndexesFetcher(_executor,
_source,
_sourceNss.db().toString(),
BSON("listIndexes" << _sourceNss.coll()),
stdx::bind(&CollectionCloner::_listIndexesCallback,
this,
stdx::placeholders::_1,
stdx::placeholders::_2,
stdx::placeholders::_3)),
_findFetcher(_executor,
_source,
_sourceNss.db().toString(),
BSON("find" << _sourceNss.coll() <<
"noCursorTimeout" << true), // SERVER-1387
stdx::bind(&CollectionCloner::_findCallback,
this,
stdx::placeholders::_1,
stdx::placeholders::_2,
stdx::placeholders::_3)),
_indexSpecs(),
_documents(),
_dbWorkCallbackHandle(),
// TODO: replace with executor database worker when it is available.
_scheduleDbWorkFn(stdx::bind(&ReplicationExecutor::scheduleWorkWithGlobalExclusiveLock,
_executor,
stdx::placeholders::_1)) {
uassert(ErrorCodes::BadValue, "null replication executor", executor);
uassert(ErrorCodes::BadValue, "invalid collection namespace: " + sourceNss.ns(),
sourceNss.isValid());
uassertStatusOK(options.validate());
uassert(ErrorCodes::BadValue, "callback function cannot be null", work);
uassert(ErrorCodes::BadValue, "null storage interface", storageInterface);
}
示例12: appendAsCommand
void CommitChunkMigrationRequest::appendAsCommand(
BSONObjBuilder* builder,
const NamespaceString& nss,
const ShardId& fromShard,
const ShardId& toShard,
const ChunkType& migratedChunkType,
const boost::optional<ChunkType>& controlChunkType) {
invariant(builder->asTempObj().isEmpty());
invariant(nss.isValid());
builder->append(kConfigSvrCommitChunkMigration, nss.ns());
builder->append(kFromShard, fromShard.toString());
builder->append(kToShard, toShard.toString());
builder->append(kMigratedChunk, migratedChunkType.toBSON());
if (controlChunkType) {
builder->append(kControlChunk, controlChunkType->toBSON());
}
}
示例13: addRequiredPrivileges
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
std::vector<Privilege>* out) {
ActionSet sourceActions;
sourceActions.addAction(ActionType::find);
out->push_back(Privilege(parseResourcePattern(dbname, cmdObj), sourceActions));
ActionSet targetActions;
targetActions.addAction(ActionType::insert);
targetActions.addAction(ActionType::createIndex);
targetActions.addAction(ActionType::convertToCapped);
const auto nssElt = cmdObj["toCollection"];
uassert(ErrorCodes::TypeMismatch,
"'toCollection' must be of type String",
nssElt.type() == BSONType::String);
const NamespaceString nss(dbname, nssElt.valueStringData());
uassert(ErrorCodes::InvalidNamespace,
str::stream() << "Invalid target namespace: " << nss.ns(),
nss.isValid());
out->push_back(Privilege(ResourcePattern::forExactNamespace(nss), targetActions));
}
示例14: validateBatch
// static
Status WriteBatchExecutor::validateBatch( const BatchedCommandRequest& request ) {
// Validate namespace
const NamespaceString nss = NamespaceString( request.getNS() );
if ( !nss.isValid() ) {
return Status( ErrorCodes::InvalidNamespace,
nss.ns() + " is not a valid namespace" );
}
// Make sure we can write to the namespace
Status allowedStatus = userAllowedWriteNS( nss );
if ( !allowedStatus.isOK() ) {
return allowedStatus;
}
// Validate insert index requests
// TODO: Push insert index requests through createIndex once all upgrade paths support it
string errMsg;
if ( request.isInsertIndexRequest() && !request.isValidIndexRequest( &errMsg ) ) {
return Status( ErrorCodes::InvalidOptions, errMsg );
}
return Status::OK();
}
示例15: runQuery
std::string runQuery(OperationContext* txn,
QueryMessage& q,
const NamespaceString& nss,
CurOp& curop,
Message &result) {
// Validate the namespace.
uassert(16256, str::stream() << "Invalid ns [" << nss.ns() << "]", nss.isValid());
invariant(!nss.isCommand());
// Set curop information.
beginQueryOp(nss, q.query, q.ntoreturn, q.ntoskip, &curop);
// Parse the qm into a CanonicalQuery.
std::auto_ptr<CanonicalQuery> cq;
{
CanonicalQuery* cqRaw;
Status canonStatus = CanonicalQuery::canonicalize(q,
&cqRaw,
WhereCallbackReal(txn, nss.db()));
if (!canonStatus.isOK()) {
uasserted(17287, str::stream() << "Can't canonicalize query: "
<< canonStatus.toString());
}
cq.reset(cqRaw);
}
invariant(cq.get());
LOG(5) << "Running query:\n" << cq->toString();
LOG(2) << "Running query: " << cq->toStringShort();
// Parse, canonicalize, plan, transcribe, and get a plan executor.
AutoGetCollectionForRead ctx(txn, nss);
Collection* collection = ctx.getCollection();
const int dbProfilingLevel = ctx.getDb() ? ctx.getDb()->getProfilingLevel() :
serverGlobalParams.defaultProfile;
// We have a parsed query. Time to get the execution plan for it.
std::unique_ptr<PlanExecutor> exec;
{
PlanExecutor* rawExec;
Status execStatus = getExecutorFind(txn,
collection,
nss,
cq.release(),
PlanExecutor::YIELD_AUTO,
&rawExec);
uassertStatusOK(execStatus);
exec.reset(rawExec);
}
const LiteParsedQuery& pq = exec->getCanonicalQuery()->getParsed();
// If it's actually an explain, do the explain and return rather than falling through
// to the normal query execution loop.
if (pq.isExplain()) {
BufBuilder bb;
bb.skip(sizeof(QueryResult::Value));
BSONObjBuilder explainBob;
Explain::explainStages(exec.get(), ExplainCommon::EXEC_ALL_PLANS, &explainBob);
// Add the resulting object to the return buffer.
BSONObj explainObj = explainBob.obj();
bb.appendBuf((void*)explainObj.objdata(), explainObj.objsize());
// TODO: Does this get overwritten/do we really need to set this twice?
curop.debug().query = q.query;
// Set query result fields.
QueryResult::View qr = bb.buf();
bb.decouple();
qr.setResultFlagsToOk();
qr.msgdata().setLen(bb.len());
curop.debug().responseLength = bb.len();
qr.msgdata().setOperation(opReply);
qr.setCursorId(0);
qr.setStartingFrom(0);
qr.setNReturned(1);
result.setData(qr.view2ptr(), true);
return "";
}
// We freak out later if this changes before we're done with the query.
const ChunkVersion shardingVersionAtStart = shardingState.getVersion(nss.ns());
// Handle query option $maxTimeMS (not used with commands).
curop.setMaxTimeMicros(static_cast<unsigned long long>(pq.getMaxTimeMS()) * 1000);
txn->checkForInterrupt(); // May trigger maxTimeAlwaysTimeOut fail point.
// uassert if we are not on a primary, and not a secondary with SlaveOk query parameter set.
bool slaveOK = pq.isSlaveOk() || pq.hasReadPref();
Status serveReadsStatus = repl::getGlobalReplicationCoordinator()->checkCanServeReadsFor(
txn,
nss,
slaveOK);
uassertStatusOK(serveReadsStatus);
// Run the query.
// bb is used to hold query results
// this buffer should contain either requested documents per query or
//.........这里部分代码省略.........