2
* Kill mongod during a background index build and ensure that the bad index
3
* can be dropped on restart.
6
load( "jstests/libs/slow_weekly_util.js" )
8
testServer = new SlowWeeklyMongod( "indexbg_dur" )
9
db = testServer.getDB( "test" );
11
function countFields( x ) {
21
print( "size: " + size );
23
var testname = "index_build";
24
var path = "/data/db/" + testname+"_dur";
25
conn = startMongodEmpty("--port", 30001, "--dbpath", path, "--dur", "--smallfiles", "--durOptions", 8);
26
t = conn.getDB( testname ).getCollection( testname );
28
for( var i = 0; i < size; ++i ) {
31
t.getDB().getLastError();
32
x = startMongoProgramNoConnect( "mongo", "--eval", "db.getSisterDB( '" + testname + "' )." + testname + ".ensureIndex( {i:1}, {background:true} );", conn.host );
34
stopMongod( 30001, /* signal */ 9 );
37
conn = startMongodNoReset("--port", 30001, "--dbpath", path, "--dur", "--smallfiles", "--durOptions", 8);
38
t = conn.getDB( testname ).getCollection( testname );
40
var statsSize = countFields( t.stats().indexSizes );
41
var nsSize = conn.getDB( testname ).system.indexes.count( {ns:testname+'.'+testname} );
43
// If index build completed before the kill, try again with more data.
44
if ( !( statsSize == 1 && nsSize == 2 ) ) {
45
print( "statsSize: " + statsSize + ", nsSize: " + nsSize + ", retrying with more data" );
51
assert.eq( "index not found", t.dropIndex( "i_1" ).errmsg );
53
var statsSize = countFields( t.stats().indexSizes );
54
var nsSize = conn.getDB( testname ).system.indexes.count( {ns:testname+'.'+testname} );
56
assert.eq( statsSize, nsSize );
57
assert( t.validate().valid );
58
// TODO check that index namespace is cleaned up as well once that is implemented
60
t.ensureIndex( {i:1} );
61
var statsSize = countFields( t.stats().indexSizes );
62
var nsSize = conn.getDB( testname ).system.indexes.count( {ns:testname+'.'+testname} );
64
assert.eq( 2, statsSize );
65
assert.eq( 2, nsSize );
67
exp = t.find( {i:20} ).explain();
68
assert.eq( 1, exp.n );
69
assert.eq( 'BtreeCursor i_1', exp.cursor );