[SERVER-6980] Record::getPrev() does not handle empty extents properly Created: 09/Sep/12  Updated: 11/Jul/16  Resolved: 29/Nov/12

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: 2.3.2

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

Operating System: ALL
Participants:

 Description   

Reverse natural iteration of a non capped or capped collection will abort when the first empty extent is encountered, because Record::getPrev() does not skip over empty extents.

    inline DiskLoc Record::getPrev(const DiskLoc& myLoc) {
        _accessing();
        if ( _prevOfs != DiskLoc::NullOfs )
            return DiskLoc(myLoc.a(), _prevOfs);
        Extent *e = myExtent(myLoc);
        if ( e->xprev.isNull() )
            return DiskLoc();
        return e->xprev.ext()->lastRecord;
    }

Test

c = db.c;
c.drop();
 
a = 0;
c.save( { a:a++ } );
 
big = new Array( 1024*1024 ).toString();
// Save 3 extents of data.                                                                               
while( c.stats().numExtents < 3 ) {
    c.save( { a:a++, b:big } );
}
 
savedCount = c.count();
assert.gt( savedCount, 2 );
 
// Remove all but the first and last documents, with the expectation that the first doc is in the        
// first extent and the last in the last extent.  This leaves the middle extent empty.                   
c.remove( { a:{ $gt:0, $lt:a-1 } } );
assert.eq( 2, c.count() );
assert.eq( 2, c.find().sort( { $natural:1 } ).itcount() );
// Check that reverse iteration properly iterates past the empty middle extent.
// Currently it stops at the empty extent (and only sees one document).
assert.eq( 2, c.find().sort( { $natural:-1 } ).itcount() );



 Comments   
Comment by Shaun Verch [ 29/Nov/12 ]

Written a jstest. Unit test should be written after the test framework is changed.

Comment by auto [ 29/Nov/12 ]

Author:

{u'date': u'2012-11-28T23:27:05Z', u'email': u'shaun.verch@10gen.com', u'name': u'Shaun Verch'}

Message: SERVER-6980 Skip empty extents in Record::getPrev
Branch: master
https://github.com/mongodb/mongo/commit/9c153e6ab96ed783f9b185fa34e0e6595baf3478

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