1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// repair with --directoryperdb
var baseName = "jstests_disk_repair2";
function check() {
files = listFiles( dbpath );
for( f in files ) {
assert( ! new RegExp( "^" + dbpath + "backup_" ).test( files[ f ].name ),
"backup dir " + files[ f ].name + " in dbpath" );
}
assert.eq.automsg( "1", "db[ baseName ].count()" );
}
port = allocatePorts( 1 )[ 0 ];
dbpath = MongoRunner.dataPath + baseName + "/";
repairpath = dbpath + "repairDir/";
longDBName = Array(61).join('a');
longRepairPath = dbpath + Array(61).join('b') + '/';
resetDbpath( dbpath );
resetDbpath( repairpath );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles:true} ) );
//Check that repair files exist in the repair directory, and nothing else
db.adminCommand( { fsync : 1 } );
files = listFiles( repairpath + "/backup_repairDatabase_0/" + baseName );
var fileCount = 0;
for( f in files ) {
print( files[ f ].name );
if ( files[ f ].isDirectory )
continue;
fileCount += 1;
assert( /\.bak$/.test( files[ f ].name ),
"In database repair directory, found unexpected file: " + files[ f ].name );
}
assert( fileCount > 0, "Expected more than zero nondirectory files in the database directory" );
check();
MongoRunner.stopMongod( port );
resetDbpath( repairpath );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
check();
MongoRunner.stopMongod( port );
//Test long database names
resetDbpath( repairpath );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( longDBName );
assert.writeOK(db[ baseName ].save( {} ));
assert.commandWorked( db.runCommand( {repairDatabase:1} ) );
MongoRunner.stopMongod( port );
//Test long repairPath
resetDbpath( longRepairPath )
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", longRepairPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( longDBName );
assert.commandWorked( db.runCommand( {repairDatabase:1, backupOriginalFiles: true} ) );
check();
MongoRunner.stopMongod( port );
//Test database name and repairPath with --repair
resetDbpath( longRepairPath )
m = startMongoProgram( "mongod", "--repair", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", longRepairPath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( longDBName );
check();
MongoRunner.stopMongod( port );
resetDbpath( repairpath );
runMongoProgram( "mongod", "--repair", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--repairpath", repairpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
check();
MongoRunner.stopMongod( port );
resetDbpath( repairpath );
runMongoProgram( "mongod", "--repair", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
check();
|