Permalink
Browse files

more aggressive about checking for index moves in multi-update SERVER…

…-1060
  • Loading branch information...
1 parent aa82a78 commit 4002e942bd96c55be54fda788eb680e8938a8533 @erh erh committed Apr 28, 2010
Showing with 32 additions and 6 deletions.
  1. +7 −6 db/update.cpp
  2. +25 −0 jstests/update_multi3.js
View
@@ -800,12 +800,8 @@ namespace mongo {
continue;
}
- if ( modsIsIndexed && multi ){
- c->noteLocation();
- }
-
const BSONObj& onDisk = loc.obj();
-
+
ModSet * useMods = mods.get();
bool forceRewrite = false;
@@ -819,6 +815,11 @@ namespace mongo {
auto_ptr<ModSetState> mss = useMods->prepare( onDisk );
+ bool indexHack = multi && ( modsIsIndexed || ! mss->canApplyInPlace() );
+
+ if ( indexHack )
+ c->noteLocation();
+
if ( modsIsIndexed <= 0 && mss->canApplyInPlace() ){
mss->applyModsInPlace();// const_cast<BSONObj&>(onDisk) );
@@ -862,7 +863,7 @@ namespace mongo {
numModded++;
if ( ! multi )
break;
- if ( multi && modsIsIndexed )
+ if ( indexHack )
c->checkLocation();
continue;
}
@@ -0,0 +1,25 @@
+
+t = db.update_multi3;
+
+function test( useIndex ){
+ t.drop();
+
+ if ( useIndex )
+ t.ensureIndex({k:1})
+
+ for (i=0; i<10; i++) {
+ t.save({ _id : i , k: 'x', a: []});
+ }
+
+ t.update({k: 'x'}, {$push: {a: 'y'}}, false, true);
+
+ t.find( { k : "x" } ).forEach(
+ function(z){
+ assert.eq( [ "y" ] , z.a , "useIndex: " + useIndex )
+ }
+ );
+
+}
+
+test( false )
+test( true )

0 comments on commit 4002e94

Please sign in to comment.