diff options
-rw-r--r-- | db/pdfile.cpp | 10 | ||||
-rw-r--r-- | dbtests/pdfiletests.cpp | 32 |
2 files changed, 39 insertions, 3 deletions
diff --git a/db/pdfile.cpp b/db/pdfile.cpp index 216f21a1789..ec4e55ac882 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -970,10 +970,14 @@ namespace mongo { int y = (int) (lastExtentLen < 4000000 ? lastExtentLen * 4.0 : lastExtentLen * 1.2); int sz = y > x ? y : x; - if ( sz < lastExtentLen ) - sz = lastExtentLen; - else if ( sz > Extent::maxSize() ) + if ( sz < lastExtentLen ){ + // this means there was an int overflow + // so we should turn it into maxSize sz = Extent::maxSize(); + } + else if ( sz > Extent::maxSize() ){ + sz = Extent::maxSize(); + } sz = ((int)sz) & 0xffffff00; assert( sz > len ); diff --git a/dbtests/pdfiletests.cpp b/dbtests/pdfiletests.cpp index 7e92783d9e8..88fd5421352 100644 --- a/dbtests/pdfiletests.cpp +++ b/dbtests/pdfiletests.cpp @@ -25,6 +25,12 @@ #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 { @@ -301,6 +307,31 @@ namespace PdfileTests { } }; } // namespace Insert + + class ExtentSizing { + public: + struct SmallFilesControl { + SmallFilesControl(){ + old = cmdLine.smallfiles; + cmdLine.smallfiles = false; + } + ~SmallFilesControl(){ + cmdLine.smallfiles = old; + } + bool old; + }; + void run(){ + 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 ); + for ( int i=0; i<100; i++ ){ + sz = followupExtentSize( obj , sz ); + } + ASSERT_EQUALS( Extent::maxSize() , sz ); + } + } + }; class All : public Suite { public: @@ -321,6 +352,7 @@ namespace PdfileTests { add< ScanCapped::FirstInExtent >(); add< ScanCapped::LastInExtent >(); add< Insert::UpdateDate >(); + add< ExtentSizing >(); } } myall; |