diff options
author | Dan Pasette <dan@10mongodb.com> | 2014-01-28 10:06:54 -0500 |
---|---|---|
committer | Dan Pasette <dan@mongodb.com> | 2014-01-29 13:27:48 -0500 |
commit | 276c79f3246ec65060cc6dfeb8f8e1cf121ccdcc (patch) | |
tree | 01c58fe7bfc8275f9e40d12d3d4179586cfef4e6 /src/mongo/tools | |
parent | 0a67590595841ef49dfc8ac83f227ece770689f3 (diff) | |
download | mongo-276c79f3246ec65060cc6dfeb8f8e1cf121ccdcc.tar.gz |
Revert "SERVER-12187 Extend mongodump to support --listExtents and --dumpExtents"
This reverts commit f54536ac4e33bc18e8d7c1289c22e2e4d6c13eca.
Diffstat (limited to 'src/mongo/tools')
-rw-r--r-- | src/mongo/tools/dump.cpp | 148 | ||||
-rw-r--r-- | src/mongo/tools/mongodump_options.cpp | 16 | ||||
-rw-r--r-- | src/mongo/tools/mongodump_options.h | 3 |
3 files changed, 5 insertions, 162 deletions
diff --git a/src/mongo/tools/dump.cpp b/src/mongo/tools/dump.cpp index 773519f1de3..b0e43927f2c 100644 --- a/src/mongo/tools/dump.cpp +++ b/src/mongo/tools/dump.cpp @@ -238,145 +238,11 @@ public: } - /** - * List all extents for a collection in the format 'diskLoc,size', e.g. '4:d587000,20480' - * Default file location is 'dump/dbName/collName.extents', e.g. 'dump/test/foo.extents' - * mongodump --dbpath /data/db/ -d test -c foo --listExtents - */ - int listExtents() { - string ns = getNS(); - toolInfoLog() << "listing extents for namespace: " << ns << endl; - Client::ReadContext cx(ns); - const NamespaceDetails* nsd = nsdetails(ns); - if (!nsd) { - toolError() << "error creating namespace" << endl; - return -1; - } - Database* db = cx.ctx().db(); - ExtentManager& em = db->getExtentManager(); - DiskLoc extentLoc = nsd->firstExtent(); - if (extentLoc.isNull()) { - toolError() << "first extent in NULL" << endl; - return -1; - } - if (!extentLoc.isValid()) { - toolError() << "first extent not valid" << endl; - return -1; - } - - boost::filesystem::path root = mongoDumpGlobalParams.outputDirectory; - root /= toolGlobalParams.db; - boost::filesystem::create_directories(root); - root /= toolGlobalParams.coll + ".extents"; - - // check if we're outputting to stdout - FilePtr out((mongoDumpGlobalParams.outputDirectory == "-") ? - stdout : fopen(root.c_str(), "wb")); - - Extent* extent = em.getExtent(extentLoc); - while (extent != NULL) { - extentLoc = extent->myLoc; - if (extentLoc.isNull()) { - toolError() << "extent is NULL" << endl; - return -1; - } - if (!extentLoc.isValid()) { - toolError() << extentLoc << ": extent not valid" << endl; - return -1; - } - fprintf(out, "%s,%d\n", extentLoc.toString().c_str(), extent->length); - extent = em.getNextExtent(extent); - } - return 0; - } - - /** - * Dump all documents for a single extent to a BSON file or stdout. - * Default file location is 'dump/dbName/collName-fileNum-offset.bson', e.g. 'dump/test/foo-4-2400.bson' - * mongodump --dbpath /data/db/ -d test -c foo --dumpExtent --diskLoc 4:d587000 - */ - int dumpExtent() { - - string::size_type n = mongoDumpGlobalParams.diskLoc.find(':'); - if (n == string::npos) { - toolError() << "expecting 'fn:offset' as value for extent DiskLoc." << endl; - return -1; - } - toolInfoLog() << "dumping BSON objects from extent: " << mongoDumpGlobalParams.diskLoc; - uint32_t fn = strtoul(mongoDumpGlobalParams.diskLoc.c_str(), NULL, 10); - uint32_t ofs = strtoul(mongoDumpGlobalParams.diskLoc.c_str() + n + 1, NULL, 16); - DiskLoc extentLoc(fn, ofs); - - // set up the file name and directory for the output file - boost::filesystem::path root = mongoDumpGlobalParams.outputDirectory; - root /= toolGlobalParams.db; - boost::filesystem::create_directories(root); - string fname = mongoDumpGlobalParams.diskLoc; - replace(fname.begin(), fname.end(), ':', '-'); - root /= toolGlobalParams.coll + "-" + fname + ".bson"; - - // check if we're outputting to stdout - FilePtr out ((mongoDumpGlobalParams.outputDirectory == "-") ? - stdout : fopen(root.c_str(), "wb")); - string ns = getNS(); - Client::ReadContext cx( ns ); - Database* db = cx.ctx().db(); - - return _dumpExtent(db, extentLoc, out); - } - - - int _dumpExtent(Database* db, DiskLoc extentLoc, FILE* out) { - - if (extentLoc.getOfs() <= 0) { - toolError() << "invalid extent offset: " << extentLoc.getOfs() << endl; - return -1; - } - - Extent* e = db->getExtentManager().getExtent(extentLoc, false); - if (!e->isOk()) { - toolError() << "Extent not ok, magic: " << e->magic << endl; - return -1; - } - - set<DiskLoc> seen; - DiskLoc loc = e->firstRecord; - - Writer writer(out, NULL); - while (!loc.isNull()) { - if (!seen.insert(loc).second) { - toolError() << "infinite loop in extent, seen: " << loc << " before" << endl; - return -1; - } - if (loc.getOfs() <= 0) { - toolError() << "offset is 0 for record which should be impossible" << endl; - return -1; - } - - Record* rec = loc.rec(); - BSONObj obj; - try { - obj = loc.obj(); - verify(obj.valid()); - writer(obj); - } - catch (std::exception& e) { - toolError() << "found invalid document @ " << loc << " " << e.what() << endl; - return -1; - } - loc = rec->getNext(loc); - - // break when new loc is outside current extent boundary - if (loc.compare(e->lastRecord) > 0) break; - } - return 0; - } - int repair() { toolInfoLog() << "going to try and recover data from: " << toolGlobalParams.db << std::endl; return _repair(toolGlobalParams.db); } - + DiskLoc _repairExtent( Database* db , string ns, bool forward , DiskLoc eLoc , Writer& w ){ LogIndentLevel lil; @@ -449,6 +315,10 @@ public: return forward ? e->xnext : e->xprev; } + /* + * NOTE: The "outfile" parameter passed in should actually represent a directory, but it is + * called "outfile" because we append the filename and use it as our output file. + */ void _repair( Database* db , string ns , boost::filesystem::path outfile ){ Collection* collection = db->getCollection( ns ); const NamespaceDetails * nsd = collection->details(); @@ -553,14 +423,6 @@ public: return repair(); } - if (mongoDumpGlobalParams.listExtents) { - return listExtents(); - } - - if (mongoDumpGlobalParams.dumpExtent) { - return dumpExtent(); - } - { if (mongoDumpGlobalParams.query.size()) { _query = fromjson(mongoDumpGlobalParams.query); diff --git a/src/mongo/tools/mongodump_options.cpp b/src/mongo/tools/mongodump_options.cpp index ea4127e46a8..aeb36b8acb3 100644 --- a/src/mongo/tools/mongodump_options.cpp +++ b/src/mongo/tools/mongodump_options.cpp @@ -72,19 +72,6 @@ namespace mongo { options->addOptionChaining("forceTableScan", "forceTableScan", moe::Switch, "force a table scan (do not use $snapshot)"); - options->addOptionChaining("listExtents", "listExtents", moe::Switch, - "list extents for given db collection").requires("dbpath") - .requires("collection").requires("db").hidden(); - - options->addOptionChaining("dumpExtent", "dumpExtent", moe::Switch, - "dump one extent specified by --diskLoc fn:offset") - .requires("diskLoc").requires("dbpath") - .requires("collection").requires("db").hidden(); - - options->addOptionChaining("diskLoc", "diskLoc", moe::String, - "extent diskLoc formatted as: 'fn:offset'") - .format("[0-9]+:[0-9a-fA-F]+", "[file]:[hex offset]") - .requires("dbpath").requires("dumpExtent").hidden(); return Status::OK(); } @@ -136,9 +123,6 @@ namespace mongo { if (!hasParam("query") && !hasParam("dbpath") && !hasParam("forceTableScan")) { mongoDumpGlobalParams.snapShotQuery = true; } - mongoDumpGlobalParams.listExtents = hasParam("listExtents"); - mongoDumpGlobalParams.dumpExtent = hasParam("dumpExtent"); - mongoDumpGlobalParams.diskLoc = getParam("diskLoc"); // Make the default db "" if it was not explicitly set if (!params.count("db")) { diff --git a/src/mongo/tools/mongodump_options.h b/src/mongo/tools/mongodump_options.h index 09e0c8c2ba9..a7d370d629f 100644 --- a/src/mongo/tools/mongodump_options.h +++ b/src/mongo/tools/mongodump_options.h @@ -43,9 +43,6 @@ namespace mongo { bool useOplog; bool repair; bool snapShotQuery; - bool listExtents; - bool dumpExtent; - std::string diskLoc; }; extern MongoDumpGlobalParams mongoDumpGlobalParams; |