MongoDataFile* Database::suitableFile( const char *ns, int sizeNeeded, bool preallocate, bool enforceQuota ) { // check existing files for ( int i=numFiles()-1; i>=0; i-- ) { MongoDataFile* f = getFile( i ); if ( f->getHeader()->unusedLength >= sizeNeeded ) { // we don't enforce the quota on "special" namespaces as that could lead to problems -- e.g. // rejecting an index insert after inserting the main record. if( cmdLine.quota && enforceQuota && i > cmdLine.quotaFiles && !NamespaceString::special(ns) ) ; else return f; } } if( cmdLine.quota && enforceQuota && numFiles() >= cmdLine.quotaFiles && !NamespaceString::special(ns) ) uasserted(12501, "quota exceeded"); // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { MongoDataFile* f = addAFile( sizeNeeded, preallocate ); if ( f->getHeader()->unusedLength >= sizeNeeded ) return f; if ( f->getHeader()->fileLength >= MongoDataFile::maxSize() ) // this is as big as they get so might as well stop return f; } uasserted(14810, "couldn't allocate space (suitableFile)"); // callers don't check for null return code return 0; }
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" ); }
MongoDataFile* Database::suitableFile( const char *ns, int sizeNeeded, bool preallocate, bool enforceQuota ) { // check existing files for ( int i=numFiles()-1; i>=0; i-- ) { MongoDataFile* f = getFile( i ); if ( f->getHeader()->unusedLength >= sizeNeeded ) { if ( fileIndexExceedsQuota( ns, i-1, enforceQuota ) ) // NOTE i-1 is the value used historically for this check. ; else return f; } } if ( fileIndexExceedsQuota( ns, numFiles(), enforceQuota ) ) uasserted(12501, "quota exceeded"); // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { MongoDataFile* f = addAFile( sizeNeeded, preallocate ); if ( f->getHeader()->unusedLength >= sizeNeeded ) return f; if ( f->getHeader()->fileLength >= MongoDataFile::maxSize() ) // this is as big as they get so might as well stop return f; } uasserted(14810, "couldn't allocate space (suitableFile)"); // callers don't check for null return code return 0; }
MongoDataFile* Database::suitableFile( int sizeNeeded, bool preallocate ) { // check existing files for ( int i=numFiles()-1; i>=0; i-- ) { MongoDataFile* f = getFile( i ); if ( f->getHeader()->unusedLength >= sizeNeeded ) return f; } // allocate files until we either get one big enough or hit maxSize for ( int i = 0; i < 8; i++ ) { MongoDataFile* f = addAFile( sizeNeeded, preallocate ); if ( f->getHeader()->unusedLength >= sizeNeeded ) return f; if ( f->getHeader()->fileLength >= MongoDataFile::maxSize() ) // this is as big as they get so might as well stop return f; } return 0; }
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" ); }
DiskLoc ExtentManager::createExtent( int size, int maxFileNoForQuota ) { 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, size, maxFileNoForQuota ); } } if ( maxFileNoForQuota > 0 && static_cast<int>( numFiles() ) >= maxFileNoForQuota && !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, size, maxFileNoForQuota ); } } // callers don't check for null return code, so assert msgasserted(14810, "couldn't allocate space for a new extent" ); }