Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SERVER-26474 clean up dumprestore7.js
Right now, there is no meaningful information gained when this test fails. I'm trying to indentify the cause of a recent failure, and the logs are not useful as is.
- Loading branch information
Matt Cotter
committed
Oct 5, 2016
1 parent
2369877
commit cf8fe65
Showing
1 changed file
with
59 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,84 @@ | ||
var name = "dumprestore7"; | ||
(function() { | ||
"use strict"; | ||
var name = "dumprestore7"; | ||
|
||
function step(msg) { | ||
msg = msg || ""; | ||
this.x = (this.x || 0) + 1; | ||
print('\n' + name + ".js step " + this.x + ' ' + msg); | ||
} | ||
var step = (function() { | ||
var n = 0; | ||
return function(msg) { | ||
msg = msg || ""; | ||
print('\n' + name + ".js step " + (++n) + ' ' + msg); | ||
}; | ||
})(); | ||
|
||
step(); | ||
step("starting the replset test"); | ||
|
||
var replTest = new ReplSetTest({name: name, nodes: 1}); | ||
var nodes = replTest.startSet(); | ||
replTest.initiate(); | ||
var master = replTest.getPrimary(); | ||
var replTest = new ReplSetTest({name: name, nodes: 1}); | ||
var nodes = replTest.startSet(); | ||
replTest.initiate(); | ||
|
||
{ | ||
step("first chunk of data"); | ||
var foo = master.getDB("foo"); | ||
for (i = 0; i < 20; i++) { | ||
step("inserting first chunk of data"); | ||
var foo = replTest.getPrimary().getDB("foo"); | ||
for (var i = 0; i < 20; i++) { | ||
foo.bar.insert({x: i, y: "abc"}); | ||
} | ||
} | ||
|
||
{ | ||
step("wait"); | ||
step("waiting for replication"); | ||
replTest.awaitReplication(); | ||
assert.eq(foo.bar.count(), 20, "should have inserted 20 documents"); | ||
|
||
// The time of the last oplog entry. | ||
var time = replTest.getPrimary() | ||
.getDB("local") | ||
.getCollection("oplog.rs") | ||
.find() | ||
.limit(1) | ||
.sort({$natural: -1}) | ||
.next(); | ||
step(time.ts.t); | ||
} | ||
.next() | ||
.ts; | ||
step("got time of last oplog entry: " + time); | ||
|
||
{ | ||
step("second chunk of data"); | ||
var foo = master.getDB("foo"); | ||
for (i = 30; i < 50; i++) { | ||
step("inserting second chunk of data"); | ||
for (var i = 30; i < 50; i++) { | ||
foo.bar.insert({x: i, y: "abc"}); | ||
} | ||
} | ||
{ var conn = MongoRunner.runMongod({}); } | ||
|
||
step("try mongodump with $timestamp"); | ||
assert.eq(foo.bar.count(), 40, "should have inserted 40 total documents"); | ||
|
||
var data = MongoRunner.dataDir + "/dumprestore7-dump1/"; | ||
var query = {ts: {$gt: {$timestamp: {t: time.ts.t, i: time.ts.i}}}}; | ||
step("try mongodump with $timestamp"); | ||
|
||
var exitCode = MongoRunner.runMongoTool("mongodump", { | ||
host: "127.0.0.1:" + replTest.ports[0], | ||
db: "local", | ||
collection: "oplog.rs", | ||
query: tojson(query), | ||
out: data, | ||
}); | ||
assert.eq(0, exitCode, "monogdump failed to dump the oplog"); | ||
var data = MongoRunner.dataDir + "/dumprestore7-dump1/"; | ||
var query = {ts: {$gt: time}}; | ||
print("mongodump query: " + tojson(query)); | ||
|
||
step("try mongorestore from $timestamp"); | ||
var testQueryCount = | ||
replTest.getPrimary().getDB("local").getCollection("oplog.rs").find(query).itcount(); | ||
assert.eq(testQueryCount, 20, "the query should match 20 documents"); | ||
|
||
exitCode = MongoRunner.runMongoTool("mongorestore", { | ||
host: "127.0.0.1:" + conn.port, | ||
dir: data, | ||
writeConcern: 1, | ||
}); | ||
assert.eq(0, exitCode, "mongorestore failed to restore the oplog"); | ||
var exitCode = MongoRunner.runMongoTool("mongodump", { | ||
host: "127.0.0.1:" + replTest.ports[0], | ||
db: "local", | ||
collection: "oplog.rs", | ||
query: tojson(query), | ||
out: data, | ||
}); | ||
assert.eq(0, exitCode, "monogdump failed to dump the oplog"); | ||
|
||
var x = 9; | ||
x = conn.getDB("local").getCollection("oplog.rs").count(); | ||
step("try mongorestore from $timestamp"); | ||
|
||
assert.eq(x, 20, "mongorestore should only have inserted the latter 20 entries"); | ||
var restoreMongod = MongoRunner.runMongod({}); | ||
exitCode = MongoRunner.runMongoTool("mongorestore", { | ||
host: "127.0.0.1:" + restoreMongod.port, | ||
dir: data, | ||
writeConcern: 1, | ||
}); | ||
assert.eq(0, exitCode, "mongorestore failed to restore the oplog"); | ||
|
||
step("stopSet"); | ||
replTest.stopSet(); | ||
var count = restoreMongod.getDB("local").getCollection("oplog.rs").count(); | ||
if (count != 20) { | ||
print("mongorestore restored too many documents"); | ||
restoreMongod.getDB("local").getCollection("oplog.rs").find().pretty().shellPrint(); | ||
assert.eq(count, 20, "mongorestore should only have inserted the latter 20 entries"); | ||
} | ||
|
||
step("SUCCESS"); | ||
step("stopping replset test"); | ||
replTest.stopSet(); | ||
})(); |