summaryrefslogtreecommitdiff
path: root/jstests/disk/directoryperdb.js
blob: c29dea0cf9737069bbb061891d44c34a9262d329 (plain)
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
var baseDir = "jstests_disk_directoryper";
var baseName = "directoryperdb"
port = allocatePorts( 1 )[ 0 ];
dbpath = "/data/db/" + baseDir + "/";

var m = startMongod( "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
db[ baseName ].save( {} );
assert.eq( 1, db[ baseName ].count() , "A : " + tojson( db[baseName].find().toArray() ) );

checkDir = function( dir ) {
    db.adminCommand( {fsync:1} );
    files = listFiles( dir );
    found = false;
    for( f in files ) {
        if ( new RegExp( baseName ).test( files[ f ].name ) ) {
            found = true;
            assert( files[ f ].isDirectory, "file not directory" );
        }
    }
    assert( found, "no directory" );

    files = listFiles( dir + baseName );
    for( f in files ) {
        if ( files[f].isDirectory )
            continue;
        assert( new RegExp( baseName + "/" + baseName + "." ).test( files[ f ].name ) , "B dir:" + dir + " f: " + f );
    }
}
checkDir( dbpath );

// file iterator
assert( m.getDBs().totalSize > 0, "bad size calc" );

// repair
db.runCommand( {repairDatabase:1, backupOriginalFiles:true} );
checkDir( dbpath );
files = listFiles( dbpath );
for( f in files ) {
    if ( new RegExp( "^" + dbpath + "backup_" ).test( files[ f ].name ) ) {
        backupDir = files[ f ].name + "/";
    }
}
checkDir( backupDir );
assert.eq( 1, db[ baseName ].count() , "C" );

// tool test
stopMongod( port );

externalPath = "/data/db/" + baseDir + "_external/";

runMongoProgram( "mongodump", "--dbpath", dbpath, "--directoryperdb", "--out", externalPath );
resetDbpath( dbpath );
runMongoProgram( "mongorestore", "--dbpath", dbpath, "--directoryperdb", "--dir", externalPath );
m = startMongoProgram( "mongod", "--directoryperdb", "--port", port, "--dbpath", dbpath, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
db = m.getDB( baseName );
checkDir( dbpath );
assert.eq( 1, db[ baseName ].count() , "C" );
assert( m.getDBs().totalSize > 0, "bad size calc" );

// drop db test
db.dropDatabase();
files = listFiles( dbpath );
files.forEach( function( f ) { assert( !new RegExp( baseName ).test( f.name ), "drop database - dir not cleared" ); } );

print("SUCCESS directoryperdb.js");