Skip to content

Commit

Permalink
Make mongorestore ignore 'v' option when restoring indexes: SERVER-3687
Browse files Browse the repository at this point in the history
  • Loading branch information
stbrody committed Aug 29, 2011
1 parent 8c0e882 commit b961557
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
Binary file added jstests/tool/data/dumprestore6/foo.bson
Binary file not shown.
Binary file added jstests/tool/data/dumprestore6/system.indexes.bson
Binary file not shown.
27 changes: 27 additions & 0 deletions jstests/tool/dumprestore6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// dumprestore6.js
// Test restoring from a dump with an old index version

t = new ToolTest( "dumprestore6" );

c = t.startDB( "foo" );
db = t.db
assert.eq( 0 , c.count() , "setup1" );

t.runTool("restore", "--dir", "jstests/tool/data/dumprestore6", "--db", "jstests_tool_dumprestore6")

assert.soon( "c.findOne()" , "no data after sleep" );
assert.eq( 1 , c.count() , "after restore" );
assert.eq( 1 , db.system.indexes.findOne({name:'a_1'}).v, "index version wasn't updated")
assert.eq( 1, c.count({v:0}), "dropped the 'v' field from a non-index collection")

db.dropDatabase()
assert.eq( 0 , c.count() , "after drop" );

t.runTool("restore", "--dir", "jstests/tool/data/dumprestore6", "--db", "jstests_tool_dumprestore6", "--keepIndexVersion")

assert.soon( "c.findOne()" , "no data after sleep2" );
assert.eq( 1 , c.count() , "after restore2" );
assert.eq( 0 , db.system.indexes.findOne({name:'a_1'}).v, "index version wasn't maintained")
assert.eq( 1, c.count({v:0}), "dropped the 'v' field from a non-index collection")

t.stop();
5 changes: 4 additions & 1 deletion tools/restore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Restore : public BSONTool {
public:

bool _drop;
bool _keepIndexVersion;
string _curns;
string _curdb;
set<string> _users; // For restoring users with --drop
Expand All @@ -47,6 +48,7 @@ class Restore : public BSONTool {
add_options()
("drop" , "drop each collection before import" )
("oplogReplay" , "replay oplog for point-in-time restore")
("keepIndexVersion" , "don't upgrade indexes to newest version")
;
add_hidden_options()
("dir", po::value<string>()->default_value("dump"), "directory to restore from")
Expand All @@ -69,6 +71,7 @@ class Restore : public BSONTool {
}

_drop = hasParam( "drop" );
_keepIndexVersion = hasParam("keepIndexVersion");

bool doOplog = hasParam( "oplogReplay" );
if (doOplog) {
Expand Down Expand Up @@ -265,7 +268,7 @@ class Restore : public BSONTool {
string s = _curdb + "." + n.coll;
bo.append("ns", s);
}
else {
else if (strcmp(e.fieldName(), "v") != 0 || _keepIndexVersion) { // Remove index version number
bo.append(e);
}
}
Expand Down

0 comments on commit b961557

Please sign in to comment.