Skip to content

Commit

Permalink
SERVER-3766 Adjust maxDiskLoc to prevent assertion when creating a re…
Browse files Browse the repository at this point in the history
…verse direction BtreeCursor. Adjust minDiskLoc for consistency.
  • Loading branch information
astaple committed Nov 20, 2012
1 parent a273613 commit 0626526
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
10 changes: 10 additions & 0 deletions jstests/minmax.js
Expand Up @@ -42,3 +42,13 @@ assert.throws( function() { t.find().min( { b: 1 } ).max( { a: 1, b: 2 } ).hint(
assert.throws( function() { t.find().min( { a: 1 } ).hint( { $natural: 1 } ).toArray() } );
assert.throws( function() { t.find().max( { a: 1 } ).hint( { $natural: 1 } ).toArray() } );

// Reverse direction scan of the a:1 index between a:6 (inclusive) and a:3 (exclusive).
t.drop();
t.ensureIndex( { a:1 } );
for( i = 0; i < 10; ++i ) {
t.save( { _id:i, a:i } );
}
if ( 0 ) { // SERVER-3766
reverseResult = t.find().min( { a:6 } ).max( { a:3 } ).sort( { a:-1 } ).hint( { a:1 } ).toArray();
assert.eq( [ { _id:6, a:6 }, { _id:5, a:5 }, { _id:4, a:4 } ], reverseResult );
}
17 changes: 14 additions & 3 deletions src/mongo/db/diskloc.h
Expand Up @@ -48,7 +48,11 @@ namespace mongo {
enum SentinelValues {
/* note NullOfs is different. todo clean up. see refs to NullOfs in code - use is valid but outside DiskLoc context so confusing as-is. */
NullOfs = -1,
MaxFiles=16000 // thus a limit of about 32TB of data per db

// Caps the number of files that may be allocated in a database, allowing about 32TB of
// data per db. Note that the DiskLoc and DiskLoc56Bit types supports more files than
// this value, as does the storage format.
MaxFiles=16000
};

DiskLoc(int a, int Ofs) : _a(a), ofs(Ofs) { }
Expand Down Expand Up @@ -154,7 +158,14 @@ namespace mongo {
};
#pragma pack()

const DiskLoc minDiskLoc(0, 1);
const DiskLoc maxDiskLoc(0x7fffffff, 0x7fffffff);
// Minimum allowed DiskLoc. No Record may begin at this location because file and extent
// headers must precede Records in a file.
const DiskLoc minDiskLoc(0, 0);

// Maximum allowed DiskLoc. Note that only three bytes are used to represent the file number
// for consistency with the v1 index DiskLoc storage format, which uses only 7 bytes total.
// No Record may begin at this location because the minimum size of a Record is larger than one
// byte.
const DiskLoc maxDiskLoc(0x00ffffff, 0x7fffffff);

} // namespace mongo
26 changes: 26 additions & 0 deletions src/mongo/dbtests/cursortests.cpp
Expand Up @@ -532,6 +532,31 @@ namespace CursorTests {
}
}
};

/** Test iteration of a reverse direction btree cursor between start and end keys. */
class ReverseDirectionStartEndKeys : public Base {
public:
void run() {
_c.dropCollection( ns() );
_c.ensureIndex( ns(), BSON( "a" << 1 ) );
// Add documents a:4 and a:5
_c.insert( ns(), BSON( "a" << 4 ) );
_c.insert( ns(), BSON( "a" << 5 ) );
Client::ReadContext ctx( ns() );
scoped_ptr<Cursor> cursor( BtreeCursor::make( nsdetails( ns() ),
nsdetails( ns() )->idx( 1 ),
/* startKey */ BSON( "" << 5 ),
/* endKey */ BSON( "" << 4 ),
/* endKeyInclusive */ true,
/* direction */ -1 ) );
// Check that the iterator produces the expected results, in the expected order.
ASSERT( cursor->ok() );
ASSERT_EQUALS( 5, cursor->current()[ "a" ].Int() );
ASSERT( cursor->advance() );
ASSERT_EQUALS( 4, cursor->current()[ "a" ].Int() );
ASSERT( !cursor->advance() );
}
};

} // namespace BtreeCursor

Expand Down Expand Up @@ -769,6 +794,7 @@ namespace CursorTests {
add<BtreeCursor::MatcherRequiredTwoConstraintsDifferentFields>();
add<BtreeCursor::TypeBracketedUpperBoundWithoutMatcher>();
add<BtreeCursor::TypeBracketedLowerBoundWithoutMatcher>();
add<BtreeCursor::ReverseDirectionStartEndKeys>();
add<ClientCursor::HandleDelete>();
add<ClientCursor::AboutToDelete>();
add<ClientCursor::AboutToDeleteDuplicate>();
Expand Down

0 comments on commit 0626526

Please sign in to comment.