Skip to content

Commit

Permalink
Revert "SERVER-4781 Allowed setting over an object whose path is only…
Browse files Browse the repository at this point in the history
… partially constructed."

This reverts commit 77bf5af.
  • Loading branch information
Alberto Lerner committed Oct 15, 2012
1 parent b525bc6 commit d9791cc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
16 changes: 4 additions & 12 deletions src/mongo/db/ops/update_internal.cpp
Expand Up @@ -802,6 +802,9 @@ namespace mongo {
switch ( cmp ) {

case LEFT_SUBFIELD: { // Mod is embedded under this element
uassert( 10145,
str::stream() << "LEFT_SUBFIELD only supports Object: " << field
<< " not: " << e.type() , e.type() == Object || e.type() == Array );
if ( onedownseen.count( e.fieldName() ) == 0 ) {
onedownseen.insert( e.fieldName() );
if ( e.type() == Object ) {
Expand All @@ -810,23 +813,12 @@ namespace mongo {
createNewObjFromMods( nr.str() , bb , e.Obj() );
bb.done();
}
else if ( e.type() == Array ) {
else {
BSONArrayBuilder ba( builder.subarrayStart( e.fieldName() ) );
stringstream nr; nr << root << e.fieldName() << ".";
createNewArrayFromMods( nr.str() , ba , BSONArray( e.embeddedObject() ) );
ba.done();
}
else {
// We have a sub-object being added to a field that was not of a
// complex type (ie, it was a scalar). For instance, we're $set-ing
// 'a.b' to be 1, when the current value of 'a' is, say, null. This
// addition will force the field to change to such complex type,
// effectively removing what was there before.
BSONObjBuilder be( builder.subobjStart( e.fieldName() ) );
stringstream nr; nr << root << e.fieldName() << ".";
createNewObjFromMods( nr.str() , be , BSONObj() );
be.done();
}
// inc both as we handled both
e = es.next();
m++;
Expand Down
29 changes: 0 additions & 29 deletions src/mongo/dbtests/repltests.cpp
Expand Up @@ -1114,34 +1114,6 @@ namespace ReplTests {
}
};

//
// replay cases
//

class ReplaySetPreexistingNoOpPull : public Base {
public:
void doIt() const {
client()->update( ns(), BSONObj(), fromjson( "{$unset:{z:1}}" ));

// This is logged as {$set:{'a.b':[]},$set:{z:1}}, which might not be
// replayable against future versions of a document (here {_id:0,a:1,z:1}) due
// to SERVER-4781. As a result the $set:{z:1} will not be replayed in such
// cases (and also an exception may abort replication). If this were instead
// logged as {$set:{z:1}}, SERVER-4781 would not be triggered.
client()->update( ns(), BSONObj(), fromjson( "{$pull:{'a.b':1}, $set:{z:1}}" ) );
client()->update( ns(), BSONObj(), fromjson( "{$set:{a:1}}" ) );
}
using ReplTests::Base::check;
void check() const {
ASSERT_EQUALS( 1, count() );
check( fromjson( "{_id:0,a:1,z:1}" ), one( fromjson("{'_id':0}") ) );
}
void reset() const {
deleteAll( ns() );
insert( fromjson( "{'_id':0,a:{b:[]},z:1}" ) );
}
};

} // namespace Idempotence

class DeleteOpIsIdBased : public Base {
Expand Down Expand Up @@ -1562,7 +1534,6 @@ namespace ReplTests {
add< Idempotence::IndexedSingletonNoRename >();
add< Idempotence::AddToSetEmptyMissing >();
add< Idempotence::AddToSetWithDollarSigns >();
add< Idempotence::ReplaySetPreexistingNoOpPull >();
add< DeleteOpIsIdBased >();
add< DatabaseIgnorerBasic >();
add< DatabaseIgnorerUpdate >();
Expand Down
6 changes: 3 additions & 3 deletions src/mongo/dbtests/updatetests.cpp
Expand Up @@ -307,7 +307,7 @@ namespace UpdateTests {
void run() {
client().insert( ns(), fromjson( "{'_id':0,a:1}" ) );
client().update( ns(), Query(), BSON( "$set" << BSON( "a.b" << 1 ) ) );
ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:1}}" ) ) == 0 );
ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:1}" ) ) == 0 );
}
};

Expand Down Expand Up @@ -428,9 +428,9 @@ namespace UpdateTests {
class SetEncapsulationConflictsWithExistingType : public SetBase {
public:
void run() {
client().insert( ns(), fromjson( "{'_id':0,a:{b:4},d:1}" ) );
client().insert( ns(), fromjson( "{'_id':0,a:{b:4}}" ) );
client().update( ns(), Query(), BSON( "$set" << BSON( "a.b.c" << 4.0 ) ) );
ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:{c:4}},d:1}" ) ) == 0 );
ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,a:{b:4}}" ) ) == 0 );
}
};

Expand Down

0 comments on commit d9791cc

Please sign in to comment.