Skip to content
Browse files

SERVER-7238 fix power of 2 allocation with documents > 8mb

  • Loading branch information...
1 parent d168d1a commit 19ecdc680e49471bd88b17024c15795a6a080137 @erh erh committed Oct 2, 2012
Showing with 11 additions and 4 deletions.
  1. +9 −3 src/mongo/db/namespace_details.cpp
  2. +2 −1 src/mongo/db/pdfile.cpp
View
12 src/mongo/db/namespace_details.cpp
@@ -753,9 +753,15 @@ namespace mongo {
if ( isUserFlagSet( Flag_UsePowerOf2Sizes ) ) {
- int x = bucket( minRecordSize );
- x = bucketSizes[x];
- return x;
+ int allocationSize = bucketSizes[ bucket( minRecordSize ) ];
+ if ( allocationSize < minRecordSize ) {
+ // if we get here, it means we're allocating more than 8mb
+ // the highest bucket is 8mb, so the above code will never return more than 8mb for allocationSize
+ // if this happens, we are going to round up to the nearest megabyte
+ fassert( 16439, bucket( minRecordSize ) == MaxBucket );
+ allocationSize = 1 + ( minRecordSize | ( ( 1 << 20 ) - 1 ) );
+ }
+ return allocationSize;
}
return static_cast<int>(minRecordSize * _paddingFactor);
View
3 src/mongo/db/pdfile.cpp
@@ -1450,7 +1450,8 @@ namespace mongo {
}
int lenWHdr = d->getRecordAllocationSize( len + Record::HeaderSize );
-
+ fassert( 16440, lenWHdr >= ( len + Record::HeaderSize ) );
+
// If the collection is capped, check if the new object will violate a unique index
// constraint before allocating space.
if (d->nIndexes &&

0 comments on commit 19ecdc6

Please sign in to comment.
Something went wrong with that request. Please try again.