DiskLoc DummyExtentManager::allocateExtent( OperationContext* txn, bool capped, int size, bool enforceQuota ) { size = quantizeExtentSize( size ); ExtentInfo info; info.data = static_cast<char*>( malloc( size ) ); info.length = size; DiskLoc loc( _extents.size(), 0 ); _extents.push_back( info ); Extent* e = getExtent( loc, false ); e->magic = Extent::extentSignature; e->myLoc = loc; e->xnext.Null(); e->xprev.Null(); e->length = size; e->firstRecord.Null(); e->lastRecord.Null(); return loc; }
DiskLoc MmapV1ExtentManager::_createExtent( OperationContext* txn, int size, bool enforceQuota ) { size = quantizeExtentSize( size ); if ( size > maxSize() ) size = maxSize(); verify( size < DataFile::maxSize() ); for ( int i = numFiles() - 1; i >= 0; i-- ) { DataFile* f = _getOpenFile(i); invariant(f); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( txn, i, f, size, enforceQuota ); } } _checkQuota( enforceQuota, numFiles() ); // no space in an existing file // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { DataFile* f = _addAFile( txn, size, false ); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( txn, numFiles() - 1, f, size, enforceQuota ); } } // callers don't check for null return code, so assert msgasserted(14810, "couldn't allocate space for a new extent" ); }
Extent* ExtentManager::createExtent(const char *ns, int size, bool newCapped, bool enforceQuota ) { size = quantizeExtentSize( size ); for ( int i = numFiles() - 1; i >= 0; i-- ) { DataFile* f = getFile( i ); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( i, f, ns, size, newCapped, enforceQuota ); } } // no space in an existing file // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { DataFile* f = addAFile( size, false ); if ( f->getHeader()->unusedLength >= size || f->getHeader()->fileLength >= DataFile::maxSize() ) { return _createExtentInFile( numFiles() - 1, f, ns, size, newCapped, enforceQuota ); } } // callers don't check for null return code, so assert msgasserted(14810, "couldn't allocate space for a new extent" ); }
int ExtentManager::followupSize(int len, int lastExtentLen) const { invariant(len < maxSize()); int x = initialSize(len); // changed from 1.20 to 1.35 in v2.1.x to get to larger extent size faster int y = (int)(lastExtentLen < 4000000 ? lastExtentLen * 4.0 : lastExtentLen * 1.35); int sz = y > x ? y : x; if (sz < lastExtentLen) { // this means there was an int overflow // so we should turn it into maxSize return maxSize(); } else if (sz > maxSize()) { return maxSize(); } sz = quantizeExtentSize(sz); verify(sz >= len); return sz; }
DiskLoc MmapV1ExtentManager::_createExtent( TransactionExperiment* txn, int size, int maxFileNoForQuota ) { size = quantizeExtentSize( size ); if ( size > maxSize() ) size = maxSize(); verify( size < DataFile::maxSize() ); for ( int i = numFiles() - 1; i >= 0; i-- ) { DataFile* f = getFile( txn, i ); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( txn, i, f, size, maxFileNoForQuota ); } } if ( maxFileNoForQuota > 0 && static_cast<int>( numFiles() ) >= maxFileNoForQuota && !cc().hasWrittenSinceCheckpoint() ) { _quotaExceeded(); } // no space in an existing file // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { DataFile* f = _addAFile( txn, size, false ); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( txn, numFiles() - 1, f, size, maxFileNoForQuota ); } } // callers don't check for null return code, so assert msgasserted(14810, "couldn't allocate space for a new extent" ); }
Extent* ExtentManager::createExtent(const char *ns, int size, bool newCapped, bool enforceQuota ) { size = quantizeExtentSize( size ); if ( size > Extent::maxSize() ) size = Extent::maxSize(); verify( size < DataFile::maxSize() ); for ( int i = numFiles() - 1; i >= 0; i-- ) { DataFile* f = getFile( i ); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( i, f, ns, size, newCapped, enforceQuota ); } } if ( enforceQuota && fileIndexExceedsQuota( ns, numFiles() ) && !cc().hasWrittenThisPass() ) { _quotaExceeded(); } // no space in an existing file // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { DataFile* f = addAFile( size, false ); if ( f->getHeader()->unusedLength >= size ) { return _createExtentInFile( numFiles() - 1, f, ns, size, newCapped, enforceQuota ); } } // callers don't check for null return code, so assert msgasserted(14810, "couldn't allocate space for a new extent" ); }