summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2011-03-01 12:07:56 -0800
committerEliot Horowitz <eliot@10gen.com>2011-03-01 15:56:24 -0500
commitaf4f0597fd0f7738b8e4923abc804567826b0c2e (patch)
treedc67fd2197fe96584c77a9557b34823c2f46c546
parentad4abbc55ba8a29d4227f74299b8f398cf835b6e (diff)
downloadmongo-af4f0597fd0f7738b8e4923abc804567826b0c2e.tar.gz
SERVER-2650 prevent too small extents
-rw-r--r--db/pdfile.cpp8
-rw-r--r--db/pdfile.h1
-rw-r--r--jstests/slowNightly/newcollection2.js11
3 files changed, 18 insertions, 2 deletions
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index cae1381fc69..5f3cd9d9b9e 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -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;
}
@@ -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 ) {
diff --git a/db/pdfile.h b/db/pdfile.h
index b173bba1e99..fb68728e2f4 100644
--- a/db/pdfile.h
+++ b/db/pdfile.h
@@ -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
diff --git a/jstests/slowNightly/newcollection2.js b/jstests/slowNightly/newcollection2.js
new file mode 100644
index 00000000000..6bf24952c36
--- /dev/null
+++ b/jstests/slowNightly/newcollection2.js
@@ -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 );