Skip to content

Commit

Permalink
ceph-objectstore-tool: Add dump-journal op
Browse files Browse the repository at this point in the history
Have dump-journal op directly dump a filestore journal without
mounting or try to dump after mounting.

Fixes: #11135

Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit 381605e)
  • Loading branch information
dzafman committed Feb 25, 2016
1 parent aaff4d7 commit 3e68825
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions src/tools/ceph_objectstore_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "os/ObjectStore.h"
#include "os/FileStore.h"
#include "os/FileJournal.h"

#include "osd/PGLog.h"
#include "osd/OSD.h"
Expand Down Expand Up @@ -2290,6 +2291,20 @@ bool ends_with(const string& check, const string& ending)
return check.size() >= ending.size() && check.rfind(ending) == (check.size() - ending.size());
}

// Based on FileStore::dump_journal(), set-up enough to only dump
int mydump_journal(Formatter *f, string journalpath, bool m_journal_dio)
{
int r;

if (!journalpath.length())
return -EINVAL;

FileJournal *journal = new FileJournal(uuid_d(), NULL, NULL, journalpath.c_str(), m_journal_dio);
r = journal->_fdump(*f, false);
delete journal;
return r;
}

int main(int argc, char **argv)
{
string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type, format;
Expand All @@ -2310,7 +2325,7 @@ int main(int argc, char **argv)
("pgid", po::value<string>(&pgidstr),
"PG id, mandatory except for import, list-lost, fix-lost, list-pgs, set-allow-sharded-objects")
("op", po::value<string>(&op),
"Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects]")
"Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal]")
("file", po::value<string>(&file),
"path of file to export or import")
("format", po::value<string>(&format)->default_value("json-pretty"),
Expand Down Expand Up @@ -2408,14 +2423,15 @@ int main(int argc, char **argv)
myexit(ret != 0);
}

if (!vm.count("data-path")) {
if (!vm.count("type")) {
type = "filestore";
}
if (!vm.count("data-path") &&
!(op == "dump-journal" && type == "filestore")) {
cerr << "Must provide --data-path" << std::endl;
usage(desc);
myexit(1);
}
if (!vm.count("type")) {
type = "filestore";
}
if (type == "filestore" && !vm.count("journal-path")) {
cerr << "Must provide --journal-path" << std::endl;
usage(desc);
Expand Down Expand Up @@ -2489,6 +2505,27 @@ int main(int argc, char **argv)
}
g_conf->apply_changes(NULL);

// Special list handling. Treating pretty_format as human readable,
// with one object per line and not an enclosing array.
human_readable = ends_with(format, "-pretty");
if (op == "list" && human_readable) {
// Remove -pretty from end of format which we know is there
format = format.substr(0, format.size() - strlen("-pretty"));
}

formatter = Formatter::create(format);
if (formatter == NULL) {
cerr << "unrecognized format: " << format << std::endl;
myexit(1);
}

// Special handling for filestore journal, so we can dump it without mounting
if (op == "dump-journal" && type == "filestore") {
int ret = mydump_journal(formatter, jpath, g_conf->journal_dio);
formatter->flush(cout);
myexit(ret != 0);
}

//Verify that data-path really exists
struct stat st;
if (::stat(dpath.c_str(), &st) == -1) {
Expand Down Expand Up @@ -2674,7 +2711,7 @@ int main(int argc, char **argv)

if (op != "list" && op != "import" && op != "list-lost" && op != "fix-lost"
&& op != "list-pgs" && op != "set-allow-sharded-objects" &&
(pgidstr.length() == 0)) {
op != "dump-journal-mount" && (pgidstr.length() == 0)) {
cerr << "Must provide pgid" << std::endl;
usage(desc);
ret = 1;
Expand Down Expand Up @@ -2786,6 +2823,19 @@ int main(int argc, char **argv)
if (ret == 0)
cout << "Import successful" << std::endl;
goto out;
} else if (op == "dump-journal-mount") {
// Undocumented feature to dump journal with mounted fs
// This doesn't support the format option, but it uses the
// ObjectStore::dump_journal() and mounts to get replay to run.
int r = fs->dump_journal(cout);
if (r) {
if (r == -EOPNOTSUPP) {
cerr << "Object store type \"" << type << "\" doesn't support journal dump" << std::endl;
} else {
cerr << "Journal dump failed with error " << r << std::endl;
}
}
goto out;
}

log_oid = OSD::make_pg_log_oid(pgid);
Expand Down Expand Up @@ -2817,21 +2867,6 @@ int main(int argc, char **argv)
goto out;
}

// Special list handling. Treating pretty_format as human readable,
// with one object per line and not an enclosing array.
human_readable = ends_with(format, "-pretty");
if (op == "list" && human_readable) {
// Remove -pretty from end of format which we know is there
format = format.substr(0, format.size() - strlen("-pretty"));
}

formatter = Formatter::create(format);
if (formatter == NULL) {
cerr << "unrecognized format: " << format << std::endl;
ret = 1;
goto out;
}

if (op == "list") {
r = do_list(fs, pgidstr, object, formatter, debug, human_readable);
if (r) {
Expand Down

0 comments on commit 3e68825

Please sign in to comment.