summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-12-24 13:31:46 -0500
committerEliot Horowitz <eliot@10gen.com>2010-12-24 13:33:39 -0500
commit113c5e3108a4b421532f20a3fab86c12da5ba480 (patch)
tree34fe97e3727c6379cbdba09c367ac782d0cb7c59
parentefee57d51b028496e42da288ed2b7b420118ceea (diff)
downloadmongo-113c5e3108a4b421532f20a3fab86c12da5ba480.tar.gz
fix follow up extent sizing when an int overflow SERVER-2287
-rw-r--r--db/pdfile.cpp10
-rw-r--r--dbtests/pdfiletests.cpp32
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;