Skip to content

Commit

Permalink
SERVER-2650 prevent too small extents
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple authored and erh committed Mar 1, 2011
1 parent ad4abbc commit af4f059
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions db/pdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ namespace mongo {
while ( size > 0 ) {
int max = MongoDataFile::maxSize() - DataFileHeader::HeaderSize;
int desiredExtentSize = (int) (size > max ? max : size);
if ( desiredExtentSize < Extent::minSize() ) {
desiredExtentSize = Extent::minSize();
}
desiredExtentSize &= 0xffffff00;
Extent *e = database->allocExtent( ns, desiredExtentSize, newCapped );
size -= e->length;
}
Expand Down Expand Up @@ -435,11 +439,11 @@ namespace mongo {

Extent* MongoDataFile::createExtent(const char *ns, int approxSize, bool newCapped, int loops) {
massert( 10357 , "shutdown in progress", ! inShutdown() );
massert( 10358 , "bad new extent size", approxSize >= 0 && approxSize <= Extent::maxSize() );
massert( 10358 , "bad new extent size", approxSize >= Extent::minSize() && approxSize <= Extent::maxSize() );
massert( 10359 , "header==0 on new extent: 32 bit mmap space exceeded?", header() ); // null if file open failed
int ExtentSize = approxSize <= header()->unusedLength ? approxSize : header()->unusedLength;
DiskLoc loc;
if ( ExtentSize <= 0 ) {
if ( ExtentSize < Extent::minSize() ) {
/* not there could be a lot of looping here is db just started and
no files are open yet. we might want to do something about that. */
if ( loops > 8 ) {
Expand Down
1 change: 1 addition & 0 deletions db/pdfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ namespace mongo {
Extent* getPrevExtent() { return xprev.isNull() ? 0 : DataFileMgr::getExtent(xprev); }

static int maxSize();
static int minSize() { return 0x100; }
/**
* @param len lengt of record we need
* @param lastRecord size of last extent which is a factor in next extent size
Expand Down
11 changes: 11 additions & 0 deletions jstests/slowNightly/newcollection2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Alocate collection forcing just a small size remainder in 2nd extent

port = allocatePorts( 1 )[ 0 ]
var baseName = "jstests_disk_newcollection2";
var m = startMongod( "--noprealloc", "--smallfiles", "--port", port, "--dbpath", "/data/db/" + baseName );
db = m.getDB( "test" );

db.createCollection( baseName, {size:0x1FFC0000-0x10-8192} );
var v = db[ baseName ].validate();
printjson( v );
assert( v.valid );

0 comments on commit af4f059

Please sign in to comment.