Skip to content

Commit

Permalink
SERVER-2340: undoing until we decide on feature
Browse files Browse the repository at this point in the history
  • Loading branch information
agirbal committed Oct 17, 2011
1 parent 20a1c7a commit 2a8522c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 57 deletions.
37 changes: 15 additions & 22 deletions db/commands/mr.cpp
Expand Up @@ -142,10 +142,6 @@ namespace mongo {

if ( finalizer ) {
res = finalizer->finalize( res );
if (res.getField("value").isNull()) {
// this means to throw away result
return BSONObj();
}
}

return res;
Expand Down Expand Up @@ -408,9 +404,6 @@ namespace mongo {
BSONObj key = i->first;
BSONList& all = i->second;

// may not be a value due to finalize
if (all.size() == 0)
continue;
assert( all.size() == 1 );

BSONObjIterator vi( all[0] );
Expand Down Expand Up @@ -507,9 +500,7 @@ namespace mongo {
values.clear();
values.push_back( temp );
values.push_back( old );
BSONObj res = _config.reducer->finalReduce( values , _config.finalizer.get() );
if (!res.isEmpty())
Helpers::upsert( _config.finalLong , res );
Helpers::upsert( _config.finalLong , _config.reducer->finalReduce( values , _config.finalizer.get() ) );
}
else {
Helpers::upsert( _config.finalLong , temp );
Expand Down Expand Up @@ -654,8 +645,7 @@ namespace mongo {
return;

BSONObj res = _config.reducer->finalReduce( values , _config.finalizer.get() );
if (!res.isEmpty())
insert( _config.tempLong , res );
insert( _config.tempLong , res );
}

BSONObj _nativeToTemp( const BSONObj& args, void* data ) {
Expand Down Expand Up @@ -704,11 +694,10 @@ namespace mongo {
assert( all.size() == 1 );

BSONObj res = _config.finalizer->finalize( all[0] );

all.clear();
if ( !res.getField("value").isNull() ) {
all.push_back( res );
size += res.objsize();
}
all.push_back( res );
size += res.objsize();
}
_size = size;
}
Expand Down Expand Up @@ -1130,6 +1119,12 @@ namespace mongo {
if ( config.verbose ) result.append( "timing" , timingBuilder.obj() );
result.append( "counts" , countsBuilder.obj() );

if ( finalCount == 0 && shouldHaveData ) {
result.append( "cmd" , cmd );
errmsg = "there were emits but no data!";
return false;
}

}
// TODO: The error handling code for queries is v. fragile,
// *requires* rethrow AssertionExceptions - should probably fix.
Expand Down Expand Up @@ -1250,12 +1245,10 @@ namespace mongo {
}

BSONObj res = config.reducer->finalReduce( values , config.finalizer.get());
if (!res.isEmpty()) {
if (state.isOnDisk())
state.insertToInc(res);
else
state.emit(res);
}
if (state.isOnDisk())
state.insertToInc(res);
else
state.emit(res);
values.clear();
if (!t.isEmpty())
values.push_back( t );
Expand Down
24 changes: 0 additions & 24 deletions jstests/mr2.js
Expand Up @@ -65,27 +65,3 @@ res.drop();

assert( ! ( "result" in res ) , "B4" )

var final2 = function(key, res) {
res.avg = res.totalSize / res.num;
if (res.avg < 18) return null;
return res;
}
res = t.mapReduce( m , r , { finalize : final2 , out : "mr2_out" } );
printjson( res )
x = reformat( res );
assert( x.a == undefined , "C1" );
assert( x.b == undefined , "C2" );
assert.eq( 18 , x.c.avg , "C3" );
res.drop();

var final2 = function(key, res) {
return null;
}
res = t.mapReduce( m , r , { finalize : final2 , out : { inline : 1 } } );
printjson( res )
x = reformat( res );
assert( x.a == undefined , "D1" );
assert( x.b == undefined , "D2" );
assert( x.c == undefined , "D3" );
res.drop();

16 changes: 7 additions & 9 deletions s/commands_public.cpp
Expand Up @@ -1202,16 +1202,14 @@ namespace mongo {
}

BSONObj final = config.reducer->finalReduce(values, config.finalizer.get());
if (!final.isEmpty()) {
if (config.outType == mr_shard::Config::MERGE) {
BSONObj id = final["_id"].wrap();
s->updateSharded(conf, outns.c_str(), id, final, UpdateOption_Upsert, true);
} else {
// insert into temp collection, but using final collection's shard chunks
s->insertSharded(conf, tempns.c_str(), final, 0, true, outns.c_str());
}
++finalCount;
if (config.outType == mr_shard::Config::MERGE) {
BSONObj id = final["_id"].wrap();
s->updateSharded(conf, outns.c_str(), id, final, UpdateOption_Upsert, true);
} else {
// insert into temp collection, but using final collection's shard chunks
s->insertSharded(conf, tempns.c_str(), final, 0, true, outns.c_str());
}
++finalCount;
values.clear();
if (!t.isEmpty()) {
values.push_back( t );
Expand Down
2 changes: 0 additions & 2 deletions s/mr_shard.cpp
Expand Up @@ -117,8 +117,6 @@ namespace mongo {

if ( finalizer ) {
res = finalizer->finalize( res );
if (res.getField("value").isNull())
return BSONObj();
}

return res;
Expand Down

0 comments on commit 2a8522c

Please sign in to comment.