本文整理汇总了C++中NamespaceString::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ NamespaceString::toString方法的具体用法?C++ NamespaceString::toString怎么用?C++ NamespaceString::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceString
的用法示例。
在下文中一共展示了NamespaceString::toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expectCount
void ShardingTestFixture::expectCount(const HostAndPort& configHost,
const NamespaceString& expectedNs,
const BSONObj& expectedQuery,
const StatusWith<long long>& response) {
onCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(configHost, request.target);
string cmdName = request.cmdObj.firstElement().fieldName();
ASSERT_EQUALS("count", cmdName);
const NamespaceString nss(request.dbname, request.cmdObj.firstElement().String());
ASSERT_EQUALS(expectedNs.toString(), nss.toString());
if (expectedQuery.isEmpty()) {
auto queryElem = request.cmdObj["query"];
ASSERT_TRUE(queryElem.eoo() || queryElem.Obj().isEmpty());
} else {
ASSERT_EQUALS(expectedQuery, request.cmdObj["query"].Obj());
}
if (response.isOK()) {
return BSON("ok" << 1 << "n" << response.getValue());
}
checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
BSONObjBuilder responseBuilder;
Command::appendCommandStatus(responseBuilder, response.getStatus());
return responseBuilder.obj();
});
}
示例2: setNs
void IndexDescriptor::setNs(NamespaceString ns) {
_parentNS = ns.toString();
_indexNamespace = makeIndexNamespace(_parentNS, _indexName);
// Construct a new infoObj with the namespace field replaced.
_infoObj = renameNsInIndexSpec(_infoObj, ns);
}
示例3: expectInserts
void ShardingTestFixture::expectInserts(const NamespaceString& nss,
const std::vector<BSONObj>& expected) {
onCommand([&nss, &expected](const RemoteCommandRequest& request) {
ASSERT_EQUALS(nss.db(), request.dbname);
BatchedInsertRequest actualBatchedInsert;
std::string errmsg;
ASSERT_TRUE(actualBatchedInsert.parseBSON(request.dbname, request.cmdObj, &errmsg));
ASSERT_EQUALS(nss.toString(), actualBatchedInsert.getNS().toString());
auto inserted = actualBatchedInsert.getDocuments();
ASSERT_EQUALS(expected.size(), inserted.size());
auto itInserted = inserted.begin();
auto itExpected = expected.begin();
for (; itInserted != inserted.end(); itInserted++, itExpected++) {
ASSERT_EQ(*itExpected, *itInserted);
}
BatchedCommandResponse response;
response.setOk(true);
return response.toBSON();
});
}
示例4: onFindWithMetadataCommand
void NetworkTestEnv::onFindWithMetadataCommand(OnFindCommandWithMetadataFunction func) {
onCommandWithMetadata([&func](const RemoteCommandRequest& request) -> RemoteCommandResponse {
const auto& resultStatus = func(request);
if (!resultStatus.isOK()) {
return resultStatus.getStatus();
}
std::vector<BSONObj> result;
BSONObj metadata;
std::tie(result, metadata) = resultStatus.getValue();
BSONArrayBuilder arr;
for (const auto& obj : result) {
arr.append(obj);
}
const NamespaceString nss =
NamespaceString(request.dbname, request.cmdObj.firstElement().String());
BSONObjBuilder resultBuilder;
appendCursorResponseObject(0LL, nss.toString(), arr.arr(), &resultBuilder);
return RemoteCommandResponse(resultBuilder.obj(), metadata, Milliseconds(1));
});
}
示例5: dropIndexes
Status dropIndexes(OperationContext* txn,
const NamespaceString& ns,
const BSONObj& idxDescriptor,
BSONObjBuilder* result) {
StringData dbName = ns.db();
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
ScopedTransaction transaction(txn, MODE_IX);
AutoGetDb autoDb(txn, dbName, MODE_X);
bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() &&
!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(ns);
if (userInitiatedWritesAndNotPrimary) {
return Status(ErrorCodes::NotMaster,
str::stream() << "Not primary while dropping indexes in "
<< ns.toString());
}
WriteUnitOfWork wunit(txn);
Status status = wrappedRun(txn, dbName, ns, autoDb.getDb(), idxDescriptor, result);
if (!status.isOK()) {
return status;
}
getGlobalServiceContext()->getOpObserver()->onDropIndex(
txn, dbName.toString() + ".$cmd", idxDescriptor);
wunit.commit();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "dropIndexes", dbName);
return Status::OK();
}
示例6: nss
RecordStoreV1Base* MMAPV1DatabaseCatalogEntry::_getNamespaceRecordStore() const {
const NamespaceString nss(name(), "system.namespaces");
CollectionMap::const_iterator i = _collections.find(nss.toString());
invariant(i != _collections.end());
return i->second->recordStore.get();
}
示例7: expectGetShards
void ShardingTestFixture::expectGetShards(const std::vector<ShardType>& shards) {
onFindCommand([this, &shards](const RemoteCommandRequest& request) {
const NamespaceString nss(request.dbname, request.cmdObj.firstElement().String());
ASSERT_EQ(nss.toString(), ShardType::ConfigNS);
auto queryResult = LiteParsedQuery::makeFromFindCommand(nss, request.cmdObj, false);
ASSERT_OK(queryResult.getStatus());
const auto& query = queryResult.getValue();
ASSERT_EQ(query->ns(), ShardType::ConfigNS);
ASSERT_EQ(query->getFilter(), BSONObj());
ASSERT_EQ(query->getSort(), BSONObj());
ASSERT_FALSE(query->getLimit().is_initialized());
checkReadConcern(request.cmdObj, Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
vector<BSONObj> shardsToReturn;
std::transform(shards.begin(),
shards.end(),
std::back_inserter(shardsToReturn),
[](const ShardType& shard) { return shard.toBSON(); });
return shardsToReturn;
});
}
示例8: add_ns
void NamespaceIndex::add_ns(OperationContext* txn,
const Namespace& ns,
const NamespaceDetails* details) {
const NamespaceString nss(ns.toString());
invariant(txn->lockState()->isDbLockedForMode(nss.db(), MODE_X));
massert(17315, "no . in ns", nsIsFull(nss.toString()));
uassert(10081, "too many namespaces/collections", _ht->put(txn, ns, *details));
}
示例9: _collectionClonerCallback
void DatabaseCloner::_collectionClonerCallback(const Status& status, const NamespaceString& nss) {
auto newStatus = status;
UniqueLock lk(_mutex);
if (!status.isOK()) {
newStatus = {status.code(),
str::stream() << "While cloning collection '" << nss.toString()
<< "' there was an error '"
<< status.reason()
<< "'"
};
_failedNamespaces.push_back({newStatus, nss});
}
++_stats.clonedCollections;
// Forward collection cloner result to caller.
// Failure to clone a collection does not stop the database cloner
// from cloning the rest of the collections in the listCollections result.
lk.unlock();
_collectionWork(newStatus, nss);
lk.lock();
_currentCollectionClonerIter++;
if (_currentCollectionClonerIter != _collectionCloners.end()) {
Status startStatus = _startCollectionCloner(*_currentCollectionClonerIter);
if (!startStatus.isOK()) {
LOG(1) << " failed to start collection cloning on "
<< _currentCollectionClonerIter->getSourceNamespace() << ": "
<< redact(startStatus);
_finishCallback_inlock(lk, startStatus);
return;
}
return;
}
Status finalStatus(Status::OK());
if (_failedNamespaces.size() > 0) {
finalStatus = {ErrorCodes::InitialSyncFailure,
str::stream() << "Failed to clone " << _failedNamespaces.size()
<< " collection(s) in '"
<< _dbname
<< "' from "
<< _source.toString()
};
}
_finishCallback_inlock(lk, finalStatus);
}
示例10: dropCollectionEvenIfSystem
Status Database::dropCollectionEvenIfSystem(OperationContext* opCtx,
const NamespaceString& fullns) {
invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_X));
LOG(1) << "dropCollection: " << fullns;
Collection* collection = getCollection(fullns);
if (!collection) {
return Status::OK(); // Post condition already met.
}
massertNamespaceNotIndex(fullns.toString(), "dropCollection");
BackgroundOperation::assertNoBgOpInProgForNs(fullns);
audit::logDropCollection(&cc(), fullns.toString());
Status s = collection->getIndexCatalog()->dropAllIndexes(opCtx, true);
if (!s.isOK()) {
warning() << "could not drop collection, trying to drop indexes" << fullns << " because of "
<< redact(s.toString());
return s;
}
verify(collection->_details->getTotalIndexCount(opCtx) == 0);
LOG(1) << "\t dropIndexes done";
Top::get(opCtx->getClient()->getServiceContext()).collectionDropped(fullns.toString());
// We want to destroy the Collection object before telling the StorageEngine to destroy the
// RecordStore.
_clearCollectionCache(opCtx, fullns.toString(), "collection dropped");
s = _dbEntry->dropCollection(opCtx, fullns.toString());
if (!s.isOK())
return s;
DEV {
// check all index collection entries are gone
string nstocheck = fullns.toString() + ".$";
for (CollectionMap::const_iterator i = _collections.begin(); i != _collections.end(); ++i) {
string temp = i->first;
if (temp.find(nstocheck) != 0)
continue;
log() << "after drop, bad cache entries for: " << fullns << " have " << temp;
verify(0);
}
}
getGlobalServiceContext()->getOpObserver()->onDropCollection(opCtx, fullns);
return Status::OK();
}
示例11: createIndexOnConfig
Status ShardLocal::createIndexOnConfig(OperationContext* txn,
const NamespaceString& ns,
const BSONObj& keys,
bool unique) {
invariant(ns.db() == "config" || ns.db() == "admin");
try {
DBDirectClient client(txn);
IndexSpec index;
index.addKeys(keys);
index.unique(unique);
client.createIndex(ns.toString(), index);
} catch (const DBException& e) {
return e.toStatus();
}
return Status::OK();
}
示例12: appendCollectionRecordCount
Status appendCollectionRecordCount(OperationContext* opCtx,
const NamespaceString& nss,
BSONObjBuilder* result) {
AutoGetCollectionForReadCommand ctx(opCtx, nss);
if (!ctx.getDb()) {
return {ErrorCodes::BadValue,
str::stream() << "Database [" << nss.db().toString() << "] not found."};
}
Collection* collection = ctx.getCollection();
if (!collection) {
return {ErrorCodes::BadValue,
str::stream() << "Collection [" << nss.toString() << "] not found."};
}
result->appendNumber("count", static_cast<long long>(collection->numRecords(opCtx)));
return Status::OK();
}
示例13: shouldRetry
bool SyncTail::shouldRetry(OperationContext* txn, const BSONObj& o) {
const NamespaceString nss(o.getStringField("ns"));
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
// Take an X lock on the database in order to preclude other modifications.
// Also, the database might not exist yet, so create it.
AutoGetOrCreateDb autoDb(txn, nss.db(), MODE_X);
Database* const db = autoDb.getDb();
// we don't have the object yet, which is possible on initial sync. get it.
log() << "adding missing object" << endl; // rare enough we can log
BSONObj missingObj = getMissingDoc(txn, db, o);
if (missingObj.isEmpty()) {
log() << "missing object not found on source."
" presumably deleted later in oplog";
log() << "o2: " << o.getObjectField("o2").toString();
log() << "o firstfield: " << o.getObjectField("o").firstElementFieldName();
return false;
} else {
WriteUnitOfWork wunit(txn);
Collection* const coll = db->getOrCreateCollection(txn, nss.toString());
invariant(coll);
Status status = coll->insertDocument(txn, missingObj, true);
uassert(15917,
str::stream() << "failed to insert missing doc: " << status.toString(),
status.isOK());
LOG(1) << "inserted missing doc: " << missingObj.toString() << endl;
wunit.commit();
return true;
}
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "InsertRetry", nss.ns());
// fixes compile errors on GCC - see SERVER-18219 for details
MONGO_UNREACHABLE;
}
示例14: makeCursorResponse
BSONObj AbstractOplogFetcherTest::makeCursorResponse(CursorId cursorId,
Fetcher::Documents oplogEntries,
bool isFirstBatch,
const NamespaceString& nss) {
BSONObjBuilder bob;
{
BSONObjBuilder cursorBob(bob.subobjStart("cursor"));
cursorBob.append("id", cursorId);
cursorBob.append("ns", nss.toString());
{
BSONArrayBuilder batchBob(
cursorBob.subarrayStart(isFirstBatch ? "firstBatch" : "nextBatch"));
for (auto oplogEntry : oplogEntries) {
batchBob.append(oplogEntry);
}
}
}
bob.append("ok", 1);
return bob.obj();
}
示例15: onFindCommand
void NetworkTestEnv::onFindCommand(OnFindCommandFunction func) {
onCommand([&func](const RemoteCommandRequest& request) -> StatusWith<BSONObj> {
const auto& resultStatus = func(request);
if (!resultStatus.isOK()) {
return resultStatus.getStatus();
}
BSONArrayBuilder arr;
for (const auto& obj : resultStatus.getValue()) {
arr.append(obj);
}
const NamespaceString nss =
NamespaceString(request.dbname, request.cmdObj.firstElement().String());
BSONObjBuilder result;
appendCursorResponseObject(0LL, nss.toString(), arr.arr(), &result);
return result.obj();
});
}