[SERVER-3803] btree cursor check location / key at check is invalid for v0 index Created: 11/Sep/11  Updated: 11/Jul/16  Resolved: 01/Mar/12

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: 2.1.1

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Aaron Staple
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-4575 two somewhat redundant procedures for... Closed
Operating System: ALL
Participants:

 Description   

It looks like BtreeCursorImpl::keyAt() checks a v1 index sentinel value for n but not the corresponding (and different) v0 index sentinel value. This causes scary looking assertions in DEBUG mode, but fortunately everything ends up working fine in a normal build. Test below only fails in DEBUG mode.

diff --git a/db/btreecursor.cpp b/db/btreecursor.cpp
index f39d5bb..f81c2ec 100644
--- a/db/btreecursor.cpp
+++ b/db/btreecursor.cpp
@@ -52,7 +52,7 @@ namespace mongo {
             assert( !bucket.isNull() );
             const BtreeBucket<V> *b = bucket.btree<V>();
             int n = b->getN();
-            if( n == 0xffff ) { 
+            if( n == 0xffff || n == -1 ) { 
                 throw UserException(15850, "keyAt bucket deleted");
             }
             dassert( n >= 0 && n < 10000 );
diff --git a/jstests/removea.js b/jstests/removea.js
new file mode 100644
index 0000000..2ed3d60
--- /dev/null
+++ b/jstests/removea.js
@@ -0,0 +1,19 @@
+// Test removal of a substantial proportion of inserted elements.
+
+t = db.jstests_removea;
+t.drop();
+
+Random.setRandomSeed(1);
+
+for( v = 0; v < 2; ++v ) {
+    t.ensureIndex({a:1}, {v:v});
+    for( i = 0; i < 10000; ++i ) {
+        t.save( {a:i} );
+    }
+    toDrop = [];
+    for( i = 0; i < 10000; ++i ) {
+        toDrop.push( Random.randInt(10000) );
+    }
+    t.remove( {a:{$in:toDrop}} );
+    assert( !db.getLastError() );
+}



 Comments   
Comment by auto [ 01/Mar/12 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-3803 check proper n sentinel value for deallocated bucket in v0 index
Branch: master
https://github.com/mongodb/mongo/commit/b974a8e8229440c1cb1cf06061f1cc4df0b3c9c4

Generated at Thu Feb 08 03:04:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.