File: dumprestore_repair.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (47 lines) | stat: -rw-r--r-- 1,781 bytes parent folder | download | duplicates (3)
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
/* dumprestore_repair.js
 * create collection that spans more than one extent.
 * mongodump using both --repair and normal
 * restore both dumps and assert they're equal
 * assert that the --repair dump is 2 times the size of the non --repair dump
 */
t = new ToolTest( "dumprestore_repair" );
c = t.startDB( "foo" );
dbName = t.db;
assert.eq( 0 , c.count() , "foo" );
for (i=0; i<100; i++) { c.save( { x : i } ); }
assert.eq( 100 , c.count() , "foo" );
t.stop();

// normal
normalDumpPath = t.ext + 'normal'
t.runTool( "dump",  "--dbpath", t.dbpath, "-d",  t.baseName, "-c", "foo", "--out", normalDumpPath );

// with repair
repairDumpPath = t.ext + 'repair'
t.runTool( "dump", "--repair", "--dbpath", t.dbpath, "-d",  t.baseName, "-c", "foo", "--out", repairDumpPath );

c = t.startDB( "foo" );

function restore(path, toolTest, coll) {
    coll.drop();
    assert.eq( 0 , coll.count() , "after drop" );
    toolTest.runTool( "restore" , "--dir" , path );
    assert.soon( "c.findOne()" , "no data after sleep" );
    assert.eq( 100 , c.count() , "after restore" );
}

restore(normalDumpPath, t, c);
restore(repairDumpPath, t, c);

// get the dumped bson files
normalFiles = listFiles( normalDumpPath + '/'  + t.baseName )

// filter out the metadata.json file
normalFiles = normalFiles.filter( function(x) { if ( x.name.match( /bson$/ ) ) return x; } )
assert.eq( normalFiles[0].name, normalDumpPath + "/" + t.baseName + "/foo.bson", "unexpected file name")
repairFiles = listFiles( repairDumpPath + '/'  + t.baseName )
assert.eq( repairFiles[0].name, repairDumpPath + "/" + t.baseName + "/foo.bson", "unexpected file name")

// the --repair bson file should be exactly twice the size of the normal dump file
assert.eq( normalFiles[0].size * 2, repairFiles[0].size );
t.stop();