void dict_set(dict_t* dict, void* key, void* value) { debug("Setting 0x%x->0x%x in dict at 0x%x\n", (uint32_t)key, (uint32_t)value, (uint32_t)dict); entry_t* entry = _findEntry(dict, key); if(entry == NULL) { debug("No such entry 0x%x, creating new one\n", (uint32_t)key); // Create a new entry entry = (entry_t*)malloc(sizeof(entry_t)); } if(dict->firstEntry == NULL) { // This is the very first entry debug("Setting 0x%x as first entry for dict 0x%x\n", (uint32_t)key, (uint32_t)dict); dict->firstEntry = entry; dict->lastEntry = entry; } else { // Append the entry to the list dict->lastEntry->next = entry; dict->lastEntry = entry; } entry->key = key; entry->value = value; entry->next = NULL; entry->parent = dict; }
std::string KVCatalog::getIndexIdent( OperationContext* opCtx, const StringData& ns, const StringData& idxName ) const { DiskLoc loc; BSONObj obj = _findEntry( opCtx, ns, &loc ); BSONObj idxIdent = obj["idxIdent"].Obj(); return idxIdent[idxName].String(); }
const BSONCollectionCatalogEntry::MetaData KVCatalog::getMetaData( OperationContext* opCtx, const StringData& ns ) { DiskLoc loc; BSONObj obj = _findEntry( opCtx, ns, &loc ); LOG(1) << " got: " << obj; BSONCollectionCatalogEntry::MetaData md; if ( obj["md"].isABSONObj() ) md.parse( obj["md"].Obj() ); return md; }
void KVCatalog::putMetaData( OperationContext* opCtx, const StringData& ns, BSONCollectionCatalogEntry::MetaData& md ) { DiskLoc loc; BSONObj obj = _findEntry( opCtx, ns, &loc ); { // rebuilt doc BSONObjBuilder b; b.append( "md", md.toBSON() ); BSONObjBuilder newIdentMap; BSONObj oldIdentMap; if ( obj["idxIdent"].isABSONObj() ) oldIdentMap = obj["idxIdent"].Obj(); // fix ident map for ( size_t i = 0; i < md.indexes.size(); i++ ) { string name = md.indexes[i].name(); BSONElement e = oldIdentMap[name]; if ( e.type() == String ) { newIdentMap.append( e ); continue; } // missing, create new std::stringstream ss; ss << getCollectionIdent( ns ) << '$' << name << '-' << _rand << '-' << _next.fetchAndAdd( 1 ); newIdentMap.append( name, ss.str() ); } b.append( "idxIdent", newIdentMap.obj() ); // add whatever is left b.appendElementsUnique( obj ); obj = b.obj(); } StatusWith<DiskLoc> status = _rs->updateRecord( opCtx, loc, obj.objdata(), obj.objsize(), false, NULL ); fassert( 28521, status.getStatus() ); invariant( status.getValue() == loc ); }
Status KVCatalog::renameCollection( OperationContext* opCtx, const StringData& fromNS, const StringData& toNS, bool stayTemp ) { DiskLoc loc; BSONObj old = _findEntry( opCtx, fromNS, &loc ).getOwned(); { BSONObjBuilder b; b.append( "ns", toNS ); BSONCollectionCatalogEntry::MetaData md; md.parse( old["md"].Obj() ); md.rename( toNS ); if ( !stayTemp ) md.options.temp = false; b.append( "md", md.toBSON() ); b.appendElementsUnique( old ); BSONObj obj = b.obj(); StatusWith<DiskLoc> status = _rs->updateRecord( opCtx, loc, obj.objdata(), obj.objsize(), false, NULL ); fassert( 28522, status.getStatus() ); invariant( status.getValue() == loc ); } boost::mutex::scoped_lock lk( _identsLock ); _idents.erase( fromNS.toString() ); _idents[toNS.toString()] = Entry( old["ident"].String(), loc ); return Status::OK(); }
void dict_del(dict_t* dict, void* key) { _deleteEntry(_findEntry(dict, key)); }