Skip to content

Commit

Permalink
added some shell helpers for common replica set problems
Browse files Browse the repository at this point in the history
  • Loading branch information
kchodorow committed Aug 4, 2011
1 parent 9fd0090 commit a97a8ef
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
35 changes: 35 additions & 0 deletions shell/mongo_vstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,41 @@ const StringData _jscode_raw_utils =
"return \"error: couldn't find \"+hn+\" in \"+tojson(c.members);\n"
"};\n"
"\n"
"rs.debug = {};\n"
"\n"
"rs.debug.nullLastOpWritten = function(primary, secondary) {\n"
"var p = connect(primary+\"/local\");\n"
"var s = connect(secondary+\"/local\");\n"
"s.getMongo().setSlaveOk();\n"
"\n"
"var secondToLast = s.oplog.rs.find().sort({$natural : -1}).limit(1).next();\n"
"var last = p.runCommand({findAndModify : \"oplog.rs\",\n"
"query : {ts : {$gt : secondToLast.ts}},\n"
"sort : {$natural : 1},\n"
"update : {$set : {op : \"n\"}}});\n"
"\n"
"if (!last.value.o || !last.value.o._id) {\n"
"print(\"couldn't find an _id?\");\n"
"}\n"
"else {\n"
"last.value.o = {_id : last.value.o._id};\n"
"}\n"
"\n"
"print(\"nulling out this op:\");\n"
"printjson(last);\n"
"};\n"
"\n"
"rs.debug.getLastOpWritten = function(server) {\n"
"var s = db.getSisterDB(\"local\");\n"
"if (server) {\n"
"s = connect(server+\"/local\");\n"
"}\n"
"s.getMongo().setSlaveOk();\n"
"\n"
"return s.oplog.rs.find().sort({$natural : -1}).limit(1).next();\n"
"};\n"
"\n"
"\n"
"help = shellHelper.help = function (x) {\n"
"if (x == \"mr\") {\n"
"print(\"\\nSee also http://www.mongodb.org/display/DOCS/MapReduce\");\n"
Expand Down
35 changes: 35 additions & 0 deletions shell/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,41 @@ rs.remove = function (hn) {
return "error: couldn't find "+hn+" in "+tojson(c.members);
};

rs.debug = {};

rs.debug.nullLastOpWritten = function(primary, secondary) {
var p = connect(primary+"/local");
var s = connect(secondary+"/local");
s.getMongo().setSlaveOk();

var secondToLast = s.oplog.rs.find().sort({$natural : -1}).limit(1).next();
var last = p.runCommand({findAndModify : "oplog.rs",
query : {ts : {$gt : secondToLast.ts}},
sort : {$natural : 1},
update : {$set : {op : "n"}}});

if (!last.value.o || !last.value.o._id) {
print("couldn't find an _id?");
}
else {
last.value.o = {_id : last.value.o._id};
}

print("nulling out this op:");
printjson(last);
};

rs.debug.getLastOpWritten = function(server) {
var s = db.getSisterDB("local");
if (server) {
s = connect(server+"/local");
}
s.getMongo().setSlaveOk();

return s.oplog.rs.find().sort({$natural : -1}).limit(1).next();
};


help = shellHelper.help = function (x) {
if (x == "mr") {
print("\nSee also http://www.mongodb.org/display/DOCS/MapReduce");
Expand Down

0 comments on commit a97a8ef

Please sign in to comment.