0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

move some extent methods into Extent class

This commit is contained in:
Eliot Horowitz 2010-12-24 13:43:06 -05:00
parent 19b8c2be8a
commit 1794b2fe34
3 changed files with 19 additions and 15 deletions

View File

@ -170,7 +170,7 @@ namespace mongo {
_applyOpToDataFiles( database, deleter, true );
}
int initialExtentSize(int len) {
int Extent::initialSize(int len) {
long long sz = len * 16;
if ( len < 1000 ) sz = len * 64;
if ( sz > 1000000000 )
@ -195,7 +195,7 @@ namespace mongo {
if( !isFreeList )
addNewNamespaceToCatalog(ns, options.isEmpty() ? 0 : &options);
long long size = initialExtentSize(128);
long long size = Extent::initialSize(128);
{
BSONElement e = options.getField("size");
if ( e.isNumber() ) {
@ -1007,9 +1007,9 @@ namespace mongo {
return dl;
}
int followupExtentSize(int len, int lastExtentLen) {
int Extent::followupSize(int len, int lastExtentLen) {
assert( len < Extent::maxSize() );
int x = initialExtentSize(len);
int x = initialSize(len);
int y = (int) (lastExtentLen < 4000000 ? lastExtentLen * 4.0 : lastExtentLen * 1.2);
int sz = y > x ? y : x;
@ -1458,7 +1458,7 @@ namespace mongo {
also if this is an addIndex, those checks should happen before this!
*/
// This may create first file in the database.
cc().database()->allocExtent(ns, initialExtentSize(len), false);
cc().database()->allocExtent(ns, Extent::initialSize(len), false);
d = nsdetails(ns);
if ( !god )
ensureIdIndexForNewNs(ns);
@ -1525,13 +1525,13 @@ namespace mongo {
// out of space
if ( d->capped == 0 ) { // size capped doesn't grow
log(1) << "allocating new extent for " << ns << " padding:" << d->paddingFactor << " lenWHdr: " << lenWHdr << endl;
cc().database()->allocExtent(ns, followupExtentSize(lenWHdr, d->lastExtentSize), false);
cc().database()->allocExtent(ns, Extent::followupSize(lenWHdr, d->lastExtentSize), false);
loc = d->alloc(ns, lenWHdr, extentLoc);
if ( loc.isNull() ){
log() << "WARNING: alloc() failed after allocating new extent. lenWHdr: " << lenWHdr << " last extent size:" << d->lastExtentSize << "; trying again\n";
for ( int zzz=0; zzz<10 && lenWHdr > d->lastExtentSize; zzz++ ){
log() << "try #" << zzz << endl;
cc().database()->allocExtent(ns, followupExtentSize(len, d->lastExtentSize), false);
cc().database()->allocExtent(ns, Extent::followupSize(len, d->lastExtentSize), false);
loc = d->alloc(ns, lenWHdr, extentLoc);
if ( ! loc.isNull() )
break;

View File

@ -265,6 +265,16 @@ namespace mongo {
Extent* getPrevExtent() { return xprev.isNull() ? 0 : DataFileMgr::getExtent(xprev); }
static int maxSize();
/**
* @param len lengt of record we need
* @param lastRecord size of last extent which is a factor in next extent size
*/
static int followupSize(int len, int lastExtentLen);
/**
* @param len lengt of record we need
*/
static int initialSize(int len);
struct FL {
DiskLoc firstRecord;

View File

@ -25,12 +25,6 @@
#include "dbtests.h"
namespace mongo {
// here because we don't nesc. want to expose yet
int initialExtentSize(int len);
int followupExtentSize(int len, int lastExtentLen);
}
namespace PdfileTests {
namespace ScanCapped {
@ -327,9 +321,9 @@ namespace PdfileTests {
SmallFilesControl c;
// test that no matter what we start with, we always get to max extent size
for ( int obj=16; obj<BSONObjMaxUserSize; obj *= 1.3 ){
int sz = initialExtentSize( obj );
int sz = Extent::initialSize( obj );
for ( int i=0; i<100; i++ ){
sz = followupExtentSize( obj , sz );
sz = Extent::followupSize( obj , sz );
}
ASSERT_EQUALS( Extent::maxSize() , sz );
}