Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-3803

btree cursor check location / key at check is invalid for v0 index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.1.1
    • Affects Version/s: None
    • Component/s: Index Maintenance
    • Labels:
      None
    • ALL

      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() );
      +}
      

            Assignee:
            aaron Aaron Staple
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: