From: Sage Weil Date: Sun, 15 Jan 2012 05:15:02 +0000 (-0800) Subject: osd: implement --dump-journal X-Git-Tag: v0.41~24 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fdaf91e250dda93f887c0508f0867bab58cd6e8e;p=ceph.git osd: implement --dump-journal Dump the contents of the journal to stdout in text form. Useful for debugging. Signed-off-by: Sage Weil --- diff --git a/src/ceph_osd.cc b/src/ceph_osd.cc index a272ac2b0412..0c6945148812 100644 --- a/src/ceph_osd.cc +++ b/src/ceph_osd.cc @@ -64,6 +64,7 @@ int main(int argc, const char **argv) bool mkjournal = false; bool mkkey = false; bool flushjournal = false; + bool dump_journal = false; bool convertfilestore = false; bool get_journal_fsid = false; bool get_osd_fsid = false; @@ -89,6 +90,8 @@ int main(int argc, const char **argv) convertfilestore = true; } else if (ceph_argparse_witharg(args, i, &val, "--dump-pg-log", (char*)NULL)) { dump_pg_log = val; + } else if (ceph_argparse_flag(args, i, "--dump-journal", (char*)NULL)) { + dump_journal = true; } else if (ceph_argparse_flag(args, i, "--get-cluster-fsid", (char*)NULL)) { get_cluster_fsid = true; } else if (ceph_argparse_flag(args, i, "--get-osd-fsid", (char*)NULL)) { @@ -211,6 +214,22 @@ int main(int argc, const char **argv) << dendl; exit(0); } + if (dump_journal) { + common_init_finish(g_ceph_context); + int err = OSD::dump_journal(g_conf->osd_data, g_conf->osd_journal, cout); + if (err < 0) { + derr << TEXT_RED << " ** ERROR: error dumping journal " << g_conf->osd_journal + << " for object store " << g_conf->osd_data + << ": " << cpp_strerror(-err) << TEXT_NORMAL << dendl; + exit(1); + } + derr << "dumped journal " << g_conf->osd_journal + << " for object store " << g_conf->osd_data + << dendl; + exit(0); + + } + if (convertfilestore) { int err = OSD::convertfs(g_conf->osd_data, g_conf->osd_journal); diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 63449723d675..ebc641fee5e0 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -504,6 +504,42 @@ void FileJournal::close() fd = -1; } + +int FileJournal::dump(ostream& out) +{ + dout(10) << "dump" << dendl; + _open(false, false); + + int err = read_header(); + if (err < 0) + return err; + + read_pos = header.start; + + while (1) { + bufferlist bl; + uint64_t seq = 0; + uint64_t pos = read_pos; + if (!read_entry(bl, seq)) { + dout(3) << "journal_replay: end of journal, done." << dendl; + break; + } + + out << "offset " << pos << " seq " << seq << "\n"; + + bufferlist::iterator p = bl.begin(); + while (!p.end()) { + ObjectStore::Transaction *t = new ObjectStore::Transaction(p); + t->dump(out); + delete t; + } + } + out << std::endl; + dout(10) << "dump finish" << dendl; + return 0; +} + + void FileJournal::start_writer() { write_stop = false; diff --git a/src/os/FileJournal.h b/src/os/FileJournal.h index 88955b2474b6..1488d65164cc 100644 --- a/src/os/FileJournal.h +++ b/src/os/FileJournal.h @@ -238,6 +238,8 @@ private: void close(); int peek_fsid(uuid_d& fsid); + int dump(ostream& out); + void flush(); void throttle(); diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 47223678b232..c1ab28552a63 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -759,6 +759,19 @@ int FileStore::open_journal() return 0; } +int FileStore::dump_journal(ostream& out) +{ + int r; + + if (!journalpath.length()) + return -EINVAL; + + FileJournal *journal = new FileJournal(fsid, &finisher, &sync_cond, journalpath.c_str(), m_journal_dio); + r = journal->dump(out); + delete journal; + return r; +} + int FileStore::wipe_subvol(const char *s) { #if defined(__linux__) diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 299d81fe3274..e6fb17f4ec1a 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -323,6 +323,8 @@ public: void flush(); void sync_and_flush(); + int dump_journal(ostream& out); + uuid_d get_fsid() { return fsid; } int snapshot(const string& name); diff --git a/src/os/Journal.h b/src/os/Journal.h index 5d9f46f3f7dc..c87e54858915 100644 --- a/src/os/Journal.h +++ b/src/os/Journal.h @@ -16,6 +16,8 @@ #ifndef CEPH_JOURNAL_H #define CEPH_JOURNAL_H +#include + #include "include/buffer.h" #include "include/Context.h" #include "common/Finisher.h" @@ -46,6 +48,8 @@ public: virtual void flush() = 0; virtual void throttle() = 0; + virtual int dump(ostream& out) { return -EOPNOTSUPP; } + void set_wait_on_full(bool b) { wait_on_full = b; } // writes diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index eae3c3105249..fa43ceed1457 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -674,6 +674,8 @@ public: virtual void flush() {} virtual void sync_and_flush() {} + virtual int dump_journal(ostream& out) { return -EOPNOTSUPP; } + virtual int snapshot(const string& name) { return -EOPNOTSUPP; } virtual void _fake_writes(bool b) {}; diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 2ab453ec4b17..4c7efcda9620 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -391,6 +391,16 @@ int OSD::flushjournal(const std::string &dev, const std::string &jdev) return err; } +int OSD::dump_journal(const std::string &dev, const std::string &jdev, ostream& out) +{ + ObjectStore *store = create_object_store(dev, jdev); + if (!store) + return -ENOENT; + int err = store->dump_journal(out); + delete store; + return err; +} + int OSD::write_meta(const std::string &base, const std::string &file, const char *val, size_t vallen) { diff --git a/src/osd/OSD.h b/src/osd/OSD.h index e64f05c3e5c8..55521e40cfe8 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1011,6 +1011,7 @@ protected: uuid_d fsid, int whoami); static int mkjournal(const std::string &dev, const std::string &jdev); static int flushjournal(const std::string &dev, const std::string &jdev); + static int dump_journal(const std::string &dev, const std::string &jdev, ostream& out); /* remove any non-user xattrs from a map of them */ void filter_xattrs(map& attrs) { for (map::iterator iter = attrs.begin();