From 086d64580da33cfabc27ba2f5a0ea6323c730cb2 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 9 Feb 2010 13:46:30 -0800 Subject: [PATCH] SERVER-606 add background indexing unit test --- jstests/index11.js | 89 +++++++++++++++++++++++++++++++++ mongo.xcodeproj/project.pbxproj | 2 + 2 files changed, 91 insertions(+) create mode 100644 jstests/index11.js diff --git a/jstests/index11.js b/jstests/index11.js new file mode 100644 index 00000000000..bc4e757cf1c --- /dev/null +++ b/jstests/index11.js @@ -0,0 +1,89 @@ +// Test background index creation + +parallel = function() { + return db[ baseName + "_parallelStatus" ]; +} + +resetParallel = function() { + parallel().drop(); +} + +doParallel = function( work ) { + resetParallel(); + startMongoProgramNoConnect( "mongo", "--eval", work + "; db." + baseName + "_parallelStatus.save( {done:1} );" ); +} + +doneParallel = function() { + return !!parallel().findOne(); +} + +waitParallel = function() { + assert.soon( function() { return doneParallel(); }, "parallel did not finish in time", 300000, 1000 ); +} + +size = 500000; +while( 1 ) { // if indexing finishes before we can run checks, try indexing w/ more data + print( "size: " + size ); + baseName = "jstests_index11"; + fullName = "db." + baseName; + t = db[ baseName ]; + t.drop(); + + db.eval( function( size ) { + for( i = 0; i < size; ++i ) { + db.jstests_index11.save( {i:i} ); + } + }, + size ); + assert.eq( size, t.count() ); + + doParallel( fullName + ".ensureIndex( {i:1}, {background:true} )" ); + try { + // wait for indexing to start + assert.soon( function() { return 2 == db.system.indexes.count( {ns:"test."+baseName} ) }, 30000, 50 ); + assert.eq( size, t.count() ); + assert.eq( 100, t.findOne( {i:100} ).i ); + q = t.find(); + for( i = 0; i < 120; ++i ) { // getmore + q.next(); + assert( q.hasNext(), "no next" ); + } + assert.eq( "BasicCursor", t.find( {i:100} ).explain().cursor, "used btree cursor" ); + t.remove( {i:40} ); + t.update( {i:10}, {i:-10} ); + id = t.find().hint( {$natural:-1} )._id; + t.update( {_id:id}, {i:-2} ); + t.save( {i:-50} ); + t.save( {i:size+2} ); + assert( !db.getLastError() ); + t.ensureIndex( {i:1} ); + printjson( db.getLastError() ); + assert( db.getLastError() ); + assert.eq( size + 1, t.count() ); + assert( !db.getLastError() ); + t.dropIndex( {i:1} ); + printjson( db.getLastError() ); + assert( db.getLastError() ); + } catch( e ) { + // only a failure if we're still indexing + // wait for parallel status to update to reflect indexing status + sleep( 1000 ); + if ( !doneParallel() ) { + throw e; + } + } + if ( !doneParallel() ) { + break; + } + print( "indexing finished too soon, retrying..." ); + size *= 2; + assert( size < 5000000, "unable to run checks in parallel with index creation" ); +} + +waitParallel(); +assert.eq( "BtreeCursor i_1", t.find( {i:100} ).explain().cursor ); +assert.eq( 1, t.count( {i:-10} ) ); +assert.eq( 1, t.count( {i:-2} ) ); +assert.eq( 1, t.count( {i:-50} ) ); +assert.eq( 1, t.count( {i:size+2} ) ); +assert.eq( 0, t.count( {i:40} ) ); \ No newline at end of file diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index aa6574cfdcf..3702c4f8af6 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -33,6 +33,7 @@ 931186FB0F8535FF00A6DC44 /* bridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bridge.cpp; sourceTree = ""; }; 931979810FBC67FB001FE537 /* utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utils.cpp; sourceTree = ""; }; 931A027A0F58AA4400147C0E /* jsobjmanipulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsobjmanipulator.h; sourceTree = ""; }; + 9323308F1121E5B100712706 /* index11.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = index11.js; sourceTree = ""; }; 93278F570F72D32900844664 /* gridfs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gridfs.cpp; sourceTree = ""; }; 93278F580F72D32900844664 /* gridfs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = gridfs.h; sourceTree = ""; }; 93278F610F72D39400844664 /* cursors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cursors.cpp; sourceTree = ""; }; @@ -735,6 +736,7 @@ 934BEB9A10DFFA9600178102 /* jstests */ = { isa = PBXGroup; children = ( + 9323308F1121E5B100712706 /* index11.js */, 93D5A8921117A1380052C931 /* regex6.js */, 938E639A110FC66900A8760A /* auth */, 93BCE41810F3AF1B00FA139B /* capped2.js */,