本文整理汇总了C++中BSONObjSet类的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjSet类的具体用法?C++ BSONObjSet怎么用?C++ BSONObjSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BSONObjSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fetchIndexInserters
/* step one of adding keys to index idxNo for a new record
@return true means done. false means multikey involved and more work to do
*/
void fetchIndexInserters(BSONObjSet & /*out*/keys,
IndexInterface::IndexInserter &inserter,
NamespaceDetails *d,
int idxNo,
const BSONObj& obj,
DiskLoc recordLoc) {
IndexDetails &idx = d->idx(idxNo);
idx.getKeysFromObject(obj, keys);
if( keys.empty() )
return;
bool dupsAllowed = !idx.unique();
Ordering ordering = Ordering::make(idx.keyPattern());
try {
// we can't do the two step method with multi keys as insertion of one key changes the indexes
// structure. however we can do the first key of the set so we go ahead and do that FWIW
inserter.addInsertionContinuation(
idx.idxInterface().beginInsertIntoIndex(
idxNo, idx, recordLoc, *keys.begin(), ordering, dupsAllowed));
}
catch (AssertionException& e) {
if( e.getCode() == 10287 && idxNo == d->nIndexes ) {
DEV log() << "info: caught key already in index on bg indexing (ok)" << endl;
}
else {
throw;
}
}
}
示例2: addKeysToIndex
/* add keys to index idxNo for a new record */
static void addKeysToIndex(const char *ns, NamespaceDetails *d, int idxNo, BSONObj& obj,
DiskLoc recordLoc, bool dupsAllowed) {
IndexDetails& idx = d->idx(idxNo);
BSONObjSet keys;
idx.getKeysFromObject(obj, keys);
if( keys.empty() )
return;
BSONObj order = idx.keyPattern();
IndexInterface& ii = idx.idxInterface();
Ordering ordering = Ordering::make(order);
int n = 0;
for ( BSONObjSet::iterator i=keys.begin(); i != keys.end(); i++ ) {
if( ++n == 2 ) {
d->setIndexIsMultikey(ns, idxNo);
}
verify( !recordLoc.isNull() );
try {
ii.bt_insert(idx.head, recordLoc, *i, ordering, dupsAllowed, idx);
}
catch (AssertionException& e) {
if( e.getCode() == 10287 && idxNo == d->nIndexes ) {
DEV log() << "info: caught key already in index on bg indexing (ok)" << endl;
continue;
}
if( !dupsAllowed ) {
// dup key exception, presumably.
throw;
}
problem() << " caught assertion addKeysToIndex " << idx.indexNamespace() << " " << obj["_id"] << endl;
}
}
}
示例3: truncateSortSet
BSONObjSet DocumentSource::truncateSortSet(const BSONObjSet& sorts,
const std::set<std::string>& fields) {
BSONObjSet out = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
for (auto&& sort : sorts) {
BSONObjBuilder outputSort;
for (auto&& key : sort) {
auto keyName = key.fieldNameStringData();
bool shouldAppend = true;
for (auto&& field : fields) {
if (keyName == field || keyName.startsWith(field + '.')) {
shouldAppend = false;
break;
}
}
if (!shouldAppend) {
break;
}
outputSort.append(key);
}
BSONObj outSortObj = outputSort.obj();
if (!outSortObj.isEmpty()) {
out.insert(outSortObj);
}
}
return out;
}
示例4: builder
void NamespaceDetails::ColdIndexer::build() {
Lock::assertWriteLocked(_d->_ns);
if (_isSecondaryIndex) {
IndexDetails::Builder builder(*_idx);
const int indexNum = _d->idxNo(*_idx);
for (shared_ptr<Cursor> cursor(BasicCursor::make(_d));
cursor->ok(); cursor->advance()) {
BSONObj pk = cursor->currPK();
BSONObj obj = cursor->current();
BSONObjSet keys;
_idx->getKeysFromObject(obj, keys);
if (keys.size() > 1) {
_d->setIndexIsMultikey(indexNum);
}
for (BSONObjSet::const_iterator ki = keys.begin(); ki != keys.end(); ++ki) {
builder.insertPair(*ki, &pk, obj);
}
killCurrentOp.checkForInterrupt(); // uasserts if we should stop
}
builder.done();
// If the index is unique, check all adjacent keys for a duplicate.
if (_idx->unique()) {
_d->checkIndexUniqueness(*_idx);
}
}
}
示例5: getOutputSorts
BSONObjSet DocumentSourceLookUp::getOutputSorts() {
BSONObjSet out;
BSONObjSet inputSort = pSource->getOutputSorts();
std::string asPath = _as.getPath(false);
for (auto&& sortObj : inputSort) {
// Truncate each sortObj at the '_as' path.
BSONObjBuilder outputSort;
for (BSONElement fieldSort : sortObj) {
if (fieldSort.fieldNameStringData() == asPath) {
break;
}
outputSort.append(fieldSort);
}
BSONObj outSortObj = outputSort.obj();
if (!outSortObj.isEmpty()) {
out.insert(outSortObj);
}
}
return out;
}
示例6: findSingle
RecordId IndexAccessMethod::findSingle(OperationContext* opCtx, const BSONObj& requestedKey) const {
// Generate the key for this index.
BSONObj actualKey;
if (_btreeState->getCollator()) {
// For performance, call get keys only if there is a non-simple collation.
BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths* multikeyPaths = nullptr;
getKeys(requestedKey, GetKeysMode::kEnforceConstraints, &keys, multikeyPaths);
invariant(keys.size() == 1);
actualKey = *keys.begin();
} else {
actualKey = requestedKey;
}
std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(opCtx));
const auto requestedInfo = kDebugBuild ? SortedDataInterface::Cursor::kKeyAndLoc
: SortedDataInterface::Cursor::kWantLoc;
if (auto kv = cursor->seekExact(actualKey, requestedInfo)) {
// StorageEngine should guarantee these.
dassert(!kv->loc.isNull());
dassert(kv->key.woCompare(actualKey, /*order*/ BSONObj(), /*considerFieldNames*/ false) ==
0);
return kv->loc;
}
return RecordId();
}
示例7: invariant
Status IndexAccessMethod::BulkBuilder::insert(OperationContext* txn,
const BSONObj& obj,
const RecordId& loc,
const InsertDeleteOptions& options,
int64_t* numInserted) {
BSONObjSet keys = SimpleBSONObjComparator::kInstance.makeBSONObjSet();
MultikeyPaths multikeyPaths;
_real->getKeys(obj, &keys, &multikeyPaths);
_everGeneratedMultipleKeys = _everGeneratedMultipleKeys || (keys.size() > 1);
if (!multikeyPaths.empty()) {
if (_indexMultikeyPaths.empty()) {
_indexMultikeyPaths = multikeyPaths;
} else {
invariant(_indexMultikeyPaths.size() == multikeyPaths.size());
for (size_t i = 0; i < multikeyPaths.size(); ++i) {
_indexMultikeyPaths[i].insert(multikeyPaths[i].begin(), multikeyPaths[i].end());
}
}
}
for (BSONObjSet::iterator it = keys.begin(); it != keys.end(); ++it) {
_sorter->add(*it, loc);
_keysInserted++;
}
if (NULL != numInserted) {
*numInserted += keys.size();
}
return Status::OK();
}
示例8: indexRecordUsingTwoSteps
/** add index keys for a newly inserted record
done in two steps/phases to allow potential deferal of write lock portion in the future
*/
void indexRecordUsingTwoSteps(const char *ns, NamespaceDetails *d, BSONObj obj,
DiskLoc loc, bool shouldBeUnlocked) {
vector<int> multi;
vector<BSONObjSet> multiKeys;
IndexInterface::IndexInserter inserter;
// Step 1, read phase.
int n = d->nIndexesBeingBuilt();
{
BSONObjSet keys;
for ( int i = 0; i < n; i++ ) {
// this call throws on unique constraint violation. we haven't done any writes yet so that is fine.
fetchIndexInserters(/*out*/keys, inserter, d, i, obj, loc);
if( keys.size() > 1 ) {
multi.push_back(i);
multiKeys.push_back(BSONObjSet());
multiKeys[multiKeys.size()-1].swap(keys);
}
keys.clear();
}
}
inserter.finishAllInsertions(); // Step 2, write phase.
// now finish adding multikeys
for( unsigned j = 0; j < multi.size(); j++ ) {
unsigned i = multi[j];
BSONObjSet& keys = multiKeys[j];
IndexDetails& idx = d->idx(i);
IndexInterface& ii = idx.idxInterface();
Ordering ordering = Ordering::make(idx.keyPattern());
d->setIndexIsMultikey(ns, i);
for( BSONObjSet::iterator k = ++keys.begin()/*skip 1*/; k != keys.end(); k++ ) {
try {
ii.bt_insert(idx.head, loc, *k, ordering, !idx.unique(), idx);
} catch (AssertionException& e) {
if( e.getCode() == 10287 && (int) i == d->nIndexes ) {
DEV log() << "info: caught key already in index on bg indexing (ok)" << endl;
}
else {
/* roll back previously added index entries
note must do self index as it is multikey and could require some cleanup itself
*/
for( int j = 0; j < n; j++ ) {
try {
_unindexRecord(d->idx(j), obj, loc, false);
}
catch(...) {
log(3) << "unindex fails on rollback after unique key constraint prevented insert\n";
}
}
throw;
}
}
}
}
}
示例9: getKeys
// Find the keys for obj, put them in the tree pointing to loc
Status BtreeBasedAccessMethod::insert(OperationContext* txn,
const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numInserted) {
*numInserted = 0;
BSONObjSet keys;
// Delegate to the subclass.
getKeys(obj, &keys);
Status ret = Status::OK();
for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) {
Status status = _newInterface->insert(txn, *i, loc, options.dupsAllowed);
// Everything's OK, carry on.
if (status.isOK()) {
++*numInserted;
continue;
}
// Error cases.
if (ErrorCodes::KeyTooLong == status.code()) {
// Ignore this error if we're on a secondary.
if (!txn->isPrimaryFor(_btreeState->ns())) {
continue;
}
// The user set a parameter to ignore key too long errors.
if (!failIndexKeyTooLong) {
continue;
}
}
if (ErrorCodes::UniqueIndexViolation == status.code()) {
// We ignore it for some reason in BG indexing.
if (!_btreeState->isReady()) {
DEV log() << "info: key already in index during bg indexing (ok)\n";
continue;
}
}
// Clean up after ourselves.
for (BSONObjSet::const_iterator j = keys.begin(); j != i; ++j) {
removeOneKey(txn, *j, loc);
*numInserted = 0;
}
return status;
}
if (*numInserted > 1) {
_btreeState->setMultikey( txn );
}
return ret;
}
示例10: insertKeys
Status AbstractIndexAccessMethod::insertKeys(OperationContext* opCtx,
const BSONObjSet& keys,
const BSONObjSet& multikeyMetadataKeys,
const MultikeyPaths& multikeyPaths,
const RecordId& loc,
const InsertDeleteOptions& options,
InsertResult* result) {
bool checkIndexKeySize = shouldCheckIndexKeySize(opCtx);
// Add all new data keys, and all new multikey metadata keys, into the index. When iterating
// over the data keys, each of them should point to the doc's RecordId. When iterating over
// the multikey metadata keys, they should point to the reserved 'kMultikeyMetadataKeyId'.
for (const auto keySet : {&keys, &multikeyMetadataKeys}) {
const auto& recordId = (keySet == &keys ? loc : kMultikeyMetadataKeyId);
for (const auto& key : *keySet) {
Status status = checkIndexKeySize ? checkKeySize(key) : Status::OK();
if (status.isOK()) {
bool unique = _descriptor->unique();
StatusWith<SpecialFormatInserted> ret =
_newInterface->insert(opCtx, key, recordId, !unique /* dupsAllowed */);
status = ret.getStatus();
// When duplicates are encountered and allowed, retry with dupsAllowed. Add the
// key to the output vector so callers know which duplicate keys were inserted.
if (ErrorCodes::DuplicateKey == status.code() && options.dupsAllowed) {
invariant(unique);
ret = _newInterface->insert(opCtx, key, recordId, true /* dupsAllowed */);
status = ret.getStatus();
// This is speculative in that the 'dupsInserted' vector is not used by any code
// today. It is currently in place to test detecting duplicate key errors during
// hybrid index builds. Duplicate detection in the future will likely not take
// place in this insert() method.
if (status.isOK() && result) {
result->dupsInserted.push_back(key);
}
}
if (status.isOK() && ret.getValue() == SpecialFormatInserted::LongTypeBitsInserted)
_btreeState->setIndexKeyStringWithLongTypeBitsExistsOnDisk(opCtx);
}
if (isFatalError(opCtx, status, key)) {
return status;
}
}
}
if (result) {
result->numInserted += keys.size() + multikeyMetadataKeys.size();
}
if (shouldMarkIndexAsMultikey(keys, multikeyMetadataKeys, multikeyPaths)) {
_btreeState->setMultikey(opCtx, multikeyPaths);
}
return Status::OK();
}
示例11: indexKeyPatterns
AllowedIndicesFilter::AllowedIndicesFilter(const BSONObjSet& indexKeyPatterns,
const stdx::unordered_set<std::string>& indexNames)
: indexKeyPatterns(SimpleBSONObjComparator::kInstance.makeBSONObjSet()),
indexNames(indexNames) {
for (BSONObjSet::const_iterator i = indexKeyPatterns.begin(); i != indexKeyPatterns.end();
++i) {
const BSONObj& indexKeyPattern = *i;
this->indexKeyPatterns.insert(indexKeyPattern.getOwned());
}
}
示例12: prefetchIndexPages
// page in pages needed for all index lookups on a given object
void prefetchIndexPages(Collection* collection,
const repl::ReplSetImpl::IndexPrefetchConfig& prefetchConfig,
const BSONObj& obj) {
DiskLoc unusedDl; // unused
BSONObjSet unusedKeys;
// do we want prefetchConfig to be (1) as-is, (2) for update ops only, or (3) configured per op type?
// One might want PREFETCH_NONE for updates, but it's more rare that it is a bad idea for inserts.
// #3 (per op), a big issue would be "too many knobs".
switch (prefetchConfig) {
case repl::ReplSetImpl::PREFETCH_NONE:
return;
case repl::ReplSetImpl::PREFETCH_ID_ONLY:
{
TimerHolder timer( &prefetchIndexStats);
// on the update op case, the call to prefetchRecordPages will touch the _id index.
// thus perhaps this option isn't very useful?
try {
IndexDescriptor* desc = collection->getIndexCatalog()->findIdIndex();
if ( !desc )
return;
IndexAccessMethod* iam = collection->getIndexCatalog()->getIndex( desc );
verify( iam );
iam->touch(obj);
}
catch (const DBException& e) {
LOG(2) << "ignoring exception in prefetchIndexPages(): " << e.what() << endl;
}
break;
}
case repl::ReplSetImpl::PREFETCH_ALL:
{
// indexCount includes all indexes, including ones
// in the process of being built
IndexCatalog::IndexIterator ii = collection->getIndexCatalog()->getIndexIterator( true );
while ( ii.more() ) {
TimerHolder timer( &prefetchIndexStats);
// This will page in all index pages for the given object.
try {
IndexDescriptor* desc = ii.next();
IndexAccessMethod* iam = collection->getIndexCatalog()->getIndex( desc );
verify( iam );
iam->touch(obj);
}
catch (const DBException& e) {
LOG(2) << "ignoring exception in prefetchIndexPages(): " << e.what() << endl;
}
unusedKeys.clear();
}
break;
}
default:
fassertFailed(16427);
}
}
示例13: insert
virtual Status insert(const BSONObj& obj,
const DiskLoc& loc,
const InsertDeleteOptions& options,
int64_t* numInserted) {
BSONObjSet keys;
_real->getKeys(obj, &keys);
_phase1.addKeys(keys, loc, false);
if ( numInserted )
*numInserted += keys.size();
return Status::OK();
}
示例14: getKeys
void getKeys( const BSONObj &obj, BSONObjSet &keys ) const {
if ( _spec._indexType.get() ) { //plugin (eg geo)
_spec._indexType->getKeys( obj , keys );
return;
}
vector<const char*> fieldNames( _spec._fieldNames );
vector<BSONElement> fixed( _spec._fixed );
_getKeys( fieldNames , fixed , obj, keys );
if ( keys.empty() && ! _spec._sparse )
keys.insert( _spec._nullKey );
}
示例15: getKeys
Status IndexAccessMethod::touch(OperationContext* txn, const BSONObj& obj) {
BSONObjSet keys;
getKeys(obj, &keys);
std::unique_ptr<SortedDataInterface::Cursor> cursor(_newInterface->newCursor(txn));
for (BSONObjSet::const_iterator i = keys.begin(); i != keys.end(); ++i) {
cursor->seekExact(*i);
}
return Status::OK();
}