summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-03-14 18:58:12 -0400
committerMathias Stearn <mathias@10gen.com>2014-03-19 15:25:20 -0400
commit0147b057c2d01fc6cd418af09fbee278a877baf1 (patch)
tree9f3a2595ff85f04a7856a71dbb3fae801343e9f3
parent8492832436f2a4cb1ffc621a0e982d262c97d6f3 (diff)
downloadmongo-0147b057c2d01fc6cd418af09fbee278a877baf1.tar.gz
SERVER-12615 Fix size calculation in JSReducer::_reduce
The old calculation didn't consider the size of the numeric-string fieldnames in arrays. This error accumulated with each value added to the array. While the new calculation doesn't consider the size of the current fieldname, it is ok because it prevents the error from accumulating and we have plenty of room between the User and Internal max sizes. (cherry picked from commit 3e0aa5769dd58c727726c3397f9678d7f767b7ff)
-rw-r--r--src/mongo/db/commands/mr.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index e48249832ec..4f0001f1db4 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -183,7 +183,6 @@ namespace mongo {
// need to build the reduce args: ( key, [values] )
BSONObjBuilder reduceArgs( sizeEstimate );
boost::scoped_ptr<BSONArrayBuilder> valueBuilder;
- int sizeSoFar = 0;
unsigned n = 0;
for ( ; n<tuples.size(); n++ ) {
BSONObjIterator j(tuples[n]);
@@ -191,7 +190,6 @@ namespace mongo {
if ( n == 0 ) {
reduceArgs.append( keyE );
key = keyE.wrap();
- sizeSoFar = 5 + keyE.size();
valueBuilder.reset(new BSONArrayBuilder( reduceArgs.subarrayStart( "tuples" ) ));
}
@@ -199,13 +197,15 @@ namespace mongo {
uassert( 13070 , "value too large to reduce" , ee.size() < ( BSONObjMaxUserSize / 2 ) );
- if ( sizeSoFar + ee.size() > BSONObjMaxUserSize ) {
+ // If adding this element to the array would cause it to be too large, break. The
+ // remainder of the tuples will be processed recursively at the end of this
+ // function.
+ if ( valueBuilder->len() + ee.size() > BSONObjMaxUserSize ) {
verify( n > 1 ); // if not, inf. loop
break;
}
valueBuilder->append( ee );
- sizeSoFar += ee.size();
}
verify(valueBuilder);
valueBuilder->done();