本文整理汇总了C++中recordFor函数的典型用法代码示例。如果您正苦于以下问题:C++ recordFor函数的具体用法?C++ recordFor怎么用?C++ recordFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了recordFor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recordFor
void RecordStoreV1Base::deleteRecord( TransactionExperiment* txn, const DiskLoc& dl ) {
Record* todelete = recordFor( dl );
/* remove ourself from the record next/prev chain */
{
if ( todelete->prevOfs() != DiskLoc::NullOfs ) {
DiskLoc prev = getPrevRecordInExtent( dl );
Record* prevRecord = recordFor( prev );
txn->writingInt( prevRecord->nextOfs() ) = todelete->nextOfs();
}
if ( todelete->nextOfs() != DiskLoc::NullOfs ) {
DiskLoc next = getNextRecord( dl );
Record* nextRecord = recordFor( next );
txn->writingInt( nextRecord->prevOfs() ) = todelete->prevOfs();
}
}
/* remove ourself from extent pointers */
{
Extent *e = txn->writing( _getExtent( _getExtentLocForRecord( dl ) ) );
if ( e->firstRecord == dl ) {
if ( todelete->nextOfs() == DiskLoc::NullOfs )
e->firstRecord.Null();
else
e->firstRecord.set(dl.a(), todelete->nextOfs() );
}
if ( e->lastRecord == dl ) {
if ( todelete->prevOfs() == DiskLoc::NullOfs )
e->lastRecord.Null();
else
e->lastRecord.set(dl.a(), todelete->prevOfs() );
}
}
/* add to the free list */
{
_details->incrementStats( txn, -1 * todelete->netLength(), -1 );
if ( _isSystemIndexes ) {
/* temp: if in system.indexes, don't reuse, and zero out: we want to be
careful until validated more, as IndexDetails has pointers
to this disk location. so an incorrectly done remove would cause
a lot of problems.
*/
memset( txn->writingPtr(todelete, todelete->lengthWithHeaders() ),
0, todelete->lengthWithHeaders() );
}
else {
DEV {
unsigned long long *p = reinterpret_cast<unsigned long long *>( todelete->data() );
*txn->writing(p) = 0;
}
addDeletedRec(txn, dl);
}
}
}
示例2: recordFor
StatusWith<DiskLoc> HeapRecordStore::updateRecord(OperationContext* txn,
const DiskLoc& loc,
const char* data,
int len,
bool enforceQuota,
UpdateMoveNotifier* notifier ) {
HeapRecord* oldRecord = recordFor( loc );
int oldLen = oldRecord->size;
if (_isCapped && len > oldLen) {
return StatusWith<DiskLoc>( ErrorCodes::InternalError,
"failing update: objects in a capped ns cannot grow",
10003 );
}
HeapRecord newRecord(len);
memcpy(newRecord.data.get(), data, len);
txn->recoveryUnit()->registerChange(new RemoveChange(_data, loc, *oldRecord));
_data->dataSize += len - oldLen;
*oldRecord = newRecord;
cappedDeleteAsNeeded(txn);
return StatusWith<DiskLoc>(loc);
}
示例3: getRecordAllocationSize
StatusWith<DiskLoc> RecordStoreV1Base::_insertRecord( OperationContext* txn,
const char* data,
int len,
bool enforceQuota ) {
int lenWHdr = getRecordAllocationSize( len + Record::HeaderSize );
fassert( 17208, lenWHdr >= ( len + Record::HeaderSize ) );
StatusWith<DiskLoc> loc = allocRecord( txn, lenWHdr, enforceQuota );
if ( !loc.isOK() )
return loc;
Record *r = recordFor( loc.getValue() );
fassert( 17210, r->lengthWithHeaders() >= lenWHdr );
// copy the data
r = reinterpret_cast<Record*>( txn->recoveryUnit()->writingPtr(r, lenWHdr) );
memcpy( r->data(), data, len );
_addRecordToRecListInExtent(txn, r, loc.getValue());
_details->incrementStats( txn, r->netLength(), 1 );
return loc;
}
示例4: shouldPadInserts
StatusWith<RecordId> RecordStoreV1Base::_insertRecord(OperationContext* txn,
const char* data,
int len,
bool enforceQuota) {
const int lenWHdr = len + MmapV1RecordHeader::HeaderSize;
const int lenToAlloc = shouldPadInserts() ? quantizeAllocationSpace(lenWHdr) : lenWHdr;
fassert(17208, lenToAlloc >= lenWHdr);
StatusWith<DiskLoc> loc = allocRecord(txn, lenToAlloc, enforceQuota);
if (!loc.isOK())
return StatusWith<RecordId>(loc.getStatus());
MmapV1RecordHeader* r = recordFor(loc.getValue());
fassert(17210, r->lengthWithHeaders() >= lenWHdr);
// copy the data
r = reinterpret_cast<MmapV1RecordHeader*>(txn->recoveryUnit()->writingPtr(r, lenWHdr));
memcpy(r->data(), data, len);
_addRecordToRecListInExtent(txn, r, loc.getValue());
_details->incrementStats(txn, r->netLength(), 1);
return StatusWith<RecordId>(loc.getValue().toRecordId());
}
示例5: recordFor
void RecordStoreV1Base::IntraExtentIterator::advance() {
if (_curr.isNull())
return;
const MmapV1RecordHeader* rec = recordFor(_curr);
const int nextOfs = _forward ? rec->nextOfs() : rec->prevOfs();
_curr = (nextOfs == DiskLoc::NullOfs ? DiskLoc() : DiskLoc(_curr.a(), nextOfs));
}
示例6: dassert
void RecordStoreV1Base::_addRecordToRecListInExtent(OperationContext* txn,
Record *r,
DiskLoc loc) {
dassert( recordFor(loc) == r );
Extent *e = _getExtent( _getExtentLocForRecord( loc ) );
if ( e->lastRecord.isNull() ) {
*txn->recoveryUnit()->writing(&e->firstRecord) = loc;
*txn->recoveryUnit()->writing(&e->lastRecord) = loc;
r->prevOfs() = r->nextOfs() = DiskLoc::NullOfs;
}
else {
Record *oldlast = recordFor(e->lastRecord);
r->prevOfs() = e->lastRecord.getOfs();
r->nextOfs() = DiskLoc::NullOfs;
txn->recoveryUnit()->writingInt(oldlast->nextOfs()) = loc.getOfs();
*txn->recoveryUnit()->writing(&e->lastRecord) = loc;
}
}
示例7: recordFor
DiskLoc RecordStoreV1Base::getNextRecordInExtent( const DiskLoc& loc ) const {
int nextOffset = recordFor( loc )->nextOfs();
if ( nextOffset == DiskLoc::NullOfs )
return DiskLoc();
fassert( 17441, abs(nextOffset) >= 8 ); // defensive
return DiskLoc( loc.a(), nextOffset );
}
示例8: recordFor
DiskLoc ExtentManager::getNextRecordInExtent( const DiskLoc& loc ) const {
int nextOffset = recordFor( loc )->nextOfs();
if ( nextOffset == DiskLoc::NullOfs )
return DiskLoc();
fassert( 16967, abs(nextOffset) >= 8 ); // defensive
return DiskLoc( loc.a(), nextOffset );
}
示例9: recordFor
DiskLoc RecordStoreV1Base::getPrevRecordInExtent( OperationContext* txn, const DiskLoc& loc ) const {
int prevOffset = recordFor( loc )->prevOfs();
if ( prevOffset == DiskLoc::NullOfs )
return DiskLoc();
fassert( 17442, abs(prevOffset) >= 8 ); // defensive
DiskLoc result( loc.a(), prevOffset );
return result;
}
示例10: DiskLoc
DiskLoc RecordStoreV1Base::IntraExtentIterator::getNext() {
if (_curr.isNull())
return DiskLoc();
const DiskLoc out = _curr; // we always return where we were, not where we will be.
const Record* rec = recordFor(_curr);
const int nextOfs = _forward ? rec->nextOfs() : rec->prevOfs();
_curr = (nextOfs == DiskLoc::NullOfs ? DiskLoc() : DiskLoc(_curr.a(), nextOfs));
return out;
}
示例11: recordFor
bool RecordStoreV1Base::findRecord( OperationContext* txn,
const DiskLoc& loc, RecordData* rd ) const {
// this is a bit odd, as the semantics of using the storage engine imply it _has_ to be.
// And in fact we can't actually check.
// So we assume the best.
Record* rec = recordFor(loc);
if ( !rec ) {
return false;
}
*rd = rec->toRecordData();
return true;
}
示例12: recordFor
Status HeapRecordStore::updateWithDamages( OperationContext* txn,
const DiskLoc& loc,
const char* damangeSource,
const mutablebson::DamageVector& damages ) {
HeapRecord* rec = recordFor( loc );
char* root = rec->data();
// All updates were in place. Apply them via durability and writing pointer.
mutablebson::DamageVector::const_iterator where = damages.begin();
const mutablebson::DamageVector::const_iterator end = damages.end();
for( ; where != end; ++where ) {
const char* sourcePtr = damangeSource + where->sourceOffset;
char* targetPtr = root + where->targetOffset;
std::memcpy(targetPtr, sourcePtr, where->size);
}
return Status::OK();
}
示例13: getRecordAllocationSize
StatusWith<DiskLoc> RecordStoreV1Base::insertRecord( TransactionExperiment* txn,
const DocWriter* doc,
int quotaMax ) {
int lenWHdr = doc->documentSize() + Record::HeaderSize;
if ( doc->addPadding() )
lenWHdr = getRecordAllocationSize( lenWHdr );
StatusWith<DiskLoc> loc = allocRecord( txn, lenWHdr, quotaMax );
if ( !loc.isOK() )
return loc;
Record *r = recordFor( loc.getValue() );
fassert( 17319, r->lengthWithHeaders() >= lenWHdr );
r = reinterpret_cast<Record*>( txn->writingPtr(r, lenWHdr) );
doc->writeDocument( r->data() );
_addRecordToRecListInExtent(txn, r, loc.getValue());
_details->incrementStats( txn, r->netLength(), 1 );
return loc;
}
示例14: log
void SimpleRecordStoreV1::_compactExtent(OperationContext* txn,
const DiskLoc extentLoc,
int extentNumber,
RecordStoreCompactAdaptor* adaptor,
const CompactOptions* compactOptions,
CompactStats* stats ) {
log() << "compact begin extent #" << extentNumber
<< " for namespace " << _ns << " " << extentLoc;
unsigned oldObjSize = 0; // we'll report what the old padding was
unsigned oldObjSizeWithPadding = 0;
Extent* const sourceExtent = _extentManager->getExtent( extentLoc );
sourceExtent->assertOk();
fassert( 17437, sourceExtent->validates(extentLoc) );
{
// The next/prev Record pointers within the Extent might not be in order so we first
// page in the whole Extent sequentially.
// TODO benchmark on slow storage to verify this is measurably faster.
log() << "compact paging in len=" << sourceExtent->length/1000000.0 << "MB" << endl;
Timer t;
size_t length = sourceExtent->length;
touch_pages( reinterpret_cast<const char*>(sourceExtent), length );
int ms = t.millis();
if( ms > 1000 )
log() << "compact end paging in " << ms << "ms "
<< sourceExtent->length/1000000.0/t.seconds() << "MB/sec" << endl;
}
{
// Move each Record out of this extent and insert it in to the "new" extents.
log() << "compact copying records" << endl;
long long totalNetSize = 0;
long long nrecords = 0;
DiskLoc nextSourceLoc = sourceExtent->firstRecord;
while (!nextSourceLoc.isNull()) {
txn->checkForInterrupt();
WriteUnitOfWork wunit(txn);
Record* recOld = recordFor(nextSourceLoc);
RecordData oldData = recOld->toRecordData();
nextSourceLoc = getNextRecordInExtent(txn, nextSourceLoc);
if ( compactOptions->validateDocuments && !adaptor->isDataValid( oldData ) ) {
// object is corrupt!
log() << "compact removing corrupt document!";
stats->corruptDocuments++;
}
else {
// How much data is in the record. Excludes padding and Record headers.
const unsigned rawDataSize = adaptor->dataSize( oldData );
nrecords++;
oldObjSize += rawDataSize;
oldObjSizeWithPadding += recOld->netLength();
// Allocation sizes include the headers and possibly some padding.
const unsigned minAllocationSize = rawDataSize + Record::HeaderSize;
unsigned allocationSize = minAllocationSize;
switch( compactOptions->paddingMode ) {
case CompactOptions::NONE: // no padding, unless using powerOf2Sizes
if ( _details->isUserFlagSet(Flag_UsePowerOf2Sizes) )
allocationSize = quantizePowerOf2AllocationSpace(minAllocationSize);
else
allocationSize = minAllocationSize;
break;
case CompactOptions::PRESERVE: // keep original padding
allocationSize = recOld->lengthWithHeaders();
break;
case CompactOptions::MANUAL: // user specified how much padding to use
allocationSize = compactOptions->computeRecordSize(minAllocationSize);
if (allocationSize < minAllocationSize
|| allocationSize > BSONObjMaxUserSize / 2 ) {
allocationSize = minAllocationSize;
}
break;
}
invariant(allocationSize >= minAllocationSize);
// Copy the data to a new record. Because we orphaned the record freelist at the
// start of the compact, this insert will allocate a record in a new extent.
// See the comment in compact() for more details.
CompactDocWriter writer( recOld, rawDataSize, allocationSize );
StatusWith<DiskLoc> status = insertRecord( txn, &writer, false );
uassertStatusOK( status.getStatus() );
const Record* newRec = recordFor(status.getValue());
invariant(unsigned(newRec->netLength()) >= rawDataSize);
totalNetSize += newRec->netLength();
// Tells the caller that the record has been moved, so it can do things such as
// add it to indexes.
adaptor->inserted(newRec->toRecordData(), status.getValue());
}
// Remove the old record from the linked list of records withing the sourceExtent.
//.........这里部分代码省略.........
示例15: recordFor
DiskLoc ExtentManager::extentLocFor( const DiskLoc& loc ) const {
Record* record = recordFor( loc );
return DiskLoc( loc.a(), record->extentOfs() );
}